My Yith Preorder plugin is overiding the backorder function.

[ad_1]

Hello!

So I have products that go on pre order 2 weeks before release. I know how many I have coming so I have the appropriate qty.

Once that sells out the product needs to go on backorder however the YITH plugin is still showing the button as “pre order” instead of “backorder”.

The custom can still see the backorder notice on the cart page but if they add to cart and then immediately check out they might not even be aware the product is on backorder. and often the product might be out of stock so I may not be able to get it, so I need it to display backorder correctly.

is there some simple code I can use to check the pre order status, then check stock status and then change the button text?

I have the following code which changes the button text to BACKORDER however it seems to be overwritten by this plugin. I have tried to set the priority to 1. no luck. Any advice where I can go from here?

function woocommerce_add_to_cart_button_text ( $text, $product ) {
if ( $product->is_on_backorder( 1 ) ) {
return ‘BACKORDER’;
}
return $text;
}
add_filter( ‘woocommerce_product_add_to_cart_text’ , ‘woocommerce_add_to_cart_button_text’,1,2 );

[ad_2]
2 Comments
  1. I haven’t tested this code myself but after reading a bit on YITH’s Pre-order plugin I think this could work:

    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘yith_custom_preorder_backorder_text’, 20, 2);
    add_filter(‘woocommerce_product_add_to_cart_text’, ‘yith_custom_preorder_backorder_text’, 20, 2);

    function yith_custom_preorder_backorder_text($button_text, $product) {
    if (function_exists(‘yit_get_prop’) && yit_get_prop($product, ‘_yith_preorder_enabled’, true) == ‘yes’) {
    if (!$product->is_in_stock()) {
    return __(‘Backorder’, ‘woocommerce’);
    } else {
    return __(‘Pre-Order Now’, ‘woocommerce’);
    }
    }
    return $button_text;
    }

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer