0

I am trying to create a functionality when a user tries to select COD as a payment option then set shipping to Free Shipping (Make this shipping option available).

Right now I have added this code.

add_action( 'woocommerce_checkout_update_order_review', __NAMESPACE__.'\\refresh_shipping_methods', 10, 1 );

function refresh_shipping_methods($post_data)
{
    if (isset($post_data['payment_method']) && $post_data['payment_method'] === 'cod') {
      // I am not sure how to add Free Shipping Method here.
    }
}

I am unable to figure out how can I add free shipping method here when it isn't available in the available_shipping_method.

How can I add it programmatically ?

bhanu
  • 1,518
  • 2
  • 9
  • 24
  • Have you seen/tried [Disable shipping method based on chosen payment method in Woocommerce](https://stackoverflow.com/q/50412379/11987538) – 7uc1f3r Mar 02 '22 at 16:20

0 Answers0