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 ?