Automattic\WooCommerce\Blocks\BlockTypes
AddToCartForm::add_steppers()
Add increment and decrement buttons to the quantity input field.
Метод класса: AddToCartForm{}
Хуков нет.
Возвращает
Строкуa
. 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 9.7.1
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 BEFORE the matched <input> element. /* translators: %s refers to the item name in the cart. */ $minus_button = '<button aria-label="' . esc_attr( sprintf( __( 'Reduce quantity of %s', 'woocommerce' ), $product_name ) ) . '"type="button" data-wc-on--click="actions.removeQuantity" class="wc-block-components-quantity-selector__button wc-block-components-quantity-selector__button--minus">-</button>$1'; // 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-wc-on--click="actions.addQuantity" class="wc-block-components-quantity-selector__button wc-block-components-quantity-selector__button--plus">+</button>'; $new_html = preg_replace( $pattern, $minus_button, $product_html ); $new_html = preg_replace( $pattern, $plus_button, $new_html ); return $new_html; }