2017-04-02 48 views
0

我有一個WooCommerce產品,它被設置爲按月訂閱。它有7天的試用期。我想爲用戶創建訂閱,但沒有試用期。我已經嘗試使用下面的代碼,但它似乎也增加了試用期,並且成本設置爲零,應該爲訂閱的第一個月支付;WooCommerce訂閱在沒有試用期限的情況下創建訂單

$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'); 

回答

-1

您可以在產品概述

+0

請詳細說明這個答案,因爲它是非常簡約的產品數據部設置試用期爲0天。您應該添加一個代碼示例或更好的解釋到您的答案。作爲參考,閱讀[答案],看看你應該如何回答問題。 – Nytrix

+0

有沒有必要詳細說明?並且沒有必要的代碼。「您可以將產品概覽的產品數據部分的試用期設置爲0天/取消試用期,位於WordPress平臺的woocommerce>產品部分」 –

相關問題