[Theming Snippets] Hide loop read more buttons for out of stock items
This breaks the ajax functionality on the add to cart button for single products on the Storefront theme.
(After implementing the code, the page reloads entirely and brings me back to the top of the page when I click the add to cart button for single products on the archive pages. Without the code, the button works as intended; the product is added to the cart WITHOUT a full page refresh.)
Yes this is breaking the default woocommerce ajax functionality of the 'Add to cart' buttons.
Though I don't like removing elements this way a quick fix alternative is to simply hide the out-of-stock item buttons with CSS:
.products .outofstock .button {
display: none;
}
This code works from Tom Usborne:
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
if ( 'Read more' == $text ) {
$text = __( 'More Info', 'woocommerce' );
}
return $text;
} );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using OceanWP with Code Snippets and it returned: