| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.5/wp-content/plugins/woocommerce/includes/product-usage/ |
Upload File : |
<?php
/**
* WooCommerce Product Usage.
*
* This class defines method to be used by Woo extensions to control product usage based on subscription status.
*
* @package WooCommerce\ProductUsage
*/
declare( strict_types = 1 );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Product usagee
*/
class WC_Product_Usage {
/**
* Load Product Usage class.
*
* @since 9.3.0
*/
public static function load() {
self::includes();
}
/**
* Include support files.
*
* @since 9.3.0
*/
protected static function includes() {
require_once WC_ABSPATH . 'includes/product-usage/class-wc-product-usage-rule-set.php';
}
/**
* Get product usage rule if it needs to be applied to the given product id.
*
* @param int $product_id product id to get feature restriction rules.
* @since 9.3.0
*/
public static function get_rules_for_product( int $product_id ): ?WC_Product_Usage_Rule_Set {
$rules = self::get_product_usage_restriction_rule( $product_id );
if ( null === $rules ) {
return null;
}
// When there is no subscription for the product, restrict usage.
if ( ! WC_Helper::has_product_subscription( $product_id ) ) {
return new WC_Product_Usage_Rule_Set( $rules );
}
$subscriptions = wp_list_filter( WC_Helper::get_installed_subscriptions(), array( 'product_id' => $product_id ) );
if ( empty( $subscriptions ) ) {
return new WC_Product_Usage_Rule_Set( $rules );
}
// Product should only have a single connected subscription on current store.
$product_subscription = current( $subscriptions );
if ( $product_subscription['expired'] ) {
return new WC_Product_Usage_Rule_Set( $rules );
}
return null;
}
/**
* Get the product usage rule for a product.
*
* @param int $product_id product id to get feature restriction rules.
* @return array|null
* @since 9.3.0
*/
private static function get_product_usage_restriction_rule( int $product_id ): ?array {
try {
$rules = WC_Helper::get_product_usage_notice_rules();
} catch ( Exception $e ) {
return null;
}
if ( empty( $rules['restricted_products'][ $product_id ] ) ) {
return null;
}
return $rules['restricted_products'][ $product_id ];
}
}
WC_Product_Usage::load();