简体   繁体   中英

How to change the design for cart item quantity in woocommerce?

I am working on cart.php template. I am changing the design. I can't find where I could change the design of cart item quantity field. For example add : after the word quantity? There is the filter woocommerce_cart_item_quantity but I don't understand how it can help me. I just enclosed this field into div and that is all.

Image: https://ibb.co/kfdaW7

Template given by woocommerce:

<div class="product-quantity delivery" data-title="<?php esc_attr_e( 'Quantity', 'woocommerce' ); ?>">
    <?php
if ( $_product->is_sold_individually() ) {
    $product_quantity = sprintf( '1 <input type="hidden" 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 );
?>
</div>

The filter woocommerce_cart_item_quantity() is used to render the quantity field's HTML. You may pass any attribute to this filter and modify the quantity field.

To change the caption of the field, change it in the first line of the code you have shared.

<div class="product-quantity delivery" data-title="<?php esc_attr_e( 'Quantity:', 'woocommerce' ); ?>">
.
.
.
.
.
.

Finally I found the right place. It can be modified in global/quantity-input.php

I would't recommend editing plugin core files. Changes will disappear after first update.

I don't know which theme are you using, and what is the structure of HTML, but for such a simple request as yours, I would recommend using ::after pseudo element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM