Woocommerce - 产品页面 - 如何在“添加到购物车"上创建 AJAX按钮?

Woocommerce - Product Page - How to create AJAX on quot;Add To Cartquot; button?(Woocommerce - 产品页面 - 如何在“添加到购物车上创建 AJAX按钮?)
本文介绍了Woocommerce - 产品页面 - 如何在“添加到购物车"上创建 AJAX按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在可以使用 AJAX 的产品页面上制作一个添加到购物车"按钮.我该怎么做?当我在产品页面上添加到购物车时 - 它会刷新页面,我如何通过 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?

存档中快速查看"上的添加到购物车"按钮由 ajax 工作 - 这很棒,但我如何在产品页面上做同样的事情?

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?

我想点击产品页面上的带我回家",然后通过 ajax 将具有选定属性的产品添加到我的购物车,然后打开该购物车(就像您将鼠标悬停在菜单上的包图片上一样)并摇晃包图片.

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.

推荐答案

只需将以下属性添加到添加到购物车"按钮即可启用 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.

无需应用任何操作或过滤器.

No need to apply any action or filter.

这篇关于Woocommerce - 产品页面 - 如何在“添加到购物车"上创建 AJAX按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Codeigniter htaccess to remove index.php and www(Codeigniter htaccess 删除 index.php 和 www)
htaccess mod_rewrite part of url to GET variable(htaccess mod_rewrite url 的一部分到 GET 变量)
Replacing a querystring parameter value using mod_rewrite(使用 mod_rewrite 替换查询字符串参数值)
.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
How to rewrite SEO friendly url#39;s like stackoverflow(如何像stackoverflow一样重写SEO友好的url)
Is it okay to have a very long .htaccess file?(有一个很长的 .htaccess 文件可以吗?)