2017-04-02 1 views
0

월별 구독으로 설정되는 WooCommerce 제품이 있습니다. 그것은 7 일 평가판이 있습니다. 평가판 기간이 아닌 사용자에 대한 구독을 만들고 싶습니다. 다음 코드를 사용하여 시험해 보았지만 시험 사용 기간을 추가하는 것으로 보입니다. 비용은 0으로 설정되어 구독 첫 달 동안 지불해야합니다.WooCommerce Subscriptions 무료 평가판 기간없이 주문 생성

$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

자세히 설명 할 필요가 없습니다. 코드가 필요 없습니다. "Wordpress 플랫폼의 woocommerce> 제품 섹션에있는 제품 개요의 제품 데이터 섹션에서 평가판 기간을 0 일로 설정하거나 평가판 사용 기간을 생략 할 수 있습니다. –

관련 문제