0

WooCommerce has a product option to “allow backorder but inform customer” which shows a notice on the frontend product page. How can I change the text of this notice?

I have seen this helpful post https://storepro.io/learn/how-to-change-out-of-stock-text-in-woocommerce/ sharing how to change "out of stock" text, but that is different from the "backorder allowed" text.

Code snippet for function.php from the above linked page:

add_filter('woocommerce_get_availability_text', 'themeprefix_change_soldout', 10, 2 );

/* Change Sold Out Text to Something Else */
function themeprefix_change_soldout ( $text, $product) {
if ( !$product->is_in_stock() ) {
$text = '<div class="">My custom sold out message.</div>';
}
return $text;
}
OC2PS
  • 1,037
  • 3
  • 19
  • 34

1 Answers1

1

You can copy the code from original source code for the backorder validation and rewrite the status text and return it from the function.

Here is the code:

function vh_wc_custom_get_availability_text( $availability, $_product ) {
    if ( $_product->managing_stock() && $_product->is_on_backorder( 1 ) ) {
        $availability = $_product->backorders_require_notification() ? __( 'Your new text goes here', 'your-child-theme-text-domain' ) : '';
    } elseif ( ! $_product->managing_stock() && $_product->is_on_backorder( 1 ) ) {
        $availability = __( 'Your new text goes here', 'your-child-theme-text-domain' );
    }

    return $availability;
}
add_filter( 'woocommerce_get_availability_text', 'vh_wc_custom_get_availability_text', 10, 2 );

You can check this page for more detail on woocommerce_get_availability_text filter hook.

Vijay Hardaha
  • 2,411
  • 1
  • 7
  • 16
  • Thank you! And I'd like to make the same change, i.e. change the "backorder allowed" text in the cart + checkout. – OC2PS Dec 18 '22 at 12:42