我已经整合了一个支付网关来接受在woocommerce上运行的我的商店的在线支付。一切正常,但我注意到woocommerce默认将所有在线付费订单的订单状态更改为wc-processing。
根据我商店的功能,我希望所有在线支付订单最初都处于wc-on-hold状态。
是否有任何方法可以阻止woocommerce通过编程将订单状态更改为wc-processing?
发布于 2016-08-03 21:12:47
这里是一个基于这个线程的代码片段。我们在这里使用woocommerce_thankyou (在付款完成后触发)来连接我们的函数,将'processing'订单状态转换为'on-hold'
add_action( 'woocommerce_thankyou', 'custom_woocommerce_paid_order_status', 10, 1 );
function custom_woocommerce_paid_order_status( $order_id ) {
if ( ! $order_id ) {
return;
}
global $woocommerce;
$order = new WC_Order( $order_id );
// 'processing' orders status are converted to 'on-hold'.
if ( is_object($order) && $order->has_status( 'processing' ) {
$order->update_status( 'on-hold' );
}
return;
}您还可以在您的条件下锁定支付网关,例如,在这里,我们绕过3个支付网关,并使用"your_payment_gateway" 段塞针对特定的支付网关。
add_action( 'woocommerce_thankyou', 'custom_woocommerce_paid_order_status', 10, 1 );
function custom_woocommerce_paid_order_status( $order_id ) {
if ( ! $order_id ) {
return;
}
global $woocommerce;
$order = new WC_Order( $order_id );
// Bypass orders with Bank wire, Cash on delivery and Cheque payment methods.
if ( ( get_post_meta($order->id, '_payment_method', true) == 'bacs' ) || ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) || ( get_post_meta($order->id, '_payment_method', true) == 'cheque' ) ) {
return;
}
// Target your "your_payment_gateway_slug" with this conditional
if ( is_object($order) && get_post_meta($order->id, '_payment_method', true) == 'your_payment_gateway_slug' && $order->has_status( 'processing' ) ) {
$order->update_status( 'on-hold' );
}
return;
}此代码片段用于活动子主题或主题的function.php文件。
你可以很容易地做任何你想做的事情,并且正确的钩子支付订单是woocommerce_thankyou
参考文献:
https://stackoverflow.com/questions/38741747
复制相似问题