Admin
4 weeks ago
AsyncTasks
4 weeks ago
Emails
4 weeks ago
Enums
10 months ago
Frontend
4 weeks ago
Privacy
4 weeks ago
Utilities
4 weeks ago
Config.php
4 weeks ago
DataRetentionController.php
4 weeks ago
Factory.php
10 months ago
Notification.php
4 weeks ago
NotificationQuery.php
10 months ago
StockNotifications.php
4 weeks ago
StockSyncController.php
10 months ago
Config.php
211 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Internal\StockNotifications; |
| 6 | |
| 7 | use Automattic\WooCommerce\Enums\ProductType; |
| 8 | use Automattic\WooCommerce\Enums\ProductStockStatus; |
| 9 | use Automattic\WooCommerce\Enums\ProductStatus; |
| 10 | |
| 11 | /** |
| 12 | * Configuration class for stock notifications. |
| 13 | */ |
| 14 | class Config { |
| 15 | |
| 16 | /** |
| 17 | * Runtime cache for supported product types. |
| 18 | * |
| 19 | * @var array<string> |
| 20 | */ |
| 21 | private static $supported_product_types; |
| 22 | |
| 23 | /** |
| 24 | * Runtime cache for supported product statuses. |
| 25 | * |
| 26 | * @var array<string> |
| 27 | */ |
| 28 | private static $supported_product_statuses; |
| 29 | |
| 30 | /** |
| 31 | * Runtime cache for eligible stock statuses. |
| 32 | * |
| 33 | * @var array<string> |
| 34 | */ |
| 35 | private static $eligible_stock_statuses; |
| 36 | |
| 37 | /** |
| 38 | * Runtime cache for verification expiration time threshold. |
| 39 | * |
| 40 | * @var int |
| 41 | */ |
| 42 | private static $verification_expiration_time_threshold; |
| 43 | |
| 44 | /** |
| 45 | * Get the supported product types. |
| 46 | * |
| 47 | * @return array<string> |
| 48 | */ |
| 49 | public static function get_supported_product_types(): array { |
| 50 | if ( is_array( self::$supported_product_types ) ) { |
| 51 | return self::$supported_product_types; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Filter: woocommerce_customer_stock_notifications_supported_product_types |
| 56 | * |
| 57 | * @since 10.2.0 |
| 58 | * |
| 59 | * @param array $product_types Product types. |
| 60 | */ |
| 61 | self::$supported_product_types = (array) apply_filters( |
| 62 | 'woocommerce_customer_stock_notifications_supported_product_types', |
| 63 | array( |
| 64 | ProductType::SIMPLE, |
| 65 | ProductType::VARIABLE, |
| 66 | ProductType::VARIATION, |
| 67 | ) |
| 68 | ); |
| 69 | |
| 70 | return self::$supported_product_types; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get the supported product statuses. |
| 75 | * |
| 76 | * @return array<string> |
| 77 | */ |
| 78 | public static function get_supported_product_statuses(): array { |
| 79 | if ( is_array( self::$supported_product_statuses ) ) { |
| 80 | return self::$supported_product_statuses; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Filter: woocommerce_customer_stock_notifications_supported_product_statuses |
| 85 | * |
| 86 | * @since 10.2.0 |
| 87 | * |
| 88 | * @param array $product_statuses Product statuses. |
| 89 | */ |
| 90 | self::$supported_product_statuses = (array) apply_filters( |
| 91 | 'woocommerce_customer_stock_notifications_supported_product_statuses', |
| 92 | array( |
| 93 | ProductStatus::PUBLISH, |
| 94 | ) |
| 95 | ); |
| 96 | |
| 97 | return self::$supported_product_statuses; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get the eligible stock statuses that trigger sending notifications. |
| 102 | * |
| 103 | * @return array<string> |
| 104 | */ |
| 105 | public static function get_eligible_stock_statuses(): array { |
| 106 | if ( is_array( self::$eligible_stock_statuses ) ) { |
| 107 | return self::$eligible_stock_statuses; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Filter: woocommerce_customer_stock_notifications_supported_stock_statuses |
| 112 | * |
| 113 | * @since 10.2.0 |
| 114 | * |
| 115 | * @param array $stock_statuses Stock statuses. |
| 116 | */ |
| 117 | self::$eligible_stock_statuses = (array) apply_filters( |
| 118 | 'woocommerce_customer_stock_notifications_supported_stock_statuses', |
| 119 | array( |
| 120 | ProductStockStatus::IN_STOCK, |
| 121 | ProductStockStatus::ON_BACKORDER, |
| 122 | ) |
| 123 | ); |
| 124 | |
| 125 | return self::$eligible_stock_statuses; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Get the metadata name for product-level signups. |
| 130 | * |
| 131 | * @return string |
| 132 | */ |
| 133 | public static function get_product_signups_meta_key(): string { |
| 134 | return 'customer_stock_notifications_enable_signups'; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Check if signups are allowed. |
| 139 | * |
| 140 | * @return bool |
| 141 | */ |
| 142 | public static function allows_signups(): bool { |
| 143 | return 'yes' === get_option( 'woocommerce_customer_stock_notifications_allow_signups', 'no' ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Check if double opt-in is required. |
| 148 | * |
| 149 | * @return bool |
| 150 | */ |
| 151 | public static function requires_double_opt_in(): bool { |
| 152 | return 'yes' === get_option( 'woocommerce_customer_stock_notifications_require_double_opt_in', 'no' ); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Check if an account is required. |
| 157 | * |
| 158 | * @return bool |
| 159 | */ |
| 160 | public static function requires_account(): bool { |
| 161 | return 'yes' === get_option( 'woocommerce_customer_stock_notifications_require_account', 'no' ); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Check if an account is created on signup. |
| 166 | * |
| 167 | * @return bool |
| 168 | */ |
| 169 | public static function creates_account_on_signup(): bool { |
| 170 | return 'yes' === get_option( 'woocommerce_customer_stock_notifications_create_account_on_signup', 'no' ); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * How long to keep pending notifications before deleting them (in days). |
| 175 | * |
| 176 | * @return int |
| 177 | */ |
| 178 | public static function get_unverified_deletion_days_threshold(): int { |
| 179 | return absint( |
| 180 | get_option( |
| 181 | 'woocommerce_customer_stock_notifications_unverified_deletions_days_threshold', |
| 182 | 0 |
| 183 | ) |
| 184 | ); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Returns verification codes expiration time threshold (in seconds). |
| 189 | * |
| 190 | * @return int |
| 191 | */ |
| 192 | public static function get_verification_expiration_time_threshold(): int { |
| 193 | if ( ! is_null( self::$verification_expiration_time_threshold ) ) { |
| 194 | return self::$verification_expiration_time_threshold; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Filter the verification codes expiration time (in seconds). |
| 199 | * |
| 200 | * @param int $threshold |
| 201 | * @since 10.2.0 |
| 202 | */ |
| 203 | self::$verification_expiration_time_threshold = (int) apply_filters( |
| 204 | 'woocommerce_customer_stock_notifications_verification_expiration_time_threshold', |
| 205 | HOUR_IN_SECONDS |
| 206 | ); |
| 207 | |
| 208 | return self::$verification_expiration_time_threshold; |
| 209 | } |
| 210 | } |
| 211 |