• This plugin is great, thank you saved me a lot of time to fix the shipping calculator.
    I have 2 suggestions which i find very useful at least in my case.
    1-suggestion: is to create a condition of the product if virtual the shortcode or the calculator will not show.
    2-suggestion: is to add a tick box if you want the calculator to be added in the checkout box.

    Here’s my solution since i have some products are virtual no shipping is required, for others could be downloadable or anything inside the product or post meta key.

    I added another shortcode including your shortcode with conditions.

    // Shortcode to conditionally display the shipping calculator
    function conditional_shipping_calculator_shortcode() {
        // Check if the current page is a product page
        if (is_product()) {
            $product_id = get_the_ID();
            
            // Check if the product is virtual using post meta
            $is_virtual = get_post_meta($product_id, '_virtual', true);
    
            if ($is_virtual == 'yes') {
                // Product is virtual, return an empty string (or any other content/message you prefer)
                return 'This product is virtual and does not require shipping.';
            }
            
            // Render the shipping calculator shortcode
            return do_shortcode('[pi_shipping_calculator]');
        }
    
        return ''; // Return empty string if not a product page
    }
    add_shortcode('conditional_shipping_calculator', 'conditional_shipping_calculator_shortcode');

    Hope this helps.

  • The topic ‘For virtual products’ is closed to new replies.