Php 从购物车删除和更新购物车数据返回零
我试图减去一个产品或从购物车中删除一个产品。假设购物车中有3个相同的项目,我想减去一个,但我使用的ajax不起作用。我在控制台日志中返回零。我想这个零来自wp die()。但它应该返回一些数据 下面是我在functions.php中的代码 和JS代码 但在控制台中它只返回零 在js传递的变量散列中,nonce和qty都可以 从中获取php代码Php 从购物车删除和更新购物车数据返回零,php,ajax,wordpress,woocommerce,Php,Ajax,Wordpress,Woocommerce,我试图减去一个产品或从购物车中删除一个产品。假设购物车中有3个相同的项目,我想减去一个,但我使用的ajax不起作用。我在控制台日志中返回零。我想这个零来自wp die()。但它应该返回一些数据 下面是我在functions.php中的代码 和JS代码 但在控制台中它只返回零 在js传递的变量散列中,nonce和qty都可以 从中获取php代码 您应该使用下面类似的代码: function removefromCart( hash, nonce, qty ){ $.ajax
您应该使用下面类似的代码:
function removefromCart( hash, nonce, qty ){
$.ajax({
type : 'POST',
url : cart_ajax.ajaxurl,
data : {
'hash' : hash,
'nonce' : nonce,
'quantity' : qty,
action : 'the_foody_removefrom_cart_process',
},
beforeSend : function(){
// codes to execute
},
success : function(response){
console.log(response);
}
})
}
add_action( 'wp_ajax_the_foody_removefrom_cart_process', 'the_foody_removefrom_cart_process' ); // If called from admin panel
add_action( 'wp_ajax_nopriv_the_foody_removefrom_cart_process', 'the_foody_removefrom_cart_process' );
而不是
add_action( 'wp_ajax_foody_removefrom_cart', 'the_foody_removefrom_cart_process' ); // If called from admin panel
add_action( 'wp_ajax_nopriv_foody_removefrom_cart', 'the_foody_removefrom_cart_process' );
已更新
type : 'POST',
url : cart_ajax.ajaxurl,
data : {
'hash' : hash,
'nonce' : nonce,
'quantity' : qty,
action : 'the_foody_removefrom_cart_process',
},
没有任何变化。这不是一个过程问题。在alsoaction之前一切正常:“从购物车中移除的食物”应该在数据中。
add_action( 'wp_ajax_foody_removefrom_cart', 'the_foody_removefrom_cart_process' ); // If called from admin panel
add_action( 'wp_ajax_nopriv_foody_removefrom_cart', 'the_foody_removefrom_cart_process' );
type : 'POST',
url : cart_ajax.ajaxurl,
data : {
'hash' : hash,
'nonce' : nonce,
'quantity' : qty,
action : 'the_foody_removefrom_cart_process',
},