Обновление fly cart после добавления продукта через ajax
При добавлении продукта через ajax не обновляет fly cart. мой js
function qty_cart(value_to_post,qty) {
var item_hash = qty.attr( 'name' ).replace(/cart\[([\w]+)\]\[qty\]/g, "$1");
var cart_item_key = qty.attr("id");
var classes = qty.parent().parent().parent().attr('class').split(" ");
$.ajax({
type: 'POST',
dataType: 'json',
url: cart_qty_ajax.ajax_url+classes[0],
data: {action : 'update_item_from_cart', 'cart_item_key' : cart_item_key, 'quantity' : value_to_post, hash: item_hash },
success: function(data) {
$( '.view-cart-popup' ).html(data);
}
})
}
Файл functions.php
function enqueue_cart_qty_ajax() {
wp_register_script( 'cart-qty-ajax-js', get_template_directory_uri() . '/assets/main.js', array( 'jquery' ), '', true );
wp_localize_script( 'cart-qty-ajax-js', 'cart_qty_ajax', array( 'ajax_url' => '?add-to-cart=' ) );
wp_enqueue_script( 'cart-qty-ajax-js' );
}
add_action('wp_enqueue_scripts', 'enqueue_cart_qty_ajax');
function ajax_qty_cart() {
// Set item key as the hash found in input.qty's name
$cart_item_key = $_POST['hash'];
// Get the array of values owned by the product we're updating
$threeball_product_values = WC()->cart->get_cart_item( $cart_item_key );
// Get the quantity of the item in the cart
$threeball_product_quantity = apply_filters( 'woocommerce_stock_amount_cart_item', apply_filters( 'woocommerce_stock_amount', preg_replace( "/[^0-9\.]/", '', filter_var($_POST['quantity'], FILTER_SANITIZE_NUMBER_INT)) ), $cart_item_key );
// Update cart validation
$passed_validation = apply_filters( 'woocommerce_update_cart_validation', true, $cart_item_key, $threeball_product_values, $threeball_product_quantity );
// Update the quantity of the item in the cart
if ( $passed_validation ) {
WC()->cart->set_quantity( $cart_item_key, $threeball_product_quantity, true );
}
// Refresh the page
echo do_shortcode( '[woocommerce_cart]' );
die();
}
add_action('wp_ajax_qty_cart', 'ajax_qty_cart');
add_action('wp_ajax_nopriv_qty_cart', 'ajax_qty_cart');
Как ето вигледит на сайте
если перейти в корзину товари есть но если кликнуть на fly cart их нет