I made an ecommerce theme and threre register mini-cart.php by <?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s &times; %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?> code but when I add product to cart its show empty,afte page reload shows product numbers

Dani AI

Generated

Brief expert note tied to the thread: the symptom described by (mini-cart shows empty until a page reload) is a classic case where WooCommerce's client-side fragment refresh is not running or cannot find the mini-cart markup to replace. is correct that the problem is on the front-end (scripts/AJAX) and in how the custom theme is wired, not just the PHP that renders the cart on a full page load.

Troubleshooting checklist (fast verifications that usually surface the cause):

  • Confirm the theme prints wp_head() and wp_footer() in the usual places; missing those stops WordPress/WooCommerce scripts from loading.
  • Verify the WooCommerce frontend scripts (notably the cart-fragments script) are present and not dequeued by the theme or another plugin. A missing script means no fragment refresh.
  • Open the browser console and network tab while adding an item: check for JS errors and for the AJAX XHR that returns fragment HTML (absence or errors point to the problem).
  • Compare the mini-cart HTML to the default output (for example, from woocommerce_mini_cart()); custom markup or missing selectors can prevent the fragment script from locating and replacing the widget.
  • Rule out caching or CDN layer interference: full-page caching or cached AJAX endpoints will keep the old HTML visible until reload.
  • Isolate with a default theme and plugins disabled to detect conflicts.

Enabling WP_DEBUG/SCRIPT_DEBUG and inspecting console/network traces will make the specific failure obvious and point to the precise fix.

Recommended Answers

All 2 Replies

Could you post the JavaScript/AJAX code that goes together with this? PHP code runs entirely server-side, and thus can only affect the browser-side rendering on a refresh. Any AJAX code has to run browser side, which effectively means JavaScript (or a language which translates into either JavaScript or WebAssembly). It is even in the acronym: AJAX stands for "Asynchronous JavaScript and XML", which was what it is used for (e.g., communicating between the browser and the server so the page could be updated without a refresh).

Looking at this again, I note that you are using the WooCommerce plugin for WordPress. This is relevant information for anyone trying to help, as the solution is going to require some knowledge of WoodCommerce and WordPress itself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.