-1

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.

1 Answers1

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