• hi

    Is there a way to charge a flat rate on orders over a certain amount.

    e.g.

    charge £5 on orders over £100

    I’ve done this before in table rate shipping plugin, but hoping todo in admin or a little code snippet given it’s such a simple thing.

Viewing 1 replies (of 1 total)
  • Thread Starter louie171

    (@louie171)

    I think I’ve done this now in code. By making a woocommerce shipping method plugin (using the shipping api).

    It would be great to get some feedback from anyone who understands this kind of thing.

    public function calculate_shipping($package = array()) {
    
                        global $woocommerce;
                        $cartTotal = $woocommerce->cart->get_cart_total();
    
                        $cartTotalNumber = preg_replace("/([^0-9\\.])/i", "", $cartTotal); // remove all chars except numbers and dot 
    
                        $minimumOrderTotalToQualifyForThisShippingRate = 100;
    
                        if ($cartTotalNumber <= $minimumOrderTotalToQualifyForThisShippingRate) // cart not qualify for this shipping rate if less than 100 total
                            return;
    
                        //echo "qualifys for this rate";
                        $rate = array(
                            'id' => $this->id,
                            'label' => $this->title,
                            'cost' => 5, /* shipping rate for the order */
                        );
    
                        // Register the rate
                        $this->add_rate($rate);
                    }
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Woocommerce] charge x amount shipping on orders over y amount’ is closed to new replies.