Plugin API, Hooks, Filters, Actions

This section is constantly updated as new features, functions, filters and actions are included in the plugin core. If you have a question which this page does not cover please contact us.

The information on this page is currently meant for developers and advanced users only, not regular users. You do not need to use this information to use our plugin.

This hook can be used to update products across network.
This hook can be used to add additional options within main plugin settings area.
This hook can be used to save customized options inserted through woo_mstore/options/options_output within plugin main settings page.
Metadata keys to exclude from master product.
Metadata to update in master product.
Is slave product inherits master product updates.
Slave product data to update.
Metadata keys to exclude from slave product.
Whether to update slave product.
Metadata to update in slave product.
Hook after slave product is updated.
This hook can be used to sync products across network.
This filter can be used to get the store IDs or identifiers.  


This hook can be used to update products across network.

When you update a product manually, make sure you fire this action hook so that your changes are replicated across the network.

 

/**
** Fire the action hook with product id
**/
do_action( ‘WOO_MSTORE_admin_product/process_product’, $product_id );

This hook can be used to add additional options within main plugin settings area.

add_action('woo_mstore/options/options_output', 'my_woo_mstore_options_html');
    function my_woo_mstore_options_html()
        {
             
            ?>
            <select name="my_custom_option">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
            </select>
            <?php
                
        }

This hook can be used to save customized options inserted through woo_mstore/options/options_output within plugin main settings page.

add_filter('woo_mstore/options/options_save', 'my_woo_mstore_options_save');
function my_woo_mstore_options_save($options)
{

//add our data
$options['my_option'] = isset($_POST['my_option']) ? $_POST['my_option'] : '';

return $options;

}

Metadata keys to exclude from master product.

/**
 * @param array         $meta_keys          Metadata keys to exclude from master product
 * @param WC_Product    $master_product     Master product
 *
 * @return array
 */
function exclude_meta_from_master_product( $meta_keys, $master_product ) {
	if ( 123 == $master_product->get_id() ) {
		$meta_keys[] = '_some_product_meta_key';
	}

	return $meta_keys;
}
add_filter( 'WOO_MSTORE_admin_product/master_product_meta_to_exclude', 'exclude_meta_from_master_product', 10, 2 );

Metadata to update in master product.

/**
 * @param array         $meta_data          Metadata to update in master product
 * @param WC_Product    $master_product     Master product
 *
 * @return array
 */
function update_master_product_meta( $meta_data, $master_product ) {
	if ( 123 == $master_product->get_id() ) {
		$meta_data['_some_product_meta_key'] = '_some_product_meta_value';
	}

	return $meta_data;
}
add_filter( 'WOO_MSTORE_admin_product/master_product_meta_to_update', 'update_master_product_meta', 10, 2 );


Is slave product inherits master product updates.

/**
 * @param bool          $result         Is slave product inherits master product updates
 * @param WC_Product    $slave_product  Slave product
 *
 * @return bool
 */
function is_product_inherit_updates( $result, $slave_product ) {
	if ( 123 == $slave_product->get_id() ) {
		$result = false;
	}

	return $result;
}
add_filter( 'WOO_MSTORE_admin_product/is_product_inherit_updates', 'is_product_inherit_updates', 10, 2 );


Slave product data to update.

/**
 * @param array $products_data_diff             Slave product data to update
 * @param array $data array(
 *      WC_Product  master_product              Master product
 *      array       master_product_attributes   Master product attributes
 *      integer     master_product_blog_id      Master product blog ID
 *      array       master_product_terms        Master product terms
 *      array       master_product_upload_dir   Master product uploads directory information ( see wp_get_upload_dir() )
 *      array       options                     Plugin options
 *      WC_Product  slave_product               Slave product
 * )

 * @return array
 */
function update_slave_product_data( $products_data_diff, $data ) {
	if (
		empty( $data['options']['child_inherit_changes_fields_control__product_cat'][ get_current_blog_id() ] )
		&&
		$data['master_product']->get_ids()
	) {
		unset( $products_data_diff['category_ids'] );
	} else {
		$products_data_diff['category_ids'] = array( 1, 2, 3 );
	}

	return $products_data_diff;
}
add_filter( 'WOO_MSTORE_admin_product/master_slave_products_data_diff', 'update_slave_product_data', 10, 2 );


Metadata keys to exclude from slave product.

/**
 * @param array $meta_keys          Metadata keys to exclude from slave product
 * @param array $data array(
 *      WC_Product  master_product              Master product
 *      array       master_product_attributes   Master product attributes
 *      integer     master_product_blog_id      Master product blog ID
 *      array       master_product_terms        Master product terms
 *      array       master_product_upload_dir   Master product uploads directory information ( see wp_get_upload_dir() )
 *      array       options                     Plugin options
 *      WC_Product  slave_product               Slave product
 * )

 * @return array
 */
function exclude_slave_product_meta( $meta_keys, $data ) {
	if ( $data['slave_product']->get_meta('_some_product_meta_key') ) {
		$meta_keys[] = '_some_product_meta_key';
	}

	return $meta_keys;
}
add_filter( 'WOO_MSTORE_admin_product/slave_product_meta_to_exclude', 'exclude_slave_product_meta', 10, 2 );


Whether to update slave product.

/**
 * @param bool          $result         Whether to update slave product
 * @param WC_Product    $slave_product  Slave product
 *
 * @return bool
 */
function is_product_stock_synchronize( $result, $slave_product ) {
	if ( 123 == $slave_product->get_id() ) {
		$result = false;
	}

	return $result;
}
add_filter( 'WOO_MSTORE_admin_product/is_product_stock_synchronize', 'is_product_stock_synchronize', 10, 2 );


Metadata to update in slave product.

/**
 * @param array $meta_data          Metadata to update in slave product
 * @param array $data array(
 *      WC_Product  master_product              Master product
 *      array       master_product_attributes   Master product attributes
 *      integer     master_product_blog_id      Master product blog ID
 *      array       master_product_terms        Master product terms
 *      array       master_product_upload_dir   Master product uploads directory information ( see wp_get_upload_dir() )
 *      array       options                     Plugin options
 *      WC_Product  slave_product               Slave product
 * )
 *
 * @return array
 */
function update_slave_product_meta( $meta_data, $data ) {
	if ( $data['slave_product']->get_meta('_some_product_meta_key') != '_some_product_meta_value' ) {
		$meta_data['_some_product_meta_key'] = '_some_product_meta_value';
	}

	return $meta_data;
}
add_filter( 'WOO_MSTORE_admin_product/slave_product_meta_to_update', 'update_slave_product_meta', 10, 2 );

Hook after slave product is updated.

This hook is fired after slave product data and its associated metadata are saved in the database. The hooks receives one parameter as an array with data containing master product instance, slave product instance and configuration options.

 

/**
function do_something_after_slave_date_saved_in_db($data) {
//your code here
}
add_action('WOO_MSTORE_admin_product/slave_product_updated', ‘do_something_after_slave_date_saved_in_db’, 10, 1);

This hook can be used to sync products across network.

To sync a product across the network programmatically, use the combination of hooks as shown below.

 

/**
 *
 * Mark a new product to sync with a store and then call process_product hook to run the sync.
 *
 * See 'WOO_MSTORE/get_store_ids' filter if you need to get store IDs.
 *
 * @param integer $product_id WooCommerce product ID
 * @param array   $stores Store IDs
 * @param string  $child_inherit Set child inherit product change option. Valid value is either yes or no.
 * @param string  $stock_sync Set stock sync option. Valid value is either yes or no.
 */

 do_action("WOO_MSTORE_admin_product/set_sync_options", $product_id, $stores, 'yes|no', 'yes|no');

/**
 * After sync option is set, now fire the sync hook.
 *
 * @param integer $product_id WooCommerce product ID
**/
do_action( ‘WOO_MSTORE_admin_product/process_product’, $product_id );

This filter can be used to get the store IDs or identifiers.

In case of multisite, returns site IDs. But for regular WordPress version returns site identifiers and URLs.

 

$store_ids = apply_filters( 'WOO_MSTORE/get_store_ids', array() );