• Resolved pkollias

    (@pkollias)


    Hello all, thank you for this wonderful plugin.

    Is there any way to programmatically change the rule cost (e.g when we need to add extra taxes), so that we don’t need to change every time manually all the costs for every rule? For example “$cost + ($cost * 0.24)” when tax is 0.24(24%). And maybe target it for a specific flexible_shipping_method, not for every in our shop (we use 4).

    I checked https://octolize.com/docs/article/940-flexible-shipping-hooks but i cannot understand if any of these hooks is what we need.

    Thank you in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support lusp

    (@lusp)

    Hi @pkollias,

    Could you please provide us with some more details on your use case and the circumstances when these extra taxes should be applied? Should the additional cost be added when some specific products are in the cart or is it dependant on any other factors?

    Kind regards,

    Luke

    Thread Starter pkollias

    (@pkollias)

    Hello,

    I managed to programmatically change the rule cost using the woocommerce_shipping_rate_cost filter as follows:

    function my_shipping_cost_tiers( $cost, $method ) {
    
    	if ( in_array( $method->get_instance_id(), array( 10 ) ) && WC()->cart ) {
    
    		return $cost + ($cost * 0.24);
    	}
    
    	return $cost;
    }
    add_filter( 'woocommerce_shipping_rate_cost', 'my_shipping_cost_tiers', 10, 2 );

    where in the array I put the instance id/ids i want to target.

    Thank you!

    Plugin Support lusp

    (@lusp)

    Thank you @pkollias for keeping us updated. It’s great to hear that you managed to sort this out and shared here the way how it was done, so it could be useful for even more users.

    Kind regards,

    Luke

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hook to programmatically change rule cost’ is closed to new replies.