Automattic\WooCommerce\Blocks\BlockTypes
AddToCartForm::add_steppers
Add increment and decrement buttons to the quantity input field.
Метод класса: AddToCartForm{}
Хуков нет.
Возвращает
Строку. Add to Cart form HTML with increment and decrement buttons.
Использование
// private - только в коде основоного (родительского) класса $result = $this->add_steppers( $product_html, $product_name );
- $product_html(строка) (обязательный)
- Add to Cart form HTML.
- $product_name(строка) (обязательный)
- Product name.
Код AddToCartForm::add_steppers() AddToCartForm::add steppers WC 10.5.0
private function add_steppers( $product_html, $product_name ) {
// Regex pattern to match the <input> element with id starting with 'quantity_'.
$pattern = '/(<input[^>]*id="quantity_[^"]*"[^>]*\/>)/';
// Replacement string to add button AFTER the matched <input> element.
/* translators: %s refers to the item name in the cart. */
$minus_button = '$1<button aria-label="' . esc_attr( sprintf( __( 'Reduce quantity of %s', 'woocommerce' ), $product_name ) ) . '" type="button" data-wp-on--click="actions.removeQuantity" class="wc-block-components-quantity-selector__button wc-block-components-quantity-selector__button--minus">−</button>';
// Replacement string to add button AFTER the matched <input> element.
/* translators: %s refers to the item name in the cart. */
$plus_button = '$1<button aria-label="' . esc_attr( sprintf( __( 'Increase quantity of %s', 'woocommerce' ), $product_name ) ) . '" type="button" data-wp-on--click="actions.addQuantity" class="wc-block-components-quantity-selector__button wc-block-components-quantity-selector__button--plus">+</button>';
$new_html = preg_replace( $pattern, $plus_button, $product_html );
$new_html = preg_replace( $pattern, $minus_button, $new_html );
return $new_html;
}