I am trying make it when user changes the Shipping address select dropdown it dynamically add a fee to cart totals using ajax.I could able to to get the value but when select a another state it wont update the totals.
我的ajax请求:
jQuery(document).ready(function () {
jQuery('#shipping_state').change(function () {
var data = {
action: 'woocommerce_custom_fee',
security: wc_checkout_params.update_order_review_nonce,
add_order_fee: 'state',
post_data: jQuery('form.checkout').serialize()
};
jQuery.ajax({
type: 'POST',
url: wc_checkout_params.ajax_url,
data: data,
success: function (code) {
var result = '';
result = jQuery.parseJSON(code);
if …Run Code Online (Sandbox Code Playgroud)我正在开发一个基于Wordpress WooCommerce的商店。我使用ajax进行数据调用。但是我正在通过wp-admin / admin-ajax.php在function.php文件中使用自己的函数进行操作。
昨天我在woocommerce类WC_AJAX中找到了。我的问题是如何启用该类中的事件,以及如何从js中调用它们。