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

Suomen kieli (Imperfekti)

In Finnish, the imperfekti is the past tense that describes actions that happened in the past, like the English simple past (e.g., "I ...