• WooCommerce Plugins
  • Support
  • Blog
  • About
  • FAQ
Menu
  • WooCommerce Plugins
  • Support
  • Blog
  • About
  • FAQ
$0.00 0 Cart

Hooks & Filters

WooCommerce Stock Sync Pro has hooks and filters which can be used to modify it’s behavior. For example, you can do the following:

  • Prevent syncing of a certain product
  • Add additional meta data when syncing occurs

You can try the examples below with Code Snippets or add them to your theme’s functions.php file.

woocommerce_rest_pre_insert_product_object

The filter is used to modify product data before it’s saved on the receiving website.

Example: save additional meta data

<?php
add_filter( 'woocommerce_rest_pre_insert_product_object', function( $product, $request, $creating ) {
  update_post_meta( $product->get_id(), '_is_synced', true );

  return $product;
}, 10, 3 );

woo_stock_sync_should_sync

The filter is used to determine whether or not the product should be synced.

Example: only sync if the product has the category with the slug acme

<?php
add_filter( 'woo_stock_sync_should_sync', function( $should_sync, $product ) {
	$slug = 'acme';

	// Get product categories
	$cat_slugs = wp_get_post_terms( $product->get_id(), 'product_cat', [
		'hide_empty' => false,
		'fields' => 'slugs',
	] );

	// Stop syncing if the product doesn't have the category with the slug "acme"
	if ( ! in_array( $slug, $cat_slugs, true ) ) {
		return false;
	}

	return $should_sync;
}, 10, 2 );

Need anything else?

If the hook you were looking for was not listed, please let us know and our developers are happy to check if it’s possible to add.

Table of Contents

  • woocommerce_rest_pre_insert_product_object
  • woo_stock_sync_should_sync
  • Need anything else?
« Back to docs
« Back to plugin

WP Trio extensions make managing WooCommerce stores easier. Save time and get more sales with our premium plugins for WooCommerce. Should you have any questions, our support is happy to help!

WP Trio

  • Support
  • Blog
  • About
  • FAQ
  • Support
  • Blog
  • About
  • FAQ

Plugins

  • Plugins
  • Docs
  • Plugins
  • Docs