• Resolved ninjaneen

    (@ninjaneen)


    Hello, I help to manage a website that sells fair trade products. They also have ‘donation’ products i.e. not really products at all. They don’t have a google category so I’d like to exclude them from being synched to Pinterest. How do I do that? Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Christian

    (@christian1983)

    Hey @ninjaneen,

    Those donation products have their own “Product Type” like “Donation” or something else? or they are “Simple products” or “Variable products”?

    Best,
    Christian

    Thread Starter ninjaneen

    (@ninjaneen)

    Hi Christian, thanks for your reply. They’re just simple products right now. If it would help, I could create a custom product type.

    Cheryl

    (@tricheryltops)

    Following this topic, too, as I was about to ask the same question. There should be a way to exclude some products or product categories.

    Plugin Support Christian

    (@christian1983)

    Hey @ninjaneen

    You can test by creating a product type and then using this snippet:

    An example of Composite products:

    function remove_composite_products_from_pinterest_feed( $excluded_products ) {
    	array_push( $excluded_products, 'composite' );
    	return $excluded_products;
    }
    
    add_filter( 'pinterest_for_woocommerce_excluded_product_types', 'remove_composite_products_from_pinterest_feed' );

    Hey @tricheryltops,

    there are no filters to use for excluding specific products or categories right now. You can add your vote on this feature request so they can prioritize it.

    Let me know if that helps.

    Best,
    Christian

    Plugin Support Christian

    (@christian1983)

    Hey there,

    Since we haven’t heard back from the OP in a while, I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Best,
    Christian

    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.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How can I exclude some products from synching?’ is closed to new replies.