- This topic has 4 replies, 2 voices, and was last updated 1 year, 6 months ago by
Jerry.
-
AuthorPosts
-
November 22, 2020 at 10:47 am #1541360
Jerry
Hi guys,
I want to add Quantity Buttons to the Add to Cart on the Shops page (like you have on the products page).
I have found this code:
/** * 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; }
This works BUT… it doesn’t align. What is a better alternative or solution?
http://jeroenc2.sg-host.com/shop/
Thanks guys!
November 22, 2020 at 12:19 pm #1541444Elvin
StaffCustomer SupportHi,
To clarify: Do you want it to be center aligned?
If so, you can add this CSS:
.add-to-cart-panel .cart.do-quantity-buttons div.quantity, .do-quantity-buttons div.quantity{ justify-content: center; }
A wise man once said:
"Have you cleared your cache?"November 22, 2020 at 4:35 pm #1541583Jerry
This worked great! How can I add padding to the top of the Quantity Plus/Minus button and the actual price? Is this possible?
November 22, 2020 at 4:47 pm #1541589Elvin
StaffCustomer SupportThis worked great! How can I add padding to the top of the Quantity Plus/Minus button and the actual price? Is this possible?
Sure you can.
You can use the same CSS selector and add
padding-top: 20px;
.So it’ll look something like this:
.add-to-cart-panel .cart.do-quantity-buttons div.quantity, .do-quantity-buttons div.quantity{ justify-content: center; padding-top: 20px; }
A wise man once said:
"Have you cleared your cache?"January 2, 2021 at 6:36 pm #1603249Jerry
Hi guys,
The codes above worked great on shop pages etc however, on the product pages where “related products” are, the Quantity buttons are misaligned as in here:
How can I get these aligned center?
This is my page: http://jeroenc2.sg-host.com/product/midnight-lychee/Thank you!
-
AuthorPosts
- You must be logged in to reply to this topic.