Woo Allowing Out of Stock Items to be Purchased
-
Hi
Is there a way to stop Woo allowing customers to purchase out of stock items that are in their carts?
I do not want to empty their carts after a certain amount of time. When testing I can see Woo knows these items are out of stock so surely it should not let me purchase them.
Is there a plugin or an extension to help with this?
I would like a message to pop up saying this item is now out of stock and it automatically removes from the cart.
Thanks in advance
Chantal
-
Hi @snoochy,
Standard behavior for WooCommerce (I’m running v3.7.0) would be to display this error message if an item in the cart has since gone out of stock: “There are some issues with the items in your cart. Please go back to the cart page and resolve these issues before checking out.”
Can you verify whether you have backorders enabled in your product’s Inventory settings?
Thank you,
JoeyHi
I am also on 3.7.0
The products are set to:
Allow Backorders? Do Not Allow
Thanks for your help
In order to troubleshoot this further, please do the following:
- Share a copy of your system status report as found under **WooCommerce > System Status**
- Share a screenshot of the product setup in question
- Share a direct link to the product in question
Thanks!
Hi:
you can try this code:
/** * This snippet allows you automatically remove any out of stock items when the user views their shopping cart. * This would be in cases when users add products to their cart and come back it it later. * You can install this snippet in your functions.php * or * even better in as an mu-plugin in mu-plugins/orb_check_for_out_of_stock_products.php * * Blog post: https://orbisius.com/4308 * @copyright Slavi Marinov | https://orbisius.com * */ function orb_check_for_out_of_stock_products() { if ( WC()->cart->is_empty() ) { return; } $removed_products = []; foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $product_obj = $cart_item['data']; if ( ! $product_obj->is_in_stock() ) { WC()->cart->remove_cart_item( $cart_item_key ); $removed_products[] = $product_obj; } } if (!empty($removed_products)) { wc_clear_notices(); // remove any WC notice about sorry about out of stock products to be removed from cart. foreach ( $removed_products as $idx => $product_obj ) { $product_name = $product_obj->get_title(); $msg = sprintf( __( "The product '%s' was removed from your cart because it is out of stock.", 'woocommerce' ), $product_name); wc_add_notice( $msg, 'error' ); } } } add_action('woocommerce_before_cart', 'orb_check_for_out_of_stock_products');
put it in your child’s theme functions.php
Regards
@osckar thanks for sharing my blog post ??
### WordPress Environment ### WordPress address (URL): https://www.snoochy.co.uk Site address (URL): https://www.snoochy.co.uk WC Version: 3.7.0 REST API Version: ? 1.0.2 Log Directory Writable: ? WP Version: 5.2.2 WP Multisite: – WP Memory Limit: 256 MB WP Debug Mode: – WP Cron: – Language: en_US External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 7.3.8 PHP Post Max Size: 16 MB PHP Time Limit: 30 PHP Max Input Vars: 1000 cURL Version: 7.29.0 NSS/3.19.1 Basic ECC SUHOSIN Installed: – MySQL Version: 5.5.60-MariaDB Max Upload Size: 16 MB Default Timezone is UTC: ? fsockopen/cURL: ? SoapClient: ? DOMDocument: ? GZip: ? Multibyte String: ? Remote Post: ? Remote Get: ? ### Database ### WC Database Version: 3.4.2 WC Database Prefix: wp_ Total Database Size: 934.35MB Database Data Size: 893.27MB Database Index Size: 41.08MB wp_woocommerce_sessions: Data: 548.00MB + Index: 23.63MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.05MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_woocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_order_items: Data: 0.36MB + Index: 0.14MB + Engine MyISAM wp_woocommerce_order_itemmeta: Data: 1.87MB + Index: 1.39MB + Engine MyISAM wp_woocommerce_tax_rates: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_woocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_commentmeta: Data: 0.04MB + Index: 0.03MB + Engine MyISAM wp_comments: Data: 0.86MB + Index: 0.42MB + Engine MyISAM wp_csp3_subscribers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_cspv5_pages: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_cup_cp_profiles: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_duplicator_packages: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_hndtst_saved: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_hugeit_slider_slide: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_hugeit_slider_slider: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_huge_itslider_images_backup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_huge_itslider_params_backup: Data: 0.04MB + Index: 0.01MB + Engine MyISAM wp_huge_itslider_sliders_backup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_links: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_mailpoet_custom_fields: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_feature_flags: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_forms: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mailpoet_log: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mailpoet_mapping_to_external_entities: Data: 0.06MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_newsletters: Data: 0.03MB + Index: 0.03MB + Engine InnoDB wp_mailpoet_newsletter_links: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_mailpoet_newsletter_option: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_newsletter_option_fields: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_newsletter_posts: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_newsletter_segment: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_newsletter_templates: Data: 2.47MB + Index: 0.00MB + Engine InnoDB wp_mailpoet_scheduled_tasks: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_mailpoet_scheduled_task_subscribers: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_segments: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_sending_queues: Data: 0.03MB + Index: 0.03MB + Engine InnoDB wp_mailpoet_settings: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_statistics_clicks: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_mailpoet_statistics_forms: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_statistics_newsletters: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_mailpoet_statistics_opens: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_mailpoet_statistics_unsubscribes: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_mailpoet_statistics_woocommerce_purchases: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_mailpoet_stats_notifications: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_mailpoet_subscribers: Data: 0.19MB + Index: 0.19MB + Engine InnoDB wp_mailpoet_subscriber_custom_field: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_subscriber_ips: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mailpoet_subscriber_segment: Data: 0.09MB + Index: 0.06MB + Engine InnoDB wp_mailpoet_user_flags: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_nextend_smartslider_layouts: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_nextend_smartslider_sliders: Data: 0.01MB + Index: 0.00MB + Engine MyISAM wp_nextend_smartslider_slides: Data: 0.03MB + Index: 0.00MB + Engine MyISAM wp_nextend_smartslider_storage: Data: 0.04MB + Index: 0.01MB + Engine MyISAM wp_ngg_album: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_ngg_gallery: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_ngg_pictures: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_options: Data: 262.77MB + Index: 0.75MB + Engine MyISAM wp_postmeta: Data: 60.95MB + Index: 9.41MB + Engine MyISAM wp_posts: Data: 12.66MB + Index: 2.36MB + Engine MyISAM wp_sm_advanced_search_temp: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_termmeta: Data: 0.06MB + Index: 0.06MB + Engine InnoDB wp_terms: Data: 0.01MB + Index: 0.04MB + Engine MyISAM wp_term_relationships: Data: 0.40MB + Index: 0.82MB + Engine MyISAM wp_term_taxonomy: Data: 0.03MB + Index: 0.02MB + Engine MyISAM wp_usermeta: Data: 0.70MB + Index: 0.31MB + Engine MyISAM wp_users: Data: 0.02MB + Index: 0.04MB + Engine MyISAM wp_w3tc_cdn_pathmap: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_w3tc_cdn_queue: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.06MB + Index: 0.09MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wdslayer: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wdsslide: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wdsslider: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpb2d_processed_dbtables: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wysija_campaign: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_campaign_list: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_custom_field: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_email: Data: 0.25MB + Index: 0.00MB + Engine MyISAM wp_wysija_email_user_stat: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_email_user_url: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_form: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_list: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_queue: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_subscriber_ips: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wysija_url: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_url_mail: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_user: Data: 0.07MB + Index: 0.05MB + Engine MyISAM wp_wysija_user_field: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_user_history: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wysija_user_list: Data: 0.01MB + Index: 0.02MB + Engine MyISAM wp_yith_wcwl: Data: 0.01MB + Index: 0.03MB + Engine MyISAM wp_yith_wcwl_lists: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_yoast_seo_links: Data: 0.05MB + Index: 0.02MB + Engine InnoDB wp_yoast_seo_meta: Data: 0.11MB + Index: 0.00MB + Engine InnoDB ### Security ### Secure connection (HTTPS): ? Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates. Hide errors from visitors: ? ### Active Plugins (30) ### Cookie Control: by Civic UK – 2.2 Cookie Notice: by dFactory – 1.2.46 Custom Related Products for WooCommerce: by Scott Nelle – 1.3 – Not tested with the active version of WooCommerce Disable Emojis (GDPR friendly): by Ryan Hellyer – 1.7.2 Easy Google Fonts: by Titanium Themes – 1.4.4 Elegant Themes Updater: by Elegant Themes – 1.0 Gleam: by Crowd9 – 1.0 MailPoet 3 (New): by MailPoet – 3.35.0 Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 3.1.1 Rel Publisher: by Christopher Davis – 1.0 Remove Query Strings From Static Resources: by Speed Up My Website Your WP Expert – 1.4 Search By SKU - for Woocommerce: by Matthew Lawson – 0.6.1 – Not tested with the active version of WooCommerce SeedProd Coming Soon Page Pro: by SeedProd – 5.12.1 Huge IT Slider: by Huge-IT – 4.0.5 Smart Manager: by StoreApps – 4.2.18 – Not tested with the active version of WooCommerce W3 Total Cache: by Frederick Townes – 0.9.7.5 WooCommerce Builder For Divi: by Abdelfatah Aboelghit | DiviKingdom.Com – 2.1.13 – Not tested with the active version of WooCommerce WooCommerce Admin: by WooCommerce – 0.16.0 – Not tested with the active version of WooCommerce WooCommerce Category Banner: by WP BackOffice – 1.1.2 – Not tested with the active version of WooCommerce WooCommerce Print Invoice & Delivery Note: by Tyche Softwares – 4.4.8 – Not tested with the active version of WooCommerce WooCommerce Empty Cart Button: by Technorigins – 1.1 – Not tested with the active version of WooCommerce Booster for WooCommerce: by Algoritmika Ltd – 4.4.1 – Not tested with the active version of WooCommerce Woocommerce Poor Guys Swiss Knife: by Uli Hake – 2.2.4 – Not tested with the active version of WooCommerce WooCommerce Product Archive Customiser: by jameskoster – 1.0.5 – Not tested with the active version of WooCommerce WooCommerce: by Automattic – 3.7.0 Yoast SEO: by Team Yoast – 11.8 – Not tested with the active version of WooCommerce WP Menu Cart: by Jeremiah Prummer Ewout Fernhout – 2.7.5 – Not tested with the active version of WooCommerce WP Smush Pro: by WPMU DEV – 2.0.6.1 WPMU DEV Dashboard: by WPMU DEV – 4.7.3.2 YITH WooCommerce Cart Messages Premium: by YITH – 1.6.1 ### Inactive Plugins (5) ### Alpine PhotoTile for Pinterest: by the Alpine Press – 1.2.6.6 Coming Soon Page & Maintenance Mode by SeedProd: by SeedProd – 5.0.26 Duplicator: by Snap Creek – 1.2.38 Elegant Themes Support: by Elegant Themes – 1.5 YITH WooCommerce Wishlist: by YITH – 2.2.12 – Not tested with the active version of WooCommerce ### Dropin Plugins (1) ### advanced-cache.php: advanced-cache.php ### Settings ### API Enabled: ? Force SSL: – Currency: GBP (£) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – ### WC Pages ### Shop base: #5 - /shop/ Cart: #6 - /cart/ Checkout: #7 - /checkout/ My account: #8 - /my-account/ Terms and conditions: ? Page not set ### Theme ### Name: Divi Version: 3.26.8 Author URL: https://www.elegantthemes.com Child Theme: ? – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ? ### Templates ### Overrides: – ### Action Scheduler ### Complete: 0 Oldest: – Newest: – Pending: 17 Oldest: 2019-08-07 15:41:54 +0000 Newest: 2019-08-16 14:48:50 +0000 Canceled: 0 Oldest: – Newest: – In-progress: 0 Oldest: – Newest: – Failed: 0 Oldest: – Newest: –
@riaanknoetze
https://www.snoochy.co.uk/wp-content/uploads/2019/08/outof-stock.jpg
this shows my product in my dashboardhttps://www.snoochy.co.uk/wp-content/uploads/2019/08/outof-stock-1.jpg
this shows my product in the cart, it’s out of stock but I did another test run and I as allowed to purchase this item.This happens for all my out of stock items that have been left in a cart.
Thansk again
@snoochy – I see you’re running an updated version of WooCommerce, but your WC Database version is still outdated:
WC Database Version: 3.4.2
Can you try doing a forced update? (WooCommerce > Status > Tools > ‘Update database’)
I’m not sure if that’s the issue here, but it certainly could be.@jricketts4 Thanks. I have set that running now. How long does it normally take?
@jricketts4 Even though I set this in motion an hour ago nothing seems to be happening. I do have a message on my dashboard which ends with this “Note: WP CRON has been disabled on your install which may prevent this update from completing.”
@jricketts4 I tried a forced update as suggested a couple of times but it is just not working.
Hey there!
Does the database still show as being outdated when you go to the System Status Report?
You might need to check with your host if wp cron is disabled and you don’t know why. You can also check out this guide if you want to try enabling it: https://www.siteground.com/kb/disable-enable-wordpress-cron/
Hopefully that helps! Have a great one!
We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.
- The topic ‘Woo Allowing Out of Stock Items to be Purchased’ is closed to new replies.