• Resolved madcrach

    (@madcrach)


    Hi everyone, maybe you can help me figure out the problem. I’ve been struggling with it for three hours already, and the same code worked fine on other projects.

    Here’s the code for the icon in the header.

    <?php $cart_url = get_permalink( wc_get_page_id( 'cart' ) ); ?>

    <a href="<?php echo esc_url( $cart_url ); ?>" class="nav__cart "><span>
    <?php echo count( WC()->cart->get_cart() ); ?></span></a>

    Here’s the filter for updates.

    add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );

    function woocommerce_header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;

    ob_start();

    $cart_url = get_permalink( wc_get_page_id( 'cart' ) );
    ?>

    I took everything from the documentation.
    Here’s what the AJAX returns.

    {
    "fragments": {
    "div.widget_shopping_cart_content": "<div class=\"widget_shopping_cart_content\">\n\n\t<ul class=\"woocommerce-mini-cart cart_list product_list_widget \">\n\t\t\t\t\t\t<li class=\"woocommerce-mini-cart-item mini_cart_item\">\n\t\t\t\t\t<a href=\"https:\/\/shop.loc\/cart\/?remove_item=060ad92489947d410d897474079c1477&_wpnonce=48641d5529\" class=\"remove remove_from_cart_button\" aria-label=\"\u0412\u0438\u0434\u0430\u043b\u0438\u0442\u0438 SAGUARO 1 \u0437 \u043a\u043e\u0448\u0438\u043a\u0430\" data-product_id=\"221\" data-cart_item_key=\"060ad92489947d410d897474079c1477\" data-product_sku=\"11153\" data-success_message=\"&quot;SAGUARO 1&quot; \u0432\u0438\u0434\u0430\u043b\u0435\u043d\u043e \u0437 \u0432\u0430\u0448\u043e\u0433\u043e \u043a\u043e\u0448\u0438\u043a\u0430\">&times;<\/a>\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/shop.loc\/product\/saguaro-1\/\">\n\t\t\t\t\t\t\t<img width=\"150\" height=\"150\" src=\"https:\/\/shop.loc\/wp-content\/uploads\/2024\/09\/katalog-img1-150x150.webp\" class=\"attachment-woocommerce_thumbnail size-woocommerce_thumbnail\" alt=\"\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/shop.loc\/wp-content\/uploads\/2024\/09\/katalog-img1-150x150.webp 150w, https:\/\/shop.loc\/wp-content\/uploads\/2024\/09\/katalog-img1-100x100.webp 100w, https:\/\/shop.loc\/wp-content\/uploads\/2024\/09\/katalog-img1-50x50.webp 50w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/>SAGUARO 1\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"quantity\">2 &times; <span class=\"woocommerce-Price-amount amount\"><bdi>120 240&nbsp;<span class=\"woocommerce-Price-currencySymbol\">\u0433\u0440\u043d<\/span><\/bdi><\/span><\/span>\t\t\t\t<\/li>\n\t\t\t\t\t<\/ul>\n\n\t<p class=\"woocommerce-mini-cart__total total\">\n\t\t<strong>\u0420\u0430\u0437\u043e\u043c:<\/strong> <span class=\"woocommerce-Price-amount amount\"><bdi>240 480&nbsp;<span class=\"woocommerce-Price-currencySymbol\">\u0433\u0440\u043d<\/span><\/bdi><\/span>\t<\/p>\n\n\t\n\t<p class=\"woocommerce-mini-cart__buttons buttons\"><a href=\"https:\/\/shop.loc\/cart\/\" class=\"button wc-forward\">\u041f\u0435\u0440\u0435\u0433\u043b\u044f\u043d\u0443\u0442\u0438 \u043a\u043e\u0448\u0438\u043a<\/a><a href=\"https:\/\/shop.loc\/checkout\/\" class=\"button checkout wc-forward\">\u041e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u043d\u044f \u0437\u0430\u043c\u043e\u0432\u043b\u0435\u043d\u043d\u044f<\/a><\/p>\n\n\t\n\n<\/div>",
    "a.nav__cart": "\n\n<a href=\"https:\/\/shop.loc\/cart\/\" class=\"nav__cart \"><span>\n 1<\/span><\/a>\n\n",
    ".woocommerce-notices-wrapper": "<div class=\"woocommerce-notices-wrapper\">\n\t<div class=\"woocommerce-message\" role=\"alert\">\n\t\t&ldquo;SAGUARO 1&rdquo; \u0434\u043e\u0434\u0430\u043d\u043e \u0434\u043e \u043a\u043e\u0448\u0438\u043a\u0430. <a href=\"https:\/\/shop.loc\/cart\/\" class=\"button wc-forward\">\u041f\u0435\u0440\u0435\u0433\u043b\u044f\u043d\u0443\u0442\u0438 \u043a\u043e\u0448\u0438\u043a<\/a>\t<\/div>\n<\/div>"
    },
    "cart_hash": "ac859f6b00313d9e09cb7af099f16993"
    }

    Help me find the issue with why the quantity update in the cart icon isn’t working.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Rajesh K. (woo-hc)

    (@rajeshml)

    Hello @madcrach,

    For reference, this particular forum is meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I will leave this thread open for a bit to see if anyone can chime in and help you out further.

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

    Thanks!

    Howdy @madcrach

    There hasn’t been any movement on this thread for a while, so I’m going to mark this as resolved – feel free to create a new topic? should you need any further help.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.