Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
admincolumns19

Product Variations & WC Marketplace (WCMp)

Hello people. Hope you’re doing well.

Currently:
We are using the WCMp plugin and by default vendors should only have access to their own products in wp-admin. When I access the “Product Variations” page logged in as a vendor, absolutely all products are being displayed, even those from other suppliers. This way, each vendor can edit the variations of other vendors.

Expected behavior:
The product variations query must be compatible with the standard query (posts query). If this is not possible, product variations should only show products from the logged in user (post_author).

Ps.: I’ve deactivated all plugins, keeping only AC, Woocommerce and WCMp.

Perhaps it may be a WCMp problem. Could you help me to investigate it, please?

2 years, 8 months ago
admincolumns19

Hello.

Can you help me, please?

2 years, 7 months ago
Tobias Schutter
Developer

Hi, the product variation list table extends the WooCommerce list table. It uses the WordPress main query $wp_query. You can simply hook into it, just like with any other global $wp_query.

This should do the trick:

add_filter( 'posts_where', function ( $where, WP_Query $query ) {
	global $wpdb;

	if ( is_admin() && $query->is_main_query() && 'product_variation' === $query->get( 'post_type' ) ) {
		$where .= $wpdb->prepare( ' AND post_author = %d', get_current_user_id() );
	}

	return $where;
}, 10, 2 );
2 years, 7 months ago
admincolumns19

Thank you Tobias!

It worked.

2 years, 7 months ago

You must be logged in to reply to this topic.