Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Last active November 22, 2021 02:34
Show Gist options
  • Save NickGreen/ac11782aefdfbcb58cf48e87c9aace33 to your computer and use it in GitHub Desktop.
Save NickGreen/ac11782aefdfbcb58cf48e87c9aace33 to your computer and use it in GitHub Desktop.
WooCommerce Subscriptions Gifting - turn off for specific products or tags
<?php
add_filter( 'wcsg_is_giftable_product', 'disable_gifting_by_product', 12, 2 );
function disable_gifting_by_product( $is_sub, $product ) {
$not_giftable_products = array( 906, 964 ); // add or remove product IDs here
if ( in_array( $product->get_id(), $not_giftable_products ) ) {
return false;
} else {
return $is_sub;
}
}
<?php
add_filter( 'wcsg_is_giftable_product', 'disable_gifting_by_tag', 12, 2 );
function disable_gifting_by_tag( $is_sub, $product ) {
if ( has_term( 'abc', 'product_tag', $product ) ) {
return false;
} else {
return $is_sub;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment