Package rate hook not triggered
-
I have installed wordpress and woocommerce plugin and enabled flat rate and local pickup methods.
I am using legacy checkout shortcode method.
I have added 2 radio buttons in form-checkout template and when clicked, trigger the package rate hook but it is not working for customers.
But it works fine for admin when checkout a product.
Below is the code. Kindly help me to resolve.
<script>
jQuery( document ).ready(function( $ ) {
jQuery(".ccdelivery_type").on("click", function () {
const selected = jQuery(this).val();
console.log('Selected delivery type:', selected);
jQuery('body').trigger('update_checkout');
});
</script>
<form name="checkout" method="post" class="checkout woocommerce-checkout zzzssstt" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data" aria-label="<?php echo esc_attr__( 'Checkout', 'woocommerce' ); ?>">
<label><input type="radio" name="delivery_type" value="home" class="ccdelivery_type"> Home
Delivery</label>
<label><input type="radio" name="delivery_type" value="pickup" class="ccdelivery_type"> Store
Pickup</label>
//other html layout related codes as in default checkout
</form>
functions.php
function update_shipping_cost_based_on_custom_field($rates, $package) {
if (!isset($_POST['post_data'])) {
return $rates;
}
parse_str($_POST['post_data'], $post_data);
echo "testing";
print_r($rates);
return $rates;
}
add_filter('woocommerce_package_rates', 'update_shipping_cost_based_on_custom_field', 10, 2);
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Package rate hook not triggered’ is closed to new replies.