Site logo

Archived topic

Woocommerce 7.4 - product page quantity buttons

14 replies · Started by Sam on February 25, 2023

Viewing posts 1–15 of 15

Hello, since updating to woocommerce 7.4 I have noticed that on the product page, when a simple product only has one unit in stock, there are some empty quantity buttons displayed: https://snipboard.io/isflJo.jpg

These used to be hidden if quantity is 1. Is this something that needs updating in GP?

Kind regards
Sam

Note: I managed to hide them with the following CSS but this is not ideal as it causes the quantity buttons to be hidden briefly on simple product pages with inventory greater than 1. This obviously counts negatively as cumulative layout shift and so is bad for SEO so I need a better way of fixing the issue.

.woocommerce .product .quantity:not(.buttons-added) {
	display: none;
}

Hi there,

thanks for reporting this, not sure if its a bug or if the your Woo database needs updating. Make sure it is updated, and then clear any of the Woo caches.

If the issues persists, let us know, and you can use this snippet as temporary fix:

add_filter( 'post_class', 'remove_post_class_if_single_product_low_stock', 10, 3 );
function remove_post_class_if_single_product_low_stock( $classes, $class, $post_id ) {
    if ( is_product() ) {
        $product = wc_get_product( $post_id );
        if ( $product && $product->is_type( 'simple' ) && $product->managing_stock() && $product->get_stock_quantity() <= 1 ) {
            $classes = array_diff( $classes, array( 'do-quantity-buttons' ) );
        }
    }

    return $classes;
}

My DB version matches the Woocommerce version so I do not think it needs updating.

Thanks for your snippet, although it only partially works, it still leaves some styling from the +/- buttons so it is slightly out of alignment: https://snipboard.io/k7VhJM.jpg

Can you clear any of the Woocommerce caches in Woocommerce > Status > Tools, and then clear any plugin / server caches ?

The only option is "Clear template cache" I do not know what that does but I assume this is what you mean?

Never mind, clearing caches or transients won't make a difference, i have been able to replicate the issue locally.
Add this CSS to remove that space when there are no quantity buttons displayed:

.single-product article:not(.do-quantity-buttons) form.cart div.quantity {
    margin-right: 0 !important;
}

OK thanks, that worked.

Will the issue be patched in an update?

thanks

Yep, thanks for reporting it, i have it on our GitIssues and we should be able to push an update out once we figure out Woo changed to cause the issue :)

I have the same issue. I have used CSS to hide the +/- buttons on the single product page, but they still show on the cart page. Will your fix remove them from the cart page as well for products sold individually?

Any idea of an ETA for the fix?
Thanks

Hi there,

if that issue is related then yes it should fix the cart page.
However these issues stem from Woocommerce changes to which there are several issues they have open, so we expect to see them make some changes.

The GP Changes as raised here, have been patched on GP Premium 2.3 - see here:

https://generatepress.com/category/changelog/

If you want to test then the alpha release is available in the your account.

Any testing and feedback would be much appreciated.

OK. I have realised that my situation is slightly different. My product is set up to be 'sold individually'. So the 'in stock ' quantity is greater than 1 but the customer is only allowed to purchase 1 of the product
product setting

GP correctly hides the quantity but it still shows the +/- buttons on the single product and cart pages see:

https://u.pcloud.link/publink/show?code=XZ17zwVZRLNxk8NQrz8fuOQRJRM91FtSvtCy

If I disable the GP Premium 'Woocommerce' module then the cart page displays correctly - i.e. no +/- buttons. See:
https://u.pcloud.link/publink/show?code=XZN7zwVZsgRpa3QPwoppeK7cETd24XkxXUmV

Hopefully you have a fix in the pipeline for this as well?

Are you running the latest version of GP Premium ? Now 2.3.1

If so can i see the site where the problems are. If needed raise a new topic where you will have access to the Private Information field.

This archived topic is closed to new replies.