PHP 自动更改 WooCommerce 订单状态的代码
PHP code for automatically change WooCommerce order status
我想根据 PHP 的自定义字段(商店)更改每个新 WooCommerce 订单的状态。
我已经尝试在 functions.php 文件中编写一个函数,但我失败了。
// set Custom Order Status at WooCommerce Checkout Process
add_action( 'woocommerce_thankyou', 'uebes_thankyou_change_order_status' );
function uebes_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;{
$order = wc_get_order( $order_id );
// update order status dependimg to custom field shopart
if(get_post_meta($order->id,'shopart',true) == 'Shop Vorbestellungen'){
$order->update_status( 'vorbestellung' );
}else{
$order->update_status( 'bestellung-neu' );
}
}
}
// set Custom Order Status at WooCommerce Checkout Process
add_action('woocommerce_thankyou', 'uebes_thankyou_change_order_status', 10, 1);
function uebes_thankyou_change_order_status($order_id) {
if (!$order_id)
return;
//create an order instance
$order = wc_get_order($order_id);
// update order status dependimg to custom field shopart
if (get_post_meta($order_id, 'shopart', true) == 'Shop Vorbestellungen') {
$order->update_status('vorbestellung');
} else {
$order->update_status('bestellung-neu');
}
}
我想根据 PHP 的自定义字段(商店)更改每个新 WooCommerce 订单的状态。
我已经尝试在 functions.php 文件中编写一个函数,但我失败了。
// set Custom Order Status at WooCommerce Checkout Process
add_action( 'woocommerce_thankyou', 'uebes_thankyou_change_order_status' );
function uebes_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;{
$order = wc_get_order( $order_id );
// update order status dependimg to custom field shopart
if(get_post_meta($order->id,'shopart',true) == 'Shop Vorbestellungen'){
$order->update_status( 'vorbestellung' );
}else{
$order->update_status( 'bestellung-neu' );
}
}
}
// set Custom Order Status at WooCommerce Checkout Process
add_action('woocommerce_thankyou', 'uebes_thankyou_change_order_status', 10, 1);
function uebes_thankyou_change_order_status($order_id) {
if (!$order_id)
return;
//create an order instance
$order = wc_get_order($order_id);
// update order status dependimg to custom field shopart
if (get_post_meta($order_id, 'shopart', true) == 'Shop Vorbestellungen') {
$order->update_status('vorbestellung');
} else {
$order->update_status('bestellung-neu');
}
}