我想让这个选项无效:
每当有人在我的网站上进行订购并且付款成功时,订单状态会自动从待处理更改为。
但是我不想此功能已启用。相反,当我处理订单时,我想手动完成。
我在woocommerce中找到了这个功能,使这个功能成为可能。我不想直接在那里更改它,而是使用某种覆盖此功能的php片段。
以下是我需要更改的功能:http://woocommerce.wp-a2z.org/oik_api/wc_orderpayment_complete/
PS:我只是很难正确地做到这一点。
答案 0 :(得分:1)
将以下代码添加到functions.php
file.function
ja_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( 'processing' == $order_status ) {
return 'pending';
}
return $order_status;
}
add_filter( 'woocommerce_payment_complete_order_status', 'ja_order_status', 10, 2 );
在 WooCommerce 上进行测试,店面通过 Stripe 测试模式付款。
答案 1 :(得分:1)
<强>更新强>
可能是payment_complete()
未参与您正在寻找的流程。或者,您可以尝试的是woocommerce_thankyou
操作挂钩:
add_action( 'woocommerce_thankyou', 'thankyou_order_status', 10, 1 );
function thankyou_order_status( $order_id ){
if( ! $order_id ) return;
$order = new WC_Order( $order_id ); // Get an instance of the WC_Order object
if ( $order->has_status( 'processing' ) )
$order-> update_status( 'pending' )
}
您可以使用相同的替代挂钩:woocommerce_thankyou_{$order->get_payment_method()}
(用付款方式ID slug替换$order->get_payment_method()
)
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。
此代码在Woocommerce 3+上进行测试并正常运行。
使用附加在 woocommerce_valid_order_statuses_for_payment_complete
过滤器挂钩中的自定义函数,您将在其中返回由负责自动的相关函数payment_complete()
执行的所需订单状态改变订单状态。
默认情况下,过滤器中的订单状态数组为:
array( 'on-hold', 'pending', 'failed', 'cancelled' ).
我们可以暂停&#39;暂停&#39;以这种方式订购状态:
add_filter( 'woocommerce_payment_complete_order_status', 'disable_auto_order_status', 10, 2 );
function disable_auto_order_status( $order_statuses, $order ) {
$return array( 'pending', 'failed', 'cancelled' );
}
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。
此代码在Woocommerce 3+上进行测试并正常运行。