【问题标题】:WooCommerce Subscriptions create order without trial periodWooCommerce 订阅无需试用期即可创建订单
【发布时间】:2017-04-02 15:06:38
【问题描述】:

我有一个按月订阅的 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' );

【问题讨论】:

    标签: php woocommerce


    【解决方案1】:

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

    【讨论】:

    • 请详细说明这个答案,因为它非常简约。您应该为您的答案添加代码示例或更好的解释。作为参考,请阅读How to Answer 了解您应该如何回答问题。
    • 不用多说了吧?而且不需要代码..“您可以将试用期设置为 0 天/取消试用期,在产品概述的产品数据部分,位于 wordpress 平台的 woocommerce > 产品部分”
    猜你喜欢
    • 2020-10-07
    • 2019-04-09
    • 2019-10-04
    • 2018-08-06
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 2019-10-14
    • 2020-04-05
    相关资源
    最近更新 更多