Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Created July 18, 2017 08:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SiR-DanieL/eb54200a81b1821b0bf64f42d07aee7a to your computer and use it in GitHub Desktop.
Save SiR-DanieL/eb54200a81b1821b0bf64f42d07aee7a to your computer and use it in GitHub Desktop.
functions.php
/**
* Checks if the customer is a reseller and
* returns false if they are trying to purchase from a specific category.
*
* @param bool $is_purchasable If the product is purchasable or not.
* @return bool
*/
function limit_purchases_by_role( $is_purchasable, $product ) {
$categories = $product->get_category_ids();
if ( current_user_can( 'resell_product' ) && in_array( 17, $categories ) ) {
return false;
}
return $is_purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'limit_purchases_by_role', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment