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按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)