• I deliver products locally and I’m using WooReer to calculate shipping based on distance.

    I’m trying to get the shipping calculator working on a single product page without having to add the product to the cart. At the moment, I’m using a shortcode to display the calculator on the product page, the problem is it won’t show up unless there is an item in the cart:

    function shipping_calculator_fn() {
    
    ob_start();
    WC()->cart->calculate_totals();
    echo '<div class="cart_totals">';
    wc_cart_totals_shipping_html();
    echo '</div>';
    
    return ob_get_clean();
    
    }
    add_shortcode('display_shipping_calculator', 'shipping_calculator_fn');

    Does anyone know of a way I could trick the calculator into thinking there is an item in the cart? I’ve looked into how other plugins and it looks as if they create a ‘pseudo’ cart to calculate off, but I can’t for the life of me figure it out.

    I’ve also tried to wrap the calculator in the native cart_totals wrapper in the hopes of a magic ajax refresh, but as you could probably guess it was unsuccessful.

    Everything actually works after you’ve added something in the cart, albeit inelegantly.

    Any help would be appreciated.

    Cheers,`

  • The topic ‘Shipping Calculator on Product Page (without items in / adding to cart)’ is closed to new replies.