functions – Woocommerce: Allow backorders on entire catalogue and notify customer with specific message

Question

I want to enable backorders on my entire catalogue in woocommerce and notify customer with a message like “Shipment of this product could be delayed”. I find this code:

// Change all products stock statuses to 'instock'
add_filter( 'woocommerce_product_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
function filter_get_stock_status_callback( $stock_status, $product ){
    return is_admin() ? $stock_status : 'instock';
}

// Enable backorders on all products
add_filter( 'woocommerce_product_get_backorders', 'filter_get_backorders_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_backorders', 'filter_get_backorders_callback', 10, 2 );
function filter_get_backorders_callback( $backorders_status, $product ){
    return 'yes'; // Enable withouttifications
}

// Remove the stock quantity from displayed stock status
add_filter( 'woocommerce_get_availability_text', 'filter_get_availability_text_callback', 10, 2 );
function filter_get_availability_text_callback( $availability_text, $product ){
    return __( 'In stock', 'woocommerce');
}

but makes all products as normally in stock and no custom message for zero stock products.

0
sm77 3 weeks 2021-05-26T02:03:17-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse