• Resolved garimagarg

    (@garimagarg)


    Hello,

    I want to increase shipping cost if any user select the COD payment method.

    I tried below code:

    add_filter( 'woocommerce_package_rates', 'custom_shipping_costs', 10, 2 );
    function custom_shipping_costs( $rates, $package ) {
        
        $tax_rate = 25;
        
        $payment_method  = 'cod';
    
        $chosen_payment_method = WC()->session->get('chosen_payment_method');
    
        if( 'cod' === WC()->session->get('chosen_payment_method') ){
            foreach( $rates as $rate_key => $rate ){
    			
    				// Set rate cost
    				$rates[$rate_key]->cost = $rates[$rate_key]->cost + $tax_rate;
    
    		}
        }
    
        return $rates;
    }

    If I remove the payment gateway IF condition then its working. but with the payment gateway condition its not working. Can nayone help me out with this?

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Increase shipping cost by selecting cod’ is closed to new replies.