WooCommerce订阅在没有试用期的情况下创建订单



我有一个WooCommerce产品,它设置为每月订阅。它有 7 天的试用期。我想为用户创建订阅,但没有试用期。我已经使用以下代码进行了尝试,但它似乎也在添加试用期,并且成本设置为零,应该支付订阅的第一个月的费用;

$product = wc_get_product($productid);
        $quantity = 1;
        $order = wc_create_order(array('customer_id' => $userid));
        $order->add_product( $product, $quantity, array());
        $order->set_address( $address, 'billing' );
        $order->set_address( $address, 'shipping' );
        $period = WC_Subscriptions_Product::get_period($product);
        //$trial_end = date( 'Y-m-d H:i:s', strtotime( $start_date." + ".$product->subscription_trial_length." ".$product->subscription_trial_period."s" ) );//WC_Subscriptions_Product::get_trial_expiration_date( $product->ID );
        $interval = WC_Subscriptions_Product::get_interval($product);
        $sub = wcs_create_subscription(array(
            'order_id' => $order->id,
            'billing_period' => $period,
            'billing_interval' => $interval,
            'start_date' => $start_date,
            'customer_id' => $userid
        ));
        $sub->add_product($product, $quantity, array());
        $sub->set_address($address, 'billing');
        $sub->set_address($address, 'shipping');
        $dates = array (
            'trial_end' => $wc_subscription->get_date( "trial_end"),
            'next_payment' => $start_date,
            'end' => date( 'Y-m-d H:i:s', strtotime( $start_date." + ".$product->subscription_length." ".$product->subscription_period."s" ) ),
        );
        $sub->update_dates($dates);
        $sub->update_status("on-hold", "Created after the last subscription expiration!");
        $sub->calculate_totals();
        $sub->delete_date( 'trial_end' );

您可以在产品概览的产品数据部分中将试用期设置为 0 天

相关内容

最新更新