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?

I don’t want go through each product and click the exclude button. That would take forever!! Click To Tweet

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

10 Comments

  • Alex Timmer

    Good fix, though too bad it’s a core edit involved, something I’d rather not do. But this thread did get me on the right track to go figure out if I can set the “exclude this product from feed” option for all products via the database, and then changing it for the few products we do want to show.
    Quite a missed opportunity that there isn’t a global option for this, and that there IS some CSV-export functionality, but NOT for this specific exclude option..

    • Shawn Hayes

      Hi Alex,
      I totally agree!! I hate hacking plugins or anything core. I really wish the author would add this feature to the plugin. I am glad this helped you get on the right track though. Let me know if you have any questions about anything.
      Shawn

  • Rob

    Great Post – I have just downloaded the plugin and as like others can’t believe there is no default option to hide all products to start with. make sense to me.
    Anyway I was able to find the code on your first part (p189) even though it is further down and slightly different. The last two points that code is not where you say and anything similar to it is just too different to yours for me to risk changing. There is no reference to Javascript in the gpf-admin php file now.
    I understand there has probably been a lot of changes since you created this post and just curious if you have an updated version at all please?

    • Shawn Hayes

      Unfortunately no, I haven’t worked with the updated version. This was for version 3.5 back in November, 2014.
      Sorry about that.

  • Jitske

    I found your hack, but it seems that this file (/plugins/woocommerce-product-feeds/woocommerce-gpf-frontend.php) has changed. So I can’t use your solution.
    Can you help me with the latest version (6.8.0)?

    I have about 2500 products and I want only 10-20 in the Google product feed, so check the box for hiding the product would be quite a job;-)

    • Shawn Hayes

      I am really sorry you are in a bad spot. As mentioned in the comment above, I haven’t worked with the updated version. This was for version 3.5 back in November, 2014. If I do work with the new version I will definitely update the tutorial.

  • Daniel Hobson

    An alternative approach if you don’t want to hack plugin files is to run a query like the following to bulk set all the products to be excluded. Be wary though as this removes any associated feed data from all products, probably best to use immediately after plugin install.

    DELETE FROM wp_postmeta
    WHERE meta_key = ‘_woocommerce_gpf_data’;
    INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
    SELECT ID, ‘_woocommerce_gpf_data’, ‘a:1:{s:15:”exclude_product”;s:2:”on”;}’ FROM wp_posts WHERE post_type = ‘product’;

    • Shawn Hayes

      Thank you for the tip Daniel. I am not super great at SQL queries but this looks pretty simple. I will have to give it go when I have a chance. Thanks again!

  • Lee Burrett

    Have tried the SQL query that Daniel has suggested – whilst everything looks ok in the database – doesn’t seem to make any change to the front end of the product – Hide from Feed checkbox is still unticked on all products. Have tried manually ticking against one product and the resulting meta_value string is exactly the same as specified above but can’t see any change in the dashboard for each product I’ve set via SQL…

    • Shawn Hayes

      Hi Lee,

      I am sorry Daniels suggestion didn’t work for you. I haven’t worked with this plugin in a few years, so I am probably not much help to you. My only suggestion is maybe try modifying my code above to work with the new version of the plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *

Featured Posts

"Like" Us On Facebook

Facebook By Weblizar Powered By Weblizar