0

Возможно кто то стыкался со следующей проблемой. Через wp-query вывел на главной странице товары. Вот код:

while ($wc_query->have_posts()) : 
                $wc_query->the_post();
                global $product;
                $list .= '<div class="carousel-products__item ' . esc_attr( implode( ' ', wc_get_product_class( $class, $product_id ) ) ) . '">
                    <div class="product-inner">
                        <div class="product-inner__img"><a href="'.get_the_permalink().'" title="'.get_the_title().'" itemprop="url">';
                            if ( $product->is_on_sale() ) {
                                $list .= apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . esc_html__( 'Sale!', 'mojmedik' ) . '</span>', $post, $product );
                            }
                            $list .= woocommerce_get_product_thumbnail() . '</a>
                            <div class="box-buttons">';
                                if ( $product ) {
                                    $defaults = array(
                                        'quantity'   => 1,
                                        'class'      => implode(
                                            ' ',
                                            array_filter(
                                                array(
                                                    'button',
                                                    'product_type_' . $product->get_type(),
                                                    $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
                                                    $product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
                                                )
                                            )
                                        ),
                                        'attributes' => array(
                                            'data-product_id'  => $product->get_id(),
                                            'data-product_sku' => $product->get_sku(),
                                            'aria-label'       => $product->add_to_cart_description(),
                                            'rel'              => 'nofollow',
                                        ),
                                    );

                                    $args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );

                                    if ( isset( $args['attributes']['aria-label'] ) ) {
                                        $args['attributes']['aria-label'] = wp_strip_all_tags( $args['attributes']['aria-label'] );
                                    }

                                    $list .= apply_filters(
                                        'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
                                        sprintf(
                                            '<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
                                            esc_url( $product->add_to_cart_url() ),
                                            esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
                                            esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
                                            isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
                                            esc_html( $product->add_to_cart_text() )
                                        ),
                                        $product,
                                        $args
                                    );
                                }
                            $list .= '<a href="'.get_the_permalink().'" class="view-product"><i class="fa fa-search"></i></a>
                            </div>
                        </div>
                        <div class="product-inner__info">
                            <h5 itemprop="name"><a href="'.get_the_permalink().'" title="'.get_the_title().'" itemprop="url">'.get_the_title().'</a></h5>
                            <div class="product-inner__price">';
                                if($product->get_price()) {
                                    $list .= '<span class="price product-price">'.$product->get_price().' €</span>';
                                    if($product->get_sale_price()) $list .= '<span class="price_before_label"> Pred zľavou</span><span class="old-price product-price"> '.$product->get_regular_price().' €</span>';
                                    $list .= '<span class="price_tax_label">S DPH</span>';
                                }
                                $list .= '<div class="price_delivery_label">Dodanie: 1 až 3 dni</div>
                            </div>
                        </div>
                    </div>
                </div>';
            endwhile;

Мини корзина выводится так:

<div class="header-cart-inner">
                                    <a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart', 'mojmedik' ); ?>" rel="nofollow">
                                        <span class="title-cart"><?php _e( 'Shopping cart', 'mojmedik' ); ?></span>
                                        <span class="cart-content"><?php echo WC()->cart->get_cart_contents_count() . ' ' . __( 'product(s)', 'mojmedik' ); ?> - <?php echo WC()->cart->get_cart_total(); ?></span>
                                    </a>
                                    <div class="header-mini-cart widget_shopping_cart_content"><?php woocommerce_mini_cart(); ?></div>
                                </div>

При добавлении в корзину товара, моя мини корзина что находится в шапке обновляется, но обновляется только один товар. Например, добавляю я в корзину Товар 1, товар 2, товар 3 и товар 4. Но в корзину добавится только Товар 1 - 4 шт. ВОт такой баг, возможно кто то уже имел с таким дело, помогите???

Этот баг только на главной, где товары через wp-query. В магазине и на странице категории - все нормально.

1
  • В стандартном виде обновляется класс .widget_shopping_cart_content, который возвращает woocommerce_mini_cart()
    – user243545
    22 апр 2020 в 17:10

1 ответ 1

0

Уже решил проблему сам. Нужно было обнулить переменную $args

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.