Skip to content

Commit 1c81781

Browse files
committed
Enhances out-of-stock badge customization
Allows greater control over the out-of-stock badge appearance and text within the product loop. Adds a filter to modify the badge class for flexible styling. Introduces a filter to customize the badge text independently of the WooCommerce default message. Adjusts badge top margin when the "read more" button is absent. Fixes the filter for hiding the "read more" button.
1 parent 4e61e92 commit 1c81781

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

woocommerce/inc/ajax-cart.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,23 @@ function bootscore_add_btn_loader_to_loop($html, $product, $args) {
6060

6161
// Check if product is in stock
6262
if ( !$product->is_in_stock() &&
63-
apply_filters('bootscore/woocommerce/loop/out-of-stock-badge', true, $product) ) {
64-
65-
$return_html .=
66-
'<p class="badge bg-secondary text-wrap mt-2 mb-0">' .
67-
esc_html(apply_filters('woocommerce_out_of_stock_message', __('This product is currently out of stock and unavailable.', 'woocommerce'))) .
63+
apply_filters('bootscore/woocommerce/loop/show-out-of-stock-badge', true, $product) ) {
64+
65+
$badge_html =
66+
'<p class="' . apply_filters('bootscore/class/woocommerce/loop/out-of-stock-badge', 'badge bg-secondary text-wrap mt-2 mb-0') . '">' .
67+
esc_html(
68+
apply_filters('bootscore/woocommerce/loop/out-of-stock-badge-text',
69+
apply_filters('woocommerce_out_of_stock_message', __('This product is currently out of stock and unavailable.', 'woocommerce'))
70+
)
71+
) .
6872
'</p>';
6973

7074
// If the product is out of stock, we add the option to return without the "read more" button
7175
if ( apply_filters('bootscore/woocommerce/loop/out-of-stock-remove-read-more', false) ) {
72-
return $return_html;
76+
return str_replace('mt-2', 'mt-auto', $badge_html);
7377
}
78+
79+
$return_html .= $badge_html;
7480
}
7581

7682
return $return_html;

0 commit comments

Comments
 (0)