【发布时间】: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