E
E
Evgeny Koryakin2019-05-13 13:21:17
WooCommerce
Evgeny Koryakin, 2019-05-13 13:21:17

How to display the cart on the product page and update it in real time?

Hello.
How to display the cart on the product page and update it as products are added?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2019-05-13
@zettend

you need to hang your cart on woocommerce_add_to_cart_fragments
like this

add_filter( 'woocommerce_add_to_cart_fragments', 'header_add_to_cart_fragment', 30, 1 );
function header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;

    ob_start();

    ?>
    <a class="cart-customlocation" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
    <?php
    $fragments['a.cart-customlocation'] = ob_get_clean();

    return $fragments;
}

In the canonical theme from woo, this is done like this
https://github.com/woocommerce/storefront/blob/e2c...
https://github.com/woocommerce/storefront/blob/d52...
And it is added like this
https: //github.com/woocommerce/storefront/blob/d52...
https://github.com/woocommerce/storefront/blob/d52...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question