• Skip to primary navigation
  • Skip to main content

WP Data Sync

The only data sync API for WordPress websites.

  • Products
  • Blog
    • Code Examples
  • Documentation
    • Getting Started
    • Actions
    • Filters
    • FAQ
    • Specifications
    • Change Log
  • Contact
  • Support
  • Checkout
    • Cart
  • Account
WP Data Sync Icon

Filter WooCommerce Backorder Status Based on Stock Quantity

WP Data Sync Code Example

If you are syncing inventory from your POS to your WooCommerce store you understand the importance of the correct backorder status. WP Data Sync plugin it packed with action hooks and filters to make this an easy customization.

In the code example below, we are setting the backorder status based on the stock quantity provided by your data source using the wp_data_sync_{$meta_key}_value filter.

Add the code snippet below to your themes function.php file.

Code Example

/**
 * Filter WooCommerce Backorder Status Based on Stock Qty
 *
 * Set the backorder staus when the stock qty is less than 1.
 *
 * @package WPDataSync
 */

// WooCommerce _stock value filter
add_filter( 'wp_data_sync__stock_value', 'wp_data_sync_backorder_status_by_stock_qty', 10, 3 );

/**
 * WP Data Sync Set Backorder Status by Stock Qty.
 *
 * @param string                   $price
 * @param int                      $product_id
 * @param WP_DataSync\App\DataSync $data_sync
 *
 * @return mixed
 */

function wp_data_sync_backorder_status_by_stock_qty( $qty, $product_id, $data_sync ) {

	if ( empty( $qty ) ) {
		return $qty;
	}

	if ( ! function_exists( 'wc_get_product' ) ) {
		return $qty;
	}

	$product = wc_get_product( $product_id );

	// Default status
	$status = 'instock';

	if ( intval( $qty ) < 1 ) {
		$status = 'onbackorder';
	}

	$product->set_stock_status( $status );
	$product->save();

	return $qty;
}

Get Started

  • WP Data Sync Starter Plan Graphic

    Starter Plan

    Rated 5.00 out of 5
    $39.00 / month
    • 10,000 Requests/Month
    • Unlimited Data Sources
    • Unlimited Websites
    • Unlimited Users
    More Info
  • WP Data Sync Basic Plan Graphic

    Basic Plan

    Rated 5.00 out of 5
    $69.00 / month
    • 40,000 Requests/Month
    • Unlimited Data Sources
    • Unlimited Websites
    • Unlimited Users
    More Info
  • WP Data Sync Professional Plan Graphic

    Professional Plan

    Rated 5.00 out of 5
    $129.00 / month
    • 150,000 Requests/Month
    • Unlimited Data Sources
    • Unlimited Websites
    • Unlimited Users
    More Info
  • WP Data Sync Data Source Mapping Graphic

    Data Source Mapping

    Rated 5.00 out of 5
    $149.00 – $999.00
    Let us do the mapping for you!!
    We will map all your data sources for you, so you can move on to other projects that demand your time. One of our experts will map up to 50 fields for you in each data source.
    More Info This product has multiple variants. The options may be chosen on the product page

WP Dat Sync icon
Copyright © 2025 · WP Data Sync · Located in Scottsdale AZ

  • Developers
  • Data Access Request
  • Terms of Service
  • Privacy Policy
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT