• Hello good day!
    I’m having a problem that’s giving me a headache already, but anyway, here’s the thing, I want to filter free shipping for all purchases over 120.00 / 150.00 by region, but I don’t want it to apply in the category Furniture, even if I buy it for more than 120.00 / 150.00 in other products in the cart, how would I do it?
    I’ve researched several ways, but nothing! I already thought by class, but not being able to remove the Free Shipping option from the furniture, how would I do that?
    Thanks for listening!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @makobaby!

    I think your best bet would be to use something like https://woocommerce.com/products/conditional-shipping-and-payments/

    Cheers!

    Thread Starter makobaby

    (@makobaby)

    I would even use this plugin, but it’s such a basic thing, that it doesn’t need a plugin (at least I think)

    I tried the following code in php functions, but it does the reverse, it only shows free shipping, how would I do to do what I want?

    add_filter( 'woocommerce_package_rates', 'custom_shipping_methods', 100, 2 );
    function custom_shipping_methods( $rates, $package ){
    
        // Define/replace here your correct category slug (!)
        $cat_slug = 'my_category_slug';
        $prod_cat = false;
    
        // Going through each item in cart to see if there is anyone of your category
        foreach ( WC()->cart->get_cart() as $values ) {
            $product = $values['data'];
    
            // compatibility with WC +3
            $product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
    
            if ( has_term( $cat_slug, 'product_cat', $product_id ) )
                $prod_cat = true;
        }
    
        $rates_arr = array();
    
        if ( $prod_cat ) {
            foreach($rates as $rate_id => $rate) { // <== There was a mistake here
                if ('local_pickup' === $rate->method_id) {
                    $rates_arr[ $rate_id ] = $rate;
                }
            }
        }
        return !empty( $rates_arr ) ? $rates_arr : $rates;
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Filter free shipping by category on woocommerce’ is closed to new replies.