我有一个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' );
答案 0 :(得分:-1)
您可以在产品概述的产品数据部分中将试用期设置为0天