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

Switch PHP version in Ubuntu OS or Zorin OS

First check where is installed your PHP by the below command: $ which php See PHP version by below command: $ php -v As I've installed P...