Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

javascript - Custom added to cart message doesn't show product name on single product pages

A Wordpress theme i'm using has a custom added to cart popup message from the default one when a product is added to the cart, however, it only seems to work on the product archive pages and not the single product pages. When I add an item to the cart on a single product page, the notification comes up and shows the product image in the message, but not the product name. This happens for both variable and simple products on the single product page. (See screenshot below)

enter image description here

This is the code that is used to show the popup notification:

        public function added_to_cart_template() {
             $text = esc_html__( 'has been added to your cart', 'mixmart' );
             echo <<<HTML
        <script type="text/html" id="tmpl-added-to-cart-template">
            <div class="notification-added-to-cart">
                 <div class="notification-wrap">
                      <div class="ns-thumb d-inline-block"><img src="{{{data.src}}}" alt="{{{data.name}}}"></div>
                      <div class="ns-content d-inline-block"><p><strong>{{{data.name}}}</strong> $text </p></div>
                 </div>
            </div>
        </script>
        HTML;
        }

Maybe it might just be easier to change the message to "Product successfully added to cart!" but it would be nice to show the product name. I can't figure out why it works everywhere but the single product pages however..

question from:https://stackoverflow.com/questions/65838057/custom-added-to-cart-message-doesnt-show-product-name-on-single-product-pages

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...