Woocommerce Google Product Feed – exclude / hide all products by default

If you love using WooCommerce as an ecommerce tool like me, at some point you will probably look into using the Google Product Feed extension.

This extension creates a feed for Google Merchant Center to pull from so your products show up in the Google Products section of search results. It’s a great extension and you can check it out at: http://www.woothemes.com/products/google-product-feed/

That said, I ran into an issue with this extension. By default the extension adds all products to the feed. There is a section on each WooCommerce product page that gives you the option to exclude the product feed.

This is a nice feature, but if you are like me and have a client that has 250 products and only wants to include 3 of those products in the feed what do you do?

[bctt tweet=”I don’t want go through each product and click the exclude button. That would take forever!!”]

I think a nice improvement to this extension would be to include a feature to exclude all products except the ones that you choose. Hopefully at some point Lee Willis the extension developer will add this.

Okay, so it’s kind of an ugly hack but this is how I resolved the issue for myself:

In your WordPress plugins directory open file: /plugins/woocommerce-product-feeds/woocommerce-gpf-frontend.php

On line 189 change:
if ( isset ( $tmp_product_data['exclude_product'] ) ) continue;

to:

if ( !isset ( $tmp_product_data['exclude_product'] ) ) continue;
Now all products will be excluded automatically. If you want to include a product in the feed you have to go to the products page and check the “Hide this product from the feed”. It’s a little backwards, but at this point you could stop and it would work for you.

If you want to fix it so it makes sense from a users point of view you can open: /plugins/woocommerce-product-feeds/woocommerce-gpf-admin.php

On line 301 change:
echo '<label for="_woocommerce_gpf_data[exclude_product]">'.__(" Hide this product from the feed", 'woocommerce_gpf');

to:

echo '<label for="_woocommerce_gpf_data[exclude_product]">'.__("Include this product in the feed", 'woocommerce_gpf');

The last thing you will have to do is remove the jquery slide reveal effect.

On line 334 to 344 delete:

Delete all of the code. It will be the code inside the javascript tags:
<script type="text/javascript">
jQuery('#woocommerce_gpf_excluded').change(function() {
if (jQuery("#woocommerce_gpf_excluded").is(':checked')) {
jQuery('#woocommerce_gpf_options').slideUp('400','swing');
} else {
jQuery('#woocommerce_gpf_options').slideDown('400','swing');
}
}
);
jQuery('#woocommerce_gpf_excluded').change();
</script>

That’s it!! You have now changed the default to exclude all products. All you have to do now is go to the products pages you want to include and check the “Include this product in the feed”.

Remember that you are hacking the plugin/extension, so if you update it you will have to resolve this issue again.

I hope this helps.

Shawn Hayes

Team Share Web Design

Featured Posts

Top

Almost there! Please complete this form and click the button below to gain instant access.

Get The Full Guide & Example Files:

It makes setting up your AJAX code super simple!