小编rob*_*ped的帖子

通过 PHP 或 jQuery 刷新 cart_fragments(mini-cart)?

我试图在 ajax 事件之后/期间更新迷你购物车 (cart_fragments)。它的工作原理是这样的。

HTML 触发器:

<a id="woomps-button-\'.$nr.\'" class="woomps-button" '.$ajax_url.' data-button-nr="'.$nr.'">
Run Code Online (Sandbox Code Playgroud)

jQuery 请求:

jQuery( document ).on('click', '.woomps-button', function() {
    var nr= jQuery(this).data('button-nr');
    jQuery.ajax({
        url : subpost.ajax_url,
        type : 'post',
        data : {
            action : 'woomps_update_nr',
            security : subpost.security,
            nr: nr
        },
        success : function( response ) {
            window.alert(nr);
            //MAYBE_code to refresh_fragments here
            }
    });
    return false;
});
Run Code Online (Sandbox Code Playgroud)

PHP 响应程序:

function woomps_update_choosen_person () {
    $p = $_POST['nr'];
    if ($p == 1) {$x= "This must show in cart";}
    WC()->session->set( 'woomps_limit_by_persons' , $x …
Run Code Online (Sandbox Code Playgroud)

php ajax wordpress jquery woocommerce

1
推荐指数
1
解决办法
6030
查看次数

标签 统计

ajax ×1

jquery ×1

php ×1

woocommerce ×1

wordpress ×1