I have a WooCommerce variable subscription product with 2 variations (one is the monthly payment and the other one is a one-time payment). Both subscriptions expire in 24 months. I want to enable automatic renewal only for a monthly payment as it is recurring and disable automatic renewal for one-time payment as it is not recurring. WooCommerce provides Manual Renewal option in the settings page however it applies to all products/variations. I want to enable manual renewal only for a specific variation so that I can use manual payment gateways for this variation. How can I achieve that? Thanks in advance.
Asked
Active
Viewed 229 times
1 Answers
0
add_filter("pre_option_woocommerce_subscriptions_accept_manual_renewals", "pre_option_woocommerce_subscriptions_accept_manual_renewals", 10, 3);
function pre_option_woocommerce_subscriptions_accept_manual_renewals($pre, $option, $default) {
if (is_checkout()) {
global $woocommerce;
$product_ids = array(1631818389, 1631818390 ); // Product IDs
$items = $woocommerce->cart->get_cart();
foreach ($items as $item => $values) {
$p_id = $values['data']->get_id();
if ( in_array($p_id, $product_ids) ) {
return 'yes';
}
}
}
return $pre;
}

mujuonly
- 11,370
- 5
- 45
- 75
-
The code works. Thank you very much. However, can I add more than one product IDs? How can I do that? – Rogue Ninja Feb 22 '22 at 12:30
-
Updated for multiple IDs – mujuonly Feb 22 '22 at 12:35
-
Now the code works like charm for multiple product IDs too. Thanks again man. Really appreciate it. – Rogue Ninja Feb 22 '22 at 12:51
-
@RogueNinja You can accept the answer if it helped – mujuonly Feb 22 '22 at 13:04