我试图在 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)