woocommerce_package_rates not firing
-
Great plugin but the hook woocommerce_package_rate isn’t firing.
Currently trying to increase the outputted rate by x%, here is the following code:
Since the Echo on the console.log isn’t showing up, I’m assuming the woocommerce_package_rates isn’t firing. In that case, what would be the hook to use with flexible shipping?
add_filter('woocommerce_package_rates', 'add_percentage_to_shipping_cost', 10, 2); function add_percentage_to_shipping_cost($rates, $package) { // I get the selected shipping method $chosen_shipping_method = WC()->session->get('chosen_shipping_methods')[0]; echo '<script>console.log("Chosen Shipping Methods: ");</script>'; // I've Defined the shipping method IDs for which I want to add 10% $target_shipping_methods = array( 'flexible_shipping_ups:2:02', 'flexible_shipping_ups:2:03', 'flexible_shipping_ups:2:01', ); if (in_array($chosen_shipping_method, $target_shipping_methods)) { foreach ($rates as $rate_id => $rate) { if (in_array($rate_id, $target_shipping_methods)) { $new_cost = $rate->cost + ($rate->cost * 0.1); $rates[$rate_id]->cost = $new_cost; } } } return $rates; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘woocommerce_package_rates not firing’ is closed to new replies.