lightspeeddevelopment /
lsx-health-plan
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * LSX Health Plan WooCommerce functions. |
||
| 4 | * |
||
| 5 | * @package lsx-health-plan |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace lsx_health_plan\functions\woocommerce; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Returns true or false if the plan has products. |
||
| 12 | * |
||
| 13 | * @return boolean |
||
| 14 | */ |
||
| 15 | function plan_has_products() { |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 16 | $lsx_hp = lsx_health_plan(); |
||
| 17 | $has_products = false; |
||
| 18 | if ( ! empty( $lsx_hp->integrations->woocommerce->plans->product_ids ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 19 | $has_products = true; |
||
| 20 | } |
||
|
0 ignored issues
–
show
|
|||
| 21 | return $has_products; |
||
| 22 | } |
||
|
0 ignored issues
–
show
|
|||
| 23 | |||
| 24 | /** |
||
| 25 | * Returns product ids attached in an array. |
||
| 26 | * |
||
| 27 | * @return array |
||
| 28 | */ |
||
| 29 | function get_plan_products() { |
||
| 30 | $lsx_hp = lsx_health_plan(); |
||
| 31 | $has_products = array(); |
||
| 32 | if ( ! empty( $lsx_hp->integrations->woocommerce->plans->product_ids ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 33 | $has_products = $lsx_hp->integrations->woocommerce->plans->product_ids; |
||
| 34 | } |
||
|
0 ignored issues
–
show
|
|||
| 35 | return $has_products; |
||
| 36 | } |
||
|
0 ignored issues
–
show
|
|||
| 37 | |||
| 38 | /** |
||
| 39 | * Returns the product IDS of your memberships |
||
| 40 | * |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | function get_membership_products() { |
||
| 44 | $product_ids = array(); |
||
| 45 | if ( function_exists( 'wc_memberships_get_user_memberships' ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 46 | $user_memberships = wc_memberships_get_user_memberships(); |
||
| 47 | |||
| 48 | if ( ! empty( $user_memberships ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 49 | foreach ( $user_memberships as $membership ) { |
||
|
0 ignored issues
–
show
|
|||
| 50 | $current_products = $membership->plan->get_product_ids(); |
||
| 51 | if ( ! empty( $current_products ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 52 | $product_ids = array_merge( $product_ids, $current_products ); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
|
0 ignored issues
–
show
|
|||
| 57 | if ( ! empty( $product_ids ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 58 | $product_ids = array_unique( $product_ids ); |
||
| 59 | } |
||
|
0 ignored issues
–
show
|
|||
| 60 | return $product_ids; |
||
| 61 | } |
||
|
0 ignored issues
–
show
|
|||
| 62 |