問(wèn)題描述
我想在可以使用 AJAX 的產(chǎn)品頁(yè)面上制作一個(gè)添加到購(gòu)物車"按鈕.我該怎么做?當(dāng)我在產(chǎn)品頁(yè)面上添加到購(gòu)物車時(shí) - 它會(huì)刷新頁(yè)面,我如何通過(guò) AJAX 使其工作?
I want to make an "Add To Cart" button on a product page that would work with AJAX. How can I do it? When I add to cart on a product page - it refreshes the page, how can I make it work by AJAX?
存檔中快速查看"上的添加到購(gòu)物車"按鈕由 ajax 工作 - 這很棒,但我如何在產(chǎn)品頁(yè)面上做同樣的事情?
The "Add to cart" button on "Quick View" on archive works by ajax - and it's great, but how can I do the same on product page?
我想點(diǎn)擊產(chǎn)品頁(yè)面上的帶我回家",然后通過(guò) ajax 將具有選定屬性的產(chǎn)品添加到我的購(gòu)物車,然后打開(kāi)該購(gòu)物車(就像您將鼠標(biāo)懸停在菜單上的包圖片上一樣)并搖晃包圖片.
I want to click on "Take me Home" on the product page which would then add the product with the selected attributes to my cart by ajax and will open that cart (like when you hover onto the bag image on menu) and shakes the bag image.
推薦答案
只需將以下屬性添加到添加到購(gòu)物車"按鈕即可啟用 Ajax 按鈕.
Just add the following attributes to the Add to Cart button to enable the Ajax button.
<a href="<?php echo $product->add_to_cart_url() ?>" value="<?php echo esc_attr( $product->get_id() ); ?>" class="ajax_add_to_cart add_to_cart_button" data-product_id="<?php echo get_the_ID(); ?>" data-product_sku="<?php echo esc_attr($sku) ?>" aria-label="Add "<?php the_title_attribute() ?>" to your cart"> Add to Cart </a>
ajax_add_to_cart add_to_cart_button
類,以及 data-product_id="<?php echo get_the_ID();?>>data-product_sku=""
屬性是必需的.
The ajax_add_to_cart add_to_cart_button
classes, and the data-product_id="<?php echo get_the_ID(); ?>" data-product_sku="<?php echo esc_attr($sku) ?>"
attributes are required.
無(wú)需應(yīng)用任何操作或過(guò)濾器.
No need to apply any action or filter.
這篇關(guān)于Woocommerce - 產(chǎn)品頁(yè)面 - 如何在“添加到購(gòu)物車"上創(chuàng)建 AJAX按鈕?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!