Created
July 18, 2017 08:30
-
-
Save SirDarcanos/eb54200a81b1821b0bf64f42d07aee7a to your computer and use it in GitHub Desktop.
functions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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