2017-04-02 65 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>产品部分” –

相关问题