WooCommerce:基于付款方式的订单状态

时间:2021-03-16 15:45:46

标签: php wordpress woocommerce orders payment-method

在 Woocommerce 上,我们可以选择 BACS 付款。有些订单以“已付款”的形式出现,有些则不是。我不明白为什么,因为他们使用完全相同的付款方式。下面的两张图片将向您展示这一点:

付费: enter image description here 未支付: enter image description here

我们正在使用一个功能来自动将这些付款从“暂停”更改为“处理中”,以防这可能与问题有关。代码如下:

add_action( 'woocommerce_thankyou', 'bacs_order_payment_processing_order_status', 10, 1 );

function bacs_order_payment_processing_order_status( $order_id ) {
if ( ! $order_id ) {
    return;
}

// Get an instance of the WC_Order object
$order = new WC_Order( $order_id );

if ( ( get_post_meta($order->id, '_payment_method', true) == 'bacs' || 'cod'  ) && ('on-hold' == $order->status || 'pending' == $order->status) ) {
    $order->update_status('processing');
}

else {
    return;
}
}

// change COD payment method order status from processing to on-hold
add_action('woocommerce_thankyou_cod', 'action_woocommerce_thankyou_cod', 10, 1);
function action_woocommerce_thankyou_cod($order_id)
{
    $order = wc_get_order($order_id);
    $order->update_status('processing');
}

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

你的代码已经过时了,而且有很多错误……

相反,更改付款的订单状态,例如:

  1. 货到付款cod使用(默认状态为“处理中”)
  1. Cash on Check cheque use *(默认状态为“on-hold”):
  1. 银行电汇 bacs 使用 *(默认状态为“暂停”):
  1. 对于其他支付网关使用(默认订单状态与每个支付网关有关,以及是否有可发货物品):