I came here because I was looking for a solution to exactly this issue – excluding certain products by category.
It turns out there absolutely is a way to do it: by modifying the XML that gets generated and sent to Pinterest.
When generating the XML product feed, the plugin uses a filter for the XML of each product: pinterest_for_woocommerce_feed_item_xml
So I hooked into this filter and created an exclusion for any parent products that were in the category I wanted to exclude (since my site only has variations).
function vnmWooExtend_pinterestFilterItem($xml, $product) {
// I'm only using variation products, so I check if the current product has a parent, as its only the parent that actually belongs to a given category
$parentProduct = wc_get_product($product->get_parent_id());
// Make sure it exists & isn't an error
if ($parentProduct && !is_wp_error($parentProduct)) {
// Term ID 123 = The category I want to exclude: so if a product is in category 123, then return nothing to the feed
if (has_term(123, 'product_cat', $product->get_parent_id())) {
return '';
}
}
return $xml;
}
add_filter('pinterest_for_woocommerce_feed_item_xml', 'vnmWooExtend_pinterestFilterItem', 10, 2);
To do the same for simple products, simply remove the check for get_parent_id()
and change the conditional to if (has_term(123, 'product_cat', $product->get_id()))
Do note that the feed is only generated once a day (you can see when by looking at the action scheduler), so you may have to wait for it to be generated, but after that, you’re good to go.
-
This reply was modified 1 year, 11 months ago by indextwo.