WP 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.
Multisite – Hook after slave product is updated.
Multisite – Hook after slave product is updated.
This hook can be used to sync products across network.
Filter, get the store IDs or identifiers.
Filter, disable bulk editor for multisite.
Filters – disable variations price sync.
Filter – Plugin user capability.
Filter, Imported order metadata.
Filter – Disable import order customer.


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 );

(Multisite) 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);

(Single Site) Hook after slave product is updated.

This hook is fired after slave product data and its associated metadata are saved in the database. The hook contains 3 arguments, child product id, parent product id, and an array with the main product’s data.

 

/**
function do_something_after_slave_date_saved_in_db( $child_p_id, $parent_p_id, $parent_data ) {
//your code here
}
add_action('WOO_MSTORE_SYNC/sync_child/complete', 'do_something_after_slave_date_saved_in_db', 10, 3);

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 );

Filter – 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() );

Filter – disable bulk editor for multisite.

For websites with large amounts of products, the bulk editor on all products page can be constly on performance. This filter allows you to turn off the bulk editor while keeping the single product edit option.

 

// Disable quick editor on all products page from a custom plugin
add_action('plugins_loaded', function(){
   add_filter('woonet_add_quick_edit', function(){
       return false;
   });
});
// Disable quick editor on all products page from a theme's functions.php
add_filter('woonet_add_quick_edit', function(){
   return false;
});

Filters – disable variations price sync.

Use the filters below to disable price sync for variations.

 

add_filter('WOO_MSTORE_SYNC/sync_child/sync_variation_price', 'sync_variation_price');
function sync_variation_price(){
   return false;
}

add_filter('WOO_MSTORE_SYNC/sync_child/sync_variation_sale_price', 'sync_variation_sale_price');
function sync_variation_sale_price(){
   return false;
}

add_filter('WOO_MSTORE_SYNC/sync_child/sync_variation_regular_price', 'sync_variation_regular_price');
function sync_variation_regular_price(){
   return false;
}

Filter – Plugin user capability

Controls if user has publish capability for the plugin.

add_filter('WOO_MSTORE/permission/user_can_publish', 'user_can_publish', 10, 2 );
function user_can_publish( $can_publish, $_options ){
    // $user = get_current_user();
    // do stuff here
    // return true;
    // return false;
}

Filter – Imported order metadata

Modify what order meta is synced back from the imported order to the original order.

add_filter('woonet_imported_order_metadata', 'imported_order_metadata' );
function imported_order_metadata( $order_meta ){
    // do stuff here with $order_meta
    // return $order_meta;
}

Filter – Disable import order customer

Controls if user has publish capability for the plugin.

function wc_multistore_import_order_customer(){
    return false;
}
add_filter('wc_multistore_import_order_customer', 'wc_multistore_import_order_customer');