1

enter image description here

I want to change "Available on backorder" to another text

function change_specific_availability_text( $availability ) {

    $targeted_text = __( 'Available on backorder', 'woocommerce' );
    $targeted_text2 = __('In stock (can be backordered)', 'woocommerce');
    $targeted_text3 = __('Available on backorder', 'woocommerce');

    if ($availability[ 'class' ] == 'available-on-backorder' && $availability[ 'availability' ] == $targeted_text) {

        $availability[ 'availability' ] = __( '預購款  |  Backorder Item', 'your-theme-textdomain' );

    }
    
     if ($availability[ 'class' ] == 'in-stock' && $availability[ 'availability' ] == $targeted_text2) {

        $availability[ 'availability' ] = __( '現貨  |  Readystock Item', 'your-theme-textdomain' );

    }
    


    return $availability;

}


add_filter( 'woocommerce_get_availability', 'change_specific_availability_text', 20, 1 );

Previously I use the code above to change backorder message in the product page, but I can't change the text inside the cart even I add one more class "backorder_notification" into the function

enter image description here

Hong Ernest
  • 67
  • 1
  • 10

1 Answers1

0

Instead of what you're doing, you can filter the availability text using the woocommerce filter woocommerce_get_availability_text This filter passes the Product Object as the second param. You can add other conditions as your needs require.

add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2 );
function filter_product_availability_text( $availability_text, $product ) {
    // Check if product status is on backorder
    if ($product->get_stock_status() === 'onbackorder') {
        $availability_text = __( 'Your Custom Text Here', 'your-text-domain' );
    }
    return $availability_text;
}
Howard E
  • 5,454
  • 3
  • 15
  • 24