WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Shipping class to be able Overwrite free shipping?

[Resolved] Shipping class to be able Overwrite free shipping?

Viewing 1 replies (of 1 total)
  • Just in case anybody comes across this issue i found my solution here:

    Disable Free Shipping on a per Product Basis in WooCommerce

    **
    */ Disable free shipping for select products
    *
    * @param bool $is_available
    */
    function my_free_shipping( $is_available ) {
    global $woocommerce;
    
    // set the product ids that are ineligible
    $ineligible = array( '14009', '14031' );
    
    // get cart contents
    $cart_items = $woocommerce->cart->get_cart();
    
    // loop through the items looking for one in the ineligible array
    foreach ( $cart_items as $key => $item ) {
    if( in_array( $item['product_id'], $ineligible ) ) {
    return false;
    }
    }
    
    // nothing found return the default value
    return $is_available;
    }
    add_filter( 'woocommerce_shipping_free_shipping_is_available', 'my_free_shipping', 20 );

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Replacing the $ineligible array for your product number you will exempt those products from free shipping. Works like a charm.

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Shipping class to be able Overwrite free shipping?’ is closed to new replies.