【问题标题】:Open popup on click [Add to cart] - Woocommerce单击 [添加到购物车] 打开弹出窗口 - Woocommerce
【发布时间】:2020-05-11 08:39:28
【问题描述】:

在 Woocommerce 中,当用户单击“添加到购物车”按钮时,我需要打开一个模式弹出窗口。我试过了,但它不起作用:

在functions.php中:

if (is_woocommerce() && is_archive()) {
    wp_enqueue_script( 'frontend-custom', get_template_directory_uri() . '/js/frontend-custom.js', array("jquery"));
    add_thickbox();
}

在主题目录/js/frontend-custom.js:

jQuery(document).ready(function($) {
    $('body').on('added_to_cart',function(e,data) {
        //alert('Added ' + data['div.widget_shopping_cart_content']);
        if ($('#hidden_cart').length == 0) { //add cart contents only once
            //$('.added_to_cart').after('<a href="#TB_inline?width=600&height=550&inlineId=hidden_cart" class="thickbox">View my inline content!</a>');
            $(this).append('<a href="#TB_inline?width=300&height=550&inlineId=hidden_cart" id="show_hidden_cart" title="<h2>Cart</h2>" class="thickbox" style="display:none"></a>');
            $(this).append('<div id="hidden_cart" style="display:none">'+data['div.widget_shopping_cart_content']+'</div>');
        }
        $('#show_hidden_cart').click();
    });
});

任何帮助表示赞赏。

【问题讨论】:

    标签: php jquery wordpress woocommerce


    【解决方案1】:

    弹出模式仅适用于 Ajax,因此您最好先使用 Ajax 来实现添加到购物车功能。

    这篇文章完美地解释了如何做到这一点: https://quadmenu.com/add-to-cart-with-woocommerce-and-ajax-step-by-step/

    为我工作!

    【讨论】:

    • 今天在原版 Wordpress 和 Woocommerce 安装上尝试过,但似乎不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多