簡體   English   中英

單擊 [加入購物車] 打開彈出窗口 - Woocommerce

[英]Open popup on click [Add to cart] - Woocommerce

在 Woocommerce 中,當用戶單擊“添加到購物車”按鈕時,我需要打開一個模式彈出窗口。 我試過這個,但它不起作用:

在函數中。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();
    });
});

任何幫助表示贊賞。

彈出模式僅適用於 Ajax,因此您必須首先使用 Ajax 來添加到購物車 function。

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

為我工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM