• On the checkout page, I added a select box with a list of regions for user to choose from.
    On change, it updates the CheckoutURL with a parameter CHECKOUTURL?location=x_region, then in my theme’s functions.php I added the below line of code.

    function my_dbf_calculated_fee_callback( $calculatedFee, $kiloMeters, $divider, $price ) {
        $customer_location =  $_GET['location'] ?? null;
        
        if($customer_location == 'x' || $customer_location == 'y') {
            $calculatedFee = 0;
        }
        return $calculatedFee;
    }
    add_filter( 'dbf_calculated_fee', 'my_dbf_calculated_fee_callback', 10, 4 );

    To my surprise, when I choose x or y on the checkout page and it reloads the page, The distance based fee is not showing 0.

    But when I echo the $calculatedFee above it returns 0, but the price on the checkout still remains unchanged.

    Am I doing something wrong?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gaylord Focker

    (@webdata)

    Hi,

    WooCommerce’s caching issue. Save shipping method’s settings once to flush the cache.

    Kim

    Thread Starter solamichealolawale

    (@solamichealolawale)

    Hi,

    I have gone to woocommerce settings to save the shipping option and it’s the same

    Plugin Author Gaylord Focker

    (@webdata)

    Hard to say what is wrong then. Maybe you could do fresh install with WP default theme, WooCommerce and then Distance based fee plugin? It would be probably easier to debug your code then and this way you can make sure no other plugins cause any conflicts. Also if you have any other caches, or CDN those can affect too.

    Kim

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘dbf_calculated_fee filter hook didn’t seem to work’ is closed to new replies.