Woocommerce 订阅在 COD 中暂停
Woocommerce Subscriptions on-hold in COD
我在我的商店使用货到付款来收取用户的订阅
但是我有一个非常严重的问题,订阅在没有完成订单的情况下就已经激活了
我用这段代码来阻止它,但它没有用
add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
function wc_subs_suspend_on_cod( $order ) {
if ( ! is_object( $order ) ) {
$order = new WC_Order( $order );
}
foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
$payment_gateways = WC()->payment_gateways->payment_gateways();
$payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';
if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
}
}
}
找到了
这是 COD 订单雕像
修复它但将顺序更改为 "pending"
function sv_wc_cod_order_status( $status ) {
return 'pending';
}
add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );
我在我的商店使用货到付款来收取用户的订阅 但是我有一个非常严重的问题,订阅在没有完成订单的情况下就已经激活了 我用这段代码来阻止它,但它没有用
add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
function wc_subs_suspend_on_cod( $order ) {
if ( ! is_object( $order ) ) {
$order = new WC_Order( $order );
}
foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
$payment_gateways = WC()->payment_gateways->payment_gateways();
$payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';
if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
}
}
}
找到了 这是 COD 订单雕像 修复它但将顺序更改为 "pending"
function sv_wc_cod_order_status( $status ) {
return 'pending';
}
add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );