Naposledy aktivní 1713290098

change-read-more-and-disable-button.php Raw
1// Change "Read More" text to "Out of Stock" for out-of-stock products
2add_filter( 'woocommerce_product_add_to_cart_text', 'change_read_more_text_for_out_of_stock_products', 10, 2 );
3function change_read_more_text_for_out_of_stock_products( $text, $product ) {
4 if ( !$product->is_in_stock() ) {
5 return 'No disponible'; // Change the text as needed
6 }
7 return $text;
8}
9
10// Remove the link of the "Add to Cart" / "Select options" / "Read More" button for out-of-stock products
11add_filter( 'woocommerce_loop_add_to_cart_link', 'remove_link_on_out_of_stock_products', 10, 2 );
12function remove_link_on_out_of_stock_products( $html, $product ) {
13 if ( !$product->is_in_stock() ) {
14 return '<button class="button" disabled>' . esc_html( $product->add_to_cart_text() ) . '</button>'; // Button is disabled and not clickable
15 }
16 return $html;
17}
18