Поддержка WooCommerce Количество товара при добавлении в корзину

  • Решено tulliuha

    (@tulliuha)


    Мне надо добавлять в корзину товар и его количество сразу со списка товара не заходя в карточку товара. Как добавить количество товара под кнопку «добавить в корзину»?

Просмотр 1 ответа (всего 1)
  • Автор tulliuha

    (@tulliuha)

    Решение!

    To display quantity input fields for simple products within your shop archive pages, use the following code:

    You will need to add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

    /**
     * Override loop template and show quantities next to add to cart buttons
     */
    add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
    function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    	if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
    		$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
    		$html .= woocommerce_quantity_input( array(), $product, false );
    		$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
    		$html .= '</form>';
    	}
    	return $html;
    }
    • Ответ изменён 4 года назад пользователем tulliuha.
    • Ответ изменён 4 года назад пользователем Denis Yanchevskiy. Причина: Оформление кода
Просмотр 1 ответа (всего 1)
  • Тема «Количество товара при добавлении в корзину» закрыта для новых ответов.