我尝试在购买后将订阅状态更改为有效(100% 折扣优惠券)。该代码成功地将订单状态更改为“竞争”,它应该自动将订阅更改为活动状态,但它没有。
我想按照给定的顺序将订阅状态更改为活动状态。 你知道如何解决这个问题吗?
最好的问候
编辑:PS。也许这无关紧要,但在购物车中购买后,没有感谢页面,bc 没有付款。当我以 0 美元的价格购买产品时,它是,但 100% 的折扣则不是。
functions.php 中的代码
add_action('woocommerce_checkout_order_processed', 'custom_woocommerce_auto_complete_order');
function custom_woocommerce_auto_complete_order($order_id)
{
if (!$order_id) {
return;
}
$order = wc_get_order($order_id);
if ($order->get_total() == 0) {
// $order->update_status('processing'); // Unneeded as you complete the order
$order->update_status('completed');
}
}
add_action( 'woocommerce_checkout_order_processed', 'order_complete_activate_subscription', 10, 2 );
function order_complete_activate_subscription( $order_id, $order ) {
$subscriptions = wcs_get_subscriptions_for_order( $order );
if ( ! empty( $subscriptions ) ) {
activate_subscriptions_for_order( $order );
}
}