plugin updates

This commit is contained in:
Tony Volpe
2024-09-17 10:43:54 -04:00
parent 44b413346f
commit b7c8882c8c
1359 changed files with 58219 additions and 11364 deletions

View File

@@ -0,0 +1,50 @@
<?php
/**
* WooCommerce Product Usage Rule.
*
* This class defines the DTO for passing product feature restriction rules to WooCommerce extensions.
*
* @package WooCommerce\Admin\ProductUsage
*/
declare( strict_types = 1 );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Product_Usage_Rule_Set.
*/
class WC_Product_Usage_Rule_Set {
/**
* Set of product feature restriction rules.
*
* @var array|null $rules
*/
protected $rules;
/**
* Constructor
*
* @param array $rules product feature restriction rules.
*/
public function __construct( $rules ) {
$this->rules = $rules;
}
/**
* Retrieve the value of a rule by name
*
* @param string $rule_name name of the rule to retrieve value.
* @return mixed|null
*/
public function get_rule( string $rule_name ) {
if ( ! isset( $this->rules[ $rule_name ] ) ) {
return null;
}
return $this->rules[ $rule_name ];
}
}

View File

@@ -0,0 +1,87 @@
<?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 {
$rules = WC_Helper::get_product_usage_notice_rules();
if ( empty( $rules['restricted_products'][ $product_id ] ) ) {
return null;
}
return $rules['restricted_products'][ $product_id ];
}
}
WC_Product_Usage::load();