WooCommerce Marketplace Suggestions

woocommerce_show_marketplace_suggestions

WooCommerce has a feature called “Marketplace suggestions” that is enabled by default. This feature will, for example, add a new tab with suggested add-ons when you edit a product.

Example of WooCommerce Marketplace suggestions

While this feature can be useful for those new to WooCommerce, you may prefer to turn it off. You can do so by following the “Manage suggestions” link or by going to WooCommerce > Settings > Advanced > Marketplace suggestions.

How to change marketplace suggestions (woocommerce_show_marketplace_suggestions) manually
How to change marketplace suggestions (woocommerce_show_marketplace_suggestions) manually

If you prefer to make the change using code, you can use the following snippet. Simply run it once or add it to your plugin or theme file.

// Update an option in WooCommerce
function update_woocommerce_option( ) {
    //Possible values: yes|no
	update_option( 'woocommerce_show_marketplace_suggestions', 'no' );
}
add_action( 'init', 'update_woocommerce_option' );

woocommerce_marketplace_suggestions


Marketplace suggestions are stored in the wp_options table under the option_name “woocommerce_marketplace_suggestions” and are automatically refreshed once per week. The data is retrieved from a remote endpoint using the following code:

	/**
	 * Pull suggestion data from options. This is retrieved from a remote endpoint.
	 *
	 * @return array of json API data
	 */
	public static function get_suggestions_api_data() {
		$data = get_option( 'woocommerce_marketplace_suggestions', array() );

		// If the options have never been updated, or were updated over a week ago, queue update.
		if ( empty( $data['updated'] ) || ( time() - WEEK_IN_SECONDS ) > $data['updated'] ) {
			$next = WC()->queue()->get_next( 'woocommerce_update_marketplace_suggestions' );
			if ( ! $next ) {
				WC()->queue()->cancel_all( 'woocommerce_update_marketplace_suggestions' );
				WC()->queue()->schedule_single( time(), 'woocommerce_update_marketplace_suggestions' );
			}
		}

		return ! empty( $data['suggestions'] ) ? $data['suggestions'] : array();
	}

Conclusion

In summary, WooCommerce has a feature called “Marketplace suggestions” that is enabled by default, which adds suggested add-ons when editing a product. If you prefer to turn this feature off, you can do so by following the “Manage suggestions” link or by going to WooCommerce > Settings > Advanced > Marketplace suggestions or by using the provided code snippet. The suggestions data is stored in the wp_options table and is automatically refreshed once per week.

Leave a Comment