0

我正在开发一个 WooCommerce 插件,我在save_post_shop_order动作挂钩上保存了额外的元数据。现在我想添加一个逻辑,根据某些条件将订单状态更改为“待处理”。我发现无论哪种状态,订单状态都不会在save_post_shop_order动作挂钩中改变。

function save_order_data(int $post_id)
{
$nonce_name = isset($_POST['save_invoice_nonce']) ? $_POST['save_invoice_nonce'] : '';
$nonce_action = 'save_invoice';

if (!wp_verify_nonce($nonce_name, $nonce_action)) {
    return;
}
if (!current_user_can('edit_shop_orders', $post_id)) {
    return;
}

if (wp_is_post_autosave($post_id)) {
    return;
}

if (wp_is_post_revision($post_id)) {
    return;
}

$order = wc_get_order($post_id);
$order->update_status('pending'); // This command works but it seems order status is being overwritten maybe by WooCommerce to previous status


}

add_action('save_post_shop_order', 'save_order_data', PHP_INT_MAX);
4

1 回答 1

0

我终于不得不使用瞬态来记住在下一页加载时进行状态更改,然后在woocommerce_after_register_post_type挂钩上更改订单状态。

于 2022-03-05T06:47:25.333 回答