Home > Net >  Get Minimum order amount from Woocommerce Settings
Get Minimum order amount from Woocommerce Settings

Time:01-25

Im using the following function to add a free shipping badge to my products. At the moment the minimum amount is hardcoded. Im trying to optimize it further. Any idea how to get the value of the minimum order amount set in the woo backend settings?

    add_filter( 'woocommerce_before_add_to_cart_quantity', 'free_shipping_badge_after_add_to_cart_button', 10 );
    function free_shipping_badge_after_add_to_cart_button() {
        
        global $post;
        $product = new WC_Product( $post->ID );         
        
        $min_amount = 100; //change this to your free shipping threshold
        $fsb_price = (float) $product->get_price(); 

        if (isset($min_amount) && $fsb_price > $min_amount) {
            echo '<span >Free Shipping</span>';              
        } else {
            // do nothing
        }
        
    }

CodePudding user response:

It is great that you are trying to avoid hard coding this value. Unfortunately, it is my understanding that this is not natively a setting in Woo. To achieve it you would either have to setup a custom option in which you set it. Or you could use one of the many plugins that are available to add things like minimum order amount.

Edit: Originally I overlooked the request for this specifically being related to free shipping. When setting up a Free shipping zone in WooCommerce you can specify a minimum amount

Free shipping settings in Woo to add minimum order amount

It was this minimum value that @evavienna was hoping to retrieve on product pages in order to display a free shipping badge.

Code on how to do this can be found in this other post getting-minimum-order-amount-for-free-shipping-method-in-checkout-page

  •  Tags:  
  • Related