
Здравствуйте, при изменении в самой корзине количества товара не меняется сумма отображения. На пример , есть товар с суммой 2000р , соответствеено в поле quantity ставлю 3 должно поменять цену на 6000р , но цена остается прежней (корзина обновляется ajax-запросом)
Шаблон mini-cart.php:
basket.js (обработчик на увеличение quantinty ) :
Буду благодарен за любые советы
Шаблон mini-cart.php:
PHP:
<?php
do_action( 'woocommerce_before_mini_cart' ); ?>
<ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">
<?php
do_action( 'woocommerce_before_mini_cart_contents' );
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
$product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
$product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
?>
<!-- Корзина шаблон -->
<div class="basket_line row align-items-center justify-content-between" data-link="<?php the_permalink();?>" data-id="<?php echo get_the_ID();?>">
<div class="col-md-3 col-4 img-cart-ad">
<?php if ( empty( $product_permalink ) ) : ?>
<?php echo $thumbnail . $product_name; ?>
<?php else : ?>
<a class="img-cart-ad" href="<?php echo esc_url( $product_permalink ); ?>">
<?php echo $thumbnail; ?>
</a>
<?php endif; ?>
</div>
<div class="col-md-3 col-8 col-lg-4"><a href="<?php the_permalink();?>" target="_blank" class="basket_title">
<?php
if ( ! $product_permalink ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . ' ' );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
}
do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );
// Meta data.
echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok.
// Backorder notification.
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>', $product_id ) );
}
?>
</a></div>
<!-- Количество -->
<div class="col-lg-2 col-6 col-md-3 basket_inc_dec">
<button class="basket_dec">–</button>
<?php
if ( $_product->is_sold_individually() ) {
$product_quantity = sprintf( '1 <input type="hidden" class="basket_num" name="cart[%s][qty]" value="1" />', $cart_item_key );
} else {
$product_quantity = woocommerce_quantity_input( array(
'input_name' => "cart[{$cart_item_key}][qty]",
'input_value' => $cart_item['quantity'],
'max_value' => $_product->get_max_purchase_quantity(),
'min_value' => '0',
'product_name' => $_product->get_name(),
), $_product, false );
}
echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); // PHPCS: XSS ok.
?>
<button class="basket_inc">+</button>
</div>
<!-- Количество конец -->
<div class="col-md-3 col-6">
<div class="basket_new_price"><span class="basket_price"><?php
echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // PHPCS: XSS ok.
?></span></div>
</div>
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" class="remove remove_from_cart_button basket_delete" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s"></a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'woocommerce' ),
esc_attr( $product_id ),
esc_attr( $cart_item_key ),
esc_attr( $_product->get_sku() )
), $cart_item_key );
?>
</div>
<!-- корзина шаблон конец -->
<?php /*
<li class="woocommerce-mini-cart-item235 <?php echo esc_attr( apply_filters( 'woocommerce_mini_cart_item_class', 'mini_cart_item', $cart_item, $cart_item_key ) ); ?>">
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" class="remove remove_from_cart_button" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s">×</a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'woocommerce' ),
esc_attr( $product_id ),
esc_attr( $cart_item_key ),
esc_attr( $_product->get_sku() )
), $cart_item_key );
?>
<?php if ( empty( $product_permalink ) ) : ?>
<?php echo $thumbnail . $product_name; ?>
<?php else : ?>
<a href="<?php echo esc_url( $product_permalink ); ?>">
<?php echo $thumbnail . $product_name; ?>
</a>
<?php endif; ?>
<?php echo wc_get_formatted_cart_item_data( $cart_item ); ?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
</li>
*/?>
<?php
}
}
do_action( 'woocommerce_mini_cart_contents' );
?>
</ul>
<?php do_action( 'woocommerce_after_mini_cart' ); ?>
basket.js (обработчик на увеличение quantinty ) :
JavaScript:
$('.basket_dec').click(function(){
data_id = $(this).parents('.basket_line').attr('data-id');
input = $(this).parents('.basket_line').find('.qty');
parseInt(input.attr('value', +input.attr('value')-1));
if(parseInt(input.attr('value')) < 1) {
input.attr('value', 1);
}
basket_cookie[data_id] = parseInt(input.attr('value'));
basket_cookie2 = JSON.stringify(basket_cookie);
Cookies.set('basket_cookie', basket_cookie2, { expires: 7, path: '/' });
});
$('.basket_inc').click(function(){
input = $(this).parents('.basket_line').find('.qty');
data_id = $(this).parents('.basket_line').attr('data-id');
parseInt(input.attr('value', +input.attr('value')+1));
basket_cookie[data_id] = parseInt(input.attr('value'));
basket_cookie2 = JSON.stringify(basket_cookie);
Cookies.set('basket_cookie', basket_cookie2, { expires: 7, path: '/' });
});
Буду благодарен за любые советы