Tuesday, November 7, 2023

Hide calculate shipping for a specific product in woocommerce

Hide calculate shipping for a specific product in woocommerce:

Write the following code in your functions.php:

// Turn off calculate shipping if cart has service product
add_filter('woocommerce_product_needs_shipping', function() {
    foreach (WC()->cart->get_cart() as $cart_item)
    {
        $pid = $cart_item['data']->get_id();
        $product = get_post($pid);
        $slug = $product->post_name;
        if ($slug == 'YOUR-PRODUCT-SLUG') {
            return false;
        }
        else {
            return true;
        }
    }
});


.:Happy coding:.

No comments:

Post a Comment

Make your window center in Ubuntu or Zorin OS

Make your window center in Ubuntu or Zorin OS by below command : gsettings set org.gnome.mutter center-new-windows true Hit enter You're...