3 php wordpress orders woocommerce payment-method
在 WooCommerce 中,我需要所有订单立即进入“处理”状态,以便在处理订单时直接发送订单处理电子邮件。
默认情况下,Paypal 和 COD 订单存在此行为,但 BACS 和 Check 则不存在,其默认状态为on-hold。
我尝试了几个像这样的片段:
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_process_order' );
function custom_woocommerce_auto_process_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'processing' );
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,订单仍然显示为“暂停”状态,并且不会发送处理电子邮件通知。现在我刚刚找到了这个片段:
add_filter( 'woocommerce_bacs_process_payment_order_status', function( $status = 'on_hold', $order = null ) {
return 'processing';
}, 10, 2 );
Run Code Online (Sandbox Code Playgroud)
它有效,但仅适用于“BACS”。我怎样才能使它也适用于“支票”订单?
\n\n过滤器挂钩
\nwoocommerce_cheque_process_payment_order_status尚未在 Woocommerce 3.5.7 \xe2\x80\xa6\xc2\xa0 中实现,如果您查看位于 woocommerce 插件中的文件:
includes>gateways>cheque>class-wc-gateway-cheque.php,则缺少挂钩 (行122):Run Code Online (Sandbox Code Playgroud)\n$order->update_status( \'on-hold\', _x( \'Awaiting check payment\', \'Check payment method\', \'woocommerce\' ) );\n\n
class-wc-gateway-cheque.php但在file的 Github WC 版本 3.5.7 上,存在钩子(行122):Run Code Online (Sandbox Code Playgroud)\n$order->update_status( apply_filters( \'woocommerce_cheque_process_payment_order_status\', \'on-hold\', $order ), _x( \'Awaiting check payment\', \'Check payment method\', \'woocommerce\' ) );\n
该挂钩计划在下一个 WooCommerce 3.6 版本中提供,请参阅 Woocommerce Github 上的文件更改。它已被标记3.6.0-rc.2并且3.6.0-beta.1
因此,可以使用以下命令将“bacs”和“支票”付款方式的默认订单状态更改为“正在处理”:
\nadd_filter( \'woocommerce_bacs_process_payment_order_status\',\'filter_process_payment_order_status_callback\', 10, 2 );\nadd_filter( \'woocommerce_cheque_process_payment_order_status\',\'filter_process_payment_order_status_callback\', 10, 2 );\nfunction filter_process_payment_order_status_callback( $status, $order ) {\n return \'processing\';\n}\nRun Code Online (Sandbox Code Playgroud)\n代码位于活动子主题(或活动主题)的functions.php 文件中。
\n| 归档时间: |
|
| 查看次数: |
5840 次 |
| 最近记录: |