Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Last active December 10, 2020 19:43
Show Gist options
  • Save hedqvist/cfba5d9a5ee7af74746d3602d0bdb183 to your computer and use it in GitHub Desktop.
Save hedqvist/cfba5d9a5ee7af74746d3602d0bdb183 to your computer and use it in GitHub Desktop.
Order Reviews - Skip certain product
<?php
/**
* @snippet WooCommerce - Order Reviews - Skip certain products
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.5.1
*/
function redlight_order_reviews_skip_certain_product( $skip, $product, $order, $line_item ) {
$line_item_data = $line_item->get_data();
//$line_item_data['product_id'] - This now contains our product since variables doesnt support terms
//How to skip on product names
if($product->get_title() == 'Polo'){
$skip = true;
}
//How to skip on certain categories, ie 'Accessories'
if ( has_term( ['Accessories'], 'product_cat', $line_item_data['product_id'] ) ) {
$skip = true;
}
//How to skip on certain tags, ie 'crafted'
if ( has_term( ['crafted'], 'product_tag', $line_item_data['product_id'] ) ) {
$skip = true;
}
return $skip;
}
add_filter('wcor_do_not_ask_for_review', 'redlight_order_reviews_skip_certain_product', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment