• Im trying to show free_shipping only on one category

    Is that possible ?

    I have a code where I can hide the free_shipping to specific categories.
    But im trying todo the reverse….(show only to 1 category)

    Here is my hiding code if that helps me get any support :

    add_filter( 'woocommerce_package_rates', 'hiding_free_shipping_to_skolamyndir' ,    10, 1 );
    
    function check_cart_for_share3() {
    
    // specify the category id's you want to hide free_shipping
     $category_ID = array(
        '141', // Grunnskólamyndir
        '140', // Hádegish?fei
        '115', // Skólamyndir
        '116', // Skólamyndir 2015
     );
    global $woocommerce;
    $cart = $woocommerce->cart->cart_contents;
    
    $found = false;
    
    // loop through the array looking for the categories. Switch to true if the category is found.
      foreach ($woocommerce->cart->cart_contents as $key => $values ) {
            $terms = get_the_terms( $values['product_id'], 'product_cat' );
            foreach ($terms as $term) {
                if( in_array( $term->term_id, $category_ID ) ) {
    
            $found = true;
            break;
        }
      }
    }
    
    return $found;
    
    }
    
    function hiding_free_shipping_to_skolamyndir( $available_methods ) {
    
    // use the function above to check the cart for the categories.
    if ( check_cart_for_share3() ) {
    
        // remove the method you want
        unset( $available_methods['free_shipping'] ); // Replace "free_shipping" with the shipping option that you want to remove.
    }
    
    // return the available methods without the one you unset.
    return $available_methods;
    }

    https://www.ads-software.com/plugins/woocommerce/

    [ No bumping please. ]

  • The topic ‘Only show free shipping on one category’ is closed to new replies.