• Hey. I am having a problem with the Allow Backorders. When I have this checked on the backend even if the product is in stock it says Available on backorder. I really don’t want it to say that. Unless it is out of stock. How can I fix this?

    The page I need help with: [log in to see the link]

Viewing 10 replies - 16 through 25 (of 25 total)
  • Plugin Author James Golovich

    (@jamesgol)

    I traced the code and it appears that WooCommerce is adding the ‘(can be backordered)’ text. If you change the backorder setting from ‘Allow, but notify customer’ to ‘Allow’ it will drop that. I’m actually surprised it doesn’t only notify if the item is actually out of stock but can be backordered. There were some changes to WooCommerce in version 3.3.4 related to this, I’ll do some digging to see how it used to work compared to now.

    Thread Starter karenlg

    (@karenlg)

    Ok. Thank you. I just really don’t want it to say anything about Back Orders until it is out of stock. When it is out of stock that is when I want it to say Available for Back Orders.

    Plugin Author James Golovich

    (@jamesgol)

    I’m baffled by the WooCommerce backorder system. Here is the output variations with stock WooCommerce (not running my plugin)

    Allow backorders: “Do not allow”
    with quantity 1: “1 in stock”
    with quantity 0: “Out of stock”

    Allow backorders: “Allow, but notify customer”
    with quantity 1: “1 in stock (can be backordered)”
    with quantity 0: “Available on backorder”

    Allow backorders: “Allow”
    with quantity 1: “1 in stock”
    with quantity 0: <no message displayed at all>

    It seems like there should either be a 4th option to notify only on out of stock or the ‘notify customer’ option shouldn’t add the (can be backorderd) bit if it’s in stock.

    Plugin Author James Golovich

    (@jamesgol)

    Here is a code snippet that you can add to your theme’s functions.php file or somewhere else that will keep the ‘(can be backordered)’ text from being displayed if the product is in stock.

    
    add_filter( 'woocommerce_product_backorders_require_notification', 'jmg_backorders_notification', 10, 2 );
    function jmg_backorders_notification( $notify, $product = null ) {
    	if ( $product && 'notify' === $product->get_backorders() && $product->is_in_stock() ) {
    		return false;
    	}
    	return $notify;
    }
    Thread Starter karenlg

    (@karenlg)

    When I tried to add this to the Staging functions.php file it gave me this error.

    Scrape nonce check failed. Please try again.

    Plugin Author James Golovich

    (@jamesgol)

    I don’t see that type of error in the code for WordPress core or WooCommerce so it must be from something else. That minor change should certainly not cause any problems.

    I did google the search and it sounds like you are using the builtin theme/plugin editor. I would never recommend anyone actually use that, but regardless in a somewhat recent version of WordPress core they changed it so it will check to make sure any changes don’t cause issues before actually saving the file. Unfortunately it is somewhat buggy and does not generally return a meaningful error code. I would suspect the problem is similar to your cron problem, your staging site cannot contact itself so cron cannot be triggered and this editor cannot verify if the modification generates an error.

    Thread Starter karenlg

    (@karenlg)

    Just to make sure we are on the same page. I need to add the code given above to the cPanle? Or is there another spot within WordPress that I can add it?

    If it’s the cPanel functions.php file how can I do this with my stage site?

    Sorry for all the questions. I really appreciate all the help.

    Plugin Author James Golovich

    (@jamesgol)

    Everyone’s setup is different so it’s tough to say what the best method is without knowing your exact setup.

    If you are using a child theme or a theme you created yourself then adding the code to the functions.php file seems like a good strategy. Otherwise you would want to put it somewhere else, since an update of the theme would wipe out that file.

    Often times it’s good to keep a separate plugin of your own tweaks so they can be used independent of the theme being used.

    Sorry I’m so vague, there are so many different ways to have WordPress setup that there isn’t a one size fits all.

    Thread Starter karenlg

    (@karenlg)

    When I got the error message I was in the child theme functions.php file

    Would it being a staging site have anything to do with the error?

    Also, do I need to have the latest version of your plugin for this code to work? If so is it ready for me to put on my live site or you still working on testing it?

    Plugin Author James Golovich

    (@jamesgol)

    It sounds like the error you got was due to WordPress’s theme/plugin editor “protecting” people from screwing up their site since version 4.9. There are situations where it doesn’t work properly and does not provide a meaningful error message.

    This bit of code works regardless of my plugin, it just keeps WooCommerce from displaying any backorder notification if the product is still in stock.

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Available on backorder’ is closed to new replies.