Woocommerce - 移动添加到购物车按钮变量产品 [英] Woocommerce - Move add to cart button variable product

查看:51
本文介绍了Woocommerce - 移动添加到购物车按钮变量产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自定义主题.我需要将添加到购物车按钮从 woocommerce_single_variation (variable.php) 部分移到 woocommerce_after_single_product_summary (content-single-product.php) 部分.

I am working on a custom theme. I need to move the add to cart button from the woocommerce_single_variation (variable.php) section into the woocommerce_after_single_product_summary (content-single-product.php) section.

通过将以下内容添加到我的 functions.php 文件中,我已经能够做到这一点.

I have been able to do this by adding the following to my functions.php file.

function remove_loop_button(){
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}
add_action('init','remove_loop_button');

add_action( 'woocommerce_after_single_product_summary', 'woocommerce_single_variation_add_to_cart_button', 30 );

但是,当我执行此操作时,按钮会显示但不起作用.点击它什么也不做.有谁知道是否可以以这种方式移动添加到购物车按钮?请注意,这是针对非单一的可变产品,所以我认为行为是不同的.

However when I do this the button shows up but is not functional. Clicking on it just does nothing. Does anyone know is it possible to move the add to cart button in such a way? Please note this is for variable products not single so I'm thinking the behavior is different.

感谢您提供的任何帮助.谢谢!

I appreciate any help that can be given. Thanks!

推荐答案

正如@LoicTheAztec 所提到的,您的 添加到购物车 按钮已从产品表单中移出,因此除非您编写一些 JS 来模拟 submit 动作.

As @LoicTheAztec mentioned, your add to cart button moved out from the product form, so it won't do anything unless you write some JS to simulate that submit action.

function inject_add_cart_form_script() { ?>

<script type="text/javascript">

(function($){
    $(document).on( 'click', 'single_add_to_cart_button', function(){
        $('form.cart').submit();
    });
})(jQuery);

</script>
<?php 
}
add_action('woocommerce_after_single_product_summary', 'inject_add_cart_form_script');

这篇关于Woocommerce - 移动添加到购物车按钮变量产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆