Created
April 19, 2016 20:57
-
-
Save bekarice/35ac6cc853a17064131fa144125e9deb to your computer and use it in GitHub Desktop.
Revisions
-
bekarice created this gist
Apr 19, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ <?php // get plan restriction rules if we have an ID, could be used in member area for example $plan = wc_memberships_get_membership_plan( $plan_id ); $product_rules = $plan->get_product_restriction_rules(); foreach ( $product_rules as $rule ) { // get the ids of restricted items from the rules $restricted_items = $rule->get_object_ids(); foreach ( $restricted_items as $item_id ) { // cast the item ID as an int $item_id = (int) $item_id; // check if the restricted objects are terms or not $term = get_term( $item_id, 'product_cat' ); // if we don't have a term, catch the exception and carry on if ( is_wp_error( $term ) ) { continue; } else { // if we do have a term, do some stuff // do whatever you want with $term here -- ie loop categories and show a list, whatever } } }