按钮单击时更新update_order_review() [英] update_order_review( ) on button click

查看:73
本文介绍了按钮单击时更新update_order_review()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的结帐页面上有一个自定义按钮,点击我通过AJAX将产品添加到购物车。

I have a custom button on my checkout page, on click I'm adding a product to cart via AJAX.

JS:

$('#add_domain_product').on('click', function() {
        $.ajax({
            url: Ajax.ajaxurl,
            type: "POST",
            data: {
                action: 'add_domain_product',
            },
            success: function (data, status, xhr) {
                // update command is executed.
                console.log(data);
            }

        });
    })

PHP :

add_action('wp_ajax_add_domain_product', 'bs_add_domain_product');
function bs_add_domain_product() {
    global $woocommerce;
    $woocommerce->cart->add_to_cart('633');
    exit();
}

之后,我需要刷新订单审核,因此显示我新增的产品也是。我该怎么做?

After that, I'd need to refresh the order review, so it displays my newly added product also. How can I do that?

推荐答案

您需要做的就是在身体上调用触发器来更新购物车。

All you need to do is call a trigger on the body to update the cart.

$( 'body' ).trigger( 'update_checkout' );

这将自动调用刷新购物车信息所需的所有后续AJAX调用,包括订单审核。

This will automatically call all the subsequent AJAX calls needed to refresh the cart information, including the order review.

这篇关于按钮单击时更新update_order_review()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆