0

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 that 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.

If you are using a version of our plugin that is older than v5.0.0 , then you can check our legacy docs for this here.

Metadata keys to exclude from the parent 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() ) {
		unset($meta_keys['_some_product_meta_key']);
	}

	return $meta_keys;
}
add_filter( 'wc_multistore_whitelisted_meta_keys', 'exclude_meta_from_master_product', 10, 2 );

Add metadata to 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'] = '';
	}

	return $meta_data;
}
add_filter( 'wc_multistore_whitelisted_meta_keys', 'update_master_product_meta', 10, 2 );

Slave product data to update

function update_child_product_data( $data ) {
	if( is_array( $data ) ){
		//unset($data['categories']);
	}

	return $data;
}
add_filter( 'wc_multistore_child_product_data', 'update_child_product_data', 10, 1 );

Metadata to update in slave product

function update_slave_product_meta( $data ) {
	if( ! is_array( $data ) ){
		return $data;
	}

	if ( ! empty($data['meta']['_some_product_meta_key']) && $data['meta']['_some_product_meta_key'] != '_some_product_meta_value' ) {
		$data['meta']['_some_product_meta_key'] = '_some_product_meta_value';
	}

	return $data;
}
add_filter( 'wc_multistore_child_product_data', 'update_slave_product_meta', 10, 1 );

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 2 arguments, wc_product and an array with the main product’s data.

function do_something_after_slave_date_saved_in_db( $wc_product, $data ) {
	//your code here
}
add_action('wc_multistore_child_product_saved', 'do_something_after_slave_date_saved_in_db', 10, 2);

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 true;
}

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

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 $can_publish;
}

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

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

Filter – Add custom fields to export order columns

Modify the data exported by order export

/**
 * @param array $header
 *
 * @return array
 */
function custom_wc_multistore_export_orders_header($header){
	// This filter needs to run on master site only
	$header['custom_field'] = 'custom_field'; // add custom field as the last column in the header
	return $header;
}
add_filter('wc_multistore_export_orders_header', 'wc_multistore_custom_export_orders_header');

/**
 * @param array $row
 * @param WC_Order $order
 * 
 * @return array
 */
function custom_wc_multistore_export_orders_order_row( $row, $order ){
	// This filter needs to run on all sites, master/child 
        // Should be used if the settings of the export order is set to row per order
	$row[] = $order->get_meta('custom_field'); // add custom field as the last column in the row
	return $row;
}
add_filter('wc_multistore_export_orders_order_row', 'custom_wc_multistore_export_orders_order_row', 10, 2 );

/**
 * @param array $row
 * @param WC_Order $order
 * @param WC_Order_Item $order_item
 *
 * @return array
 */
function custom_wc_multistore_export_orders_product_row( $row, $order, $order_item ){
	// This filter needs to run on all sites, master/child
        // Should be used if the settings of the export order is set to row per product
	$row[] = $order->get_meta('custom_field'); // add custom field as the last column in the row
	return $row;
}
add_filter('wc_multistore_export_orders_product_row', 'custom_wc_multistore_export_orders_product_row', 10, 3 );