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

Hooks & Filters

Plugin: WooCommerce Product Sync Pro

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
30 DAY MONEY BACK GUARANTEE
+6000 HAPPY CUSTOMERS
SUPPORT FROM THE DEVELOPER

WP Trio / BitBot Oy
Flätbackantie 1, 04150 Sipoo
FINLAND
VAT ID: FI28269925

WP Trio

  • Support
  • Blog
  • About
  • FAQ
  • My account
  • Support
  • Blog
  • About
  • FAQ
  • My account

Plugins

  • Plugins
  • Docs
  • Plugins
  • Docs