消息信息WooCommerce



将WooCommerce用于数字产品,众所周知,对于这种类型的产品或支付状态,它总是作为处理。要解决此问题,请使用以下代码来解决问题,但"已成功收到付款"通知消息不会同步。有人知道怎么解决吗?

add_action( 'woocommerce_order_status_changed', 'ts_auto_complete_by_payment_method' );
function ts_auto_complete_by_payment_method( $order_id ) {
if ( !$order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ( $order->data[ 'status' ] == 'processing' ) {
$payment_method = $order->get_payment_method();
if ( $payment_method != "cod" ) {
$order->update_status( 'completed' );
}
}
}
add_action( 'woocommerce_before_thankyou', 'update_order_status_and_show_info' );
function update_order_status_and_show_info( $order_id ) {
if ( !$order_id ) {
return;
}

$order = wc_get_order( $order_id );
if ( $order->get_status() == 'processing' ) {
$payment_method = $order->get_payment_method();
if ( $payment_method != "cod" ) {
$order->update_status( 'completed' );
echo "<span>Payment received successfully.</span>";
}
}
}

试试这个代码

最新更新