Php create subscriptions
-
Hi, I need advice, I’m creating a php code to create a subscription product, I have this code:
$product = new WC_Product_Subscription(); $product->set_name('test'); $product->set_status('publish'); $product->set_sku('tipster_'. $user_id); $product->set_virtual(true); $subscription_period = 'month'; $subscription_length = 1; $subscription_price = 60; $product_id = $product->save(); update_post_meta($product_id, 'user_id_tipster', $user_id); update_post_meta($product_id, '_subscription_period', $subscription_period); update_post_meta($product_id, '_subscription_length', $subscription_length); update_post_meta($product_id, '_subscription_price', $subscription_price); update_post_meta($product_id, '_subscription_trial_length', 0); update_post_meta($product_id, '_subscription_trial_period', 'day');
The product is created for me, but when I go to the product page, I can’t see the price and I can’t add it to the cart. But as soon as I update the product, I see the price on the product page and can add it to the cart.
So I assume that I’m missing some code. Can anyone advise me, thank you.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Php create subscriptions’ is closed to new replies.