Woocommerce and Pricing deals plugin total price update with AJAX

I'm using Pricing deals pro plugin and i have a custom theme which displays a custom cart on shop page.I've c

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

If 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

相关推荐

  • Woocommerce and Pricing deals plugin total price update with AJAX

    I'm using Pricing deals pro plugin and i have a custom theme which displays a custom cart on shop page.I've c

    18小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信