• Resolved Steven Cooper

    (@kingcooper)


    Hi

    I am using a third party shipping plugin.

    It seems to checkout even when mistakenly it works below a minimum figure.

    As a workaround I’d like to refuse checkout if shipping value is <1.97, with echo message too.

    Is there a code sample I can use for this?

    Thanks

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Moses M. (woo-hc)

    (@mosesmedh)

    Hi @kingcooper,

    You can use the woocommerce_checkout_process hook to prevent checkout if the shipping cost is below $1.97 and display an error message. Simply add the following code to your theme’s functions.php file or a custom plugin:

    add_action('woocommerce_checkout_process', function() {
        $shipping_total = WC()->cart->get_shipping_total();
        
        if ($shipping_total < 1.97) {
            wc_add_notice('Shipping cost must be at least $1.97 to proceed with checkout.', 'error');
        }
    });
    

    This function retrieves the total shipping cost using WC()->cart->get_shipping_total();. If the amount is below $1.97, it prevents checkout and displays an error message. Please note that the code above is a sample code. If it doesn’t work for you, you may need to consult with an expert as giving customization codes is beyond our support scope.

    Alternatively, you can use a conditional plugin to enforce this rule without coding. You can find relevant plugins by searching for “Conditional Shipping and Payments WooCommerce” or checking this quick search: Google Search.

    Thread Starter Steven Cooper

    (@kingcooper)

    Right. That worked perfectly.

    Thanks

    Plugin Support Moses M. (woo-hc)

    (@mosesmedh)

    Hi @kingcooper,

    Glad to hear the snippet worked for you! If you need help with anything else, feel free to start a new topic.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.