mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-17 14:52:56 +00:00
2.1.0
This commit is contained in:

committed by
Remco Tolsma

parent
82336a2bd8
commit
153a2cd7ed
47
includes/wcs-limit-functions.php
Normal file
47
includes/wcs-limit-functions.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Subscriptions Limit Functions
|
||||
*
|
||||
* @author Prospress
|
||||
* @category Core
|
||||
* @package WooCommerce Subscriptions/Functions
|
||||
* @version 2.1
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subscription's limit type.
|
||||
*
|
||||
* @param int|WC_Product $product A WC_Product object or the ID of a product
|
||||
* @return string containing the limit type
|
||||
*/
|
||||
function wcs_get_product_limitation( $product ) {
|
||||
if ( ! is_object( $product ) ) {
|
||||
$product = wc_get_product( $product );
|
||||
}
|
||||
|
||||
if ( ! isset( $product->product_custom_fields['_subscription_limit'][0] ) ) {
|
||||
return 'no';
|
||||
} elseif ( 'yes' == $product->product_custom_fields['_subscription_limit'][0] ) { // backward compatibility
|
||||
return 'any';
|
||||
} else {
|
||||
return $product->product_custom_fields['_subscription_limit'][0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if product is limited to one active subscription and user currently has this product on-hold.
|
||||
*
|
||||
* @param int|WC_Product $product A WC_Product object or the ID of a product
|
||||
* @return boolean
|
||||
*/
|
||||
function wcs_is_product_limited_for_user( $product, $user_id = 0 ) {
|
||||
if ( ! is_object( $product ) ) {
|
||||
$product = wc_get_product( $product );
|
||||
}
|
||||
|
||||
return ( ( 'active' == wcs_get_product_limitation( $product ) && wcs_user_has_subscription( $user_id, $product->id, 'on-hold' ) ) || ( 'no' !== wcs_get_product_limitation( $product ) && wcs_user_has_subscription( $user_id, $product->id, wcs_get_product_limitation( $product ) ) ) ) ? true : false;
|
||||
}
|
Reference in New Issue
Block a user