I'm using Pricing deals pro plugin and i have a custom theme which displays a custom cart on shop page. I've created ajax functions for cart items update and cart price update:
For the item update i'm using this functionality:
add_action( 'wp_ajax_nopriv_upate-cartitem-filter', 'prefix_update_cart_item' );
add_action( 'wp_ajax_upate-cartitem-filter', 'prefix_update_cart_item' );
function prefix_update_cart_item (){
$product_key = $_POST[ 'itemkey' ];
$item_quantity = $_POST[ 'itemamount' ];
global $woocommerce;
wc()->cart->set_quantity($product_key, $item_quantity, true);
die();
}
To get cart totals i'm using this one:
add_action( 'wp_ajax_nopriv_upate-carttotal-filter', 'prefix_update_cart_total' );
add_action( 'wp_ajax_upate-carttotal-filter', 'prefix_update_cart_total' );
function prefix_update_cart_total(){
global $woocommerce;
$total_price = WC()->cart->get_cart_total();
echo $total_price;
}
When i'm updating the product using standard AJAX i'm getting the totals without the pricing deals plugin calculations, only after page refresh i'm getting the price after the deal. What am i missing?
I'm using Pricing deals pro plugin and i have a custom theme which displays a custom cart on shop page. I've created ajax functions for cart items update and cart price update:
For the item update i'm using this functionality:
add_action( 'wp_ajax_nopriv_upate-cartitem-filter', 'prefix_update_cart_item' );
add_action( 'wp_ajax_upate-cartitem-filter', 'prefix_update_cart_item' );
function prefix_update_cart_item (){
$product_key = $_POST[ 'itemkey' ];
$item_quantity = $_POST[ 'itemamount' ];
global $woocommerce;
wc()->cart->set_quantity($product_key, $item_quantity, true);
die();
}
To get cart totals i'm using this one:
add_action( 'wp_ajax_nopriv_upate-carttotal-filter', 'prefix_update_cart_total' );
add_action( 'wp_ajax_upate-carttotal-filter', 'prefix_update_cart_total' );
function prefix_update_cart_total(){
global $woocommerce;
$total_price = WC()->cart->get_cart_total();
echo $total_price;
}
When i'm updating the product using standard AJAX i'm getting the totals without the pricing deals plugin calculations, only after page refresh i'm getting the price after the deal. What am i missing?
Share Improve this question edited Sep 16, 2018 at 14:18 Gil asked Sep 16, 2018 at 14:12 GilGil 113 bronze badges1 Answer
Reset to default 1If you want to update your cart after a property change (such as price or item quantity), you might want to take a look at this:
https://gist.github/mikaelz/f41e29c6a99a595602e4
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744995331a4605154.html
评论列表(0条)