Assets.php
2 weeks ago
Cache.php
2 weeks ago
Date.php
2 weeks ago
Debug.php
2 weeks ago
FeedReader.php
2 weeks ago
HTML.php
2 weeks ago
Helper.php
2 weeks ago
JSON.php
2 weeks ago
Nonce.php
2 weeks ago
Notice.php
2 weeks ago
Number.php
2 weeks ago
NumberConverter.php
2 weeks ago
Param.php
2 weeks ago
Sanitizing.php
2 weeks ago
Strip.php
2 weeks ago
Templates.php
2 weeks ago
User.php
2 weeks ago
Validating.php
2 weeks ago
WooCommerce.php
2 weeks ago
WordPress.php
2 weeks ago
WooCommerce.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPParsidate\Helper; |
| 4 | |
| 5 | class WooCommerce { |
| 6 | /** |
| 7 | * Check WC custom order tables are enabled or not |
| 8 | * |
| 9 | * @return bool |
| 10 | */ |
| 11 | public static function hposEnabled(): bool { |
| 12 | return class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled(); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Check value is postal code |
| 17 | * |
| 18 | * @param mixed $postalCode |
| 19 | * @param bool $checkSum |
| 20 | * |
| 21 | * @return bool |
| 22 | */ |
| 23 | public static function isPostalCode( $postalCode, $checkSum = false ): bool { |
| 24 | // Convert to English |
| 25 | $postalCode = Number::toEnglish( $postalCode ); |
| 26 | |
| 27 | // Remove space and special character |
| 28 | $cleanedCode = preg_replace( '/[-\s]/', '', $postalCode ); |
| 29 | if ( ! preg_match( "/^\d{10}$/", $cleanedCode ) ) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // Postal code not start with zero |
| 34 | if ( $cleanedCode[0] === '0' ) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | // Checksum Control |
| 39 | if ( $checkSum ) { |
| 40 | $checkDigit = (int) $cleanedCode[9]; |
| 41 | $sum = 0; |
| 42 | for ( $i = 0; $i < 9; $i ++ ) { |
| 43 | $sum += (int) $cleanedCode[ $i ] * ( 10 - $i ); |
| 44 | } |
| 45 | $remainder = $sum % 11; |
| 46 | $calculatedCheckDigit = ( $remainder < 2 ) ? $remainder : 11 - $remainder; |
| 47 | |
| 48 | return $checkDigit === $calculatedCheckDigit; |
| 49 | } |
| 50 | |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get WC order statuses |
| 56 | * |
| 57 | * @return array |
| 58 | */ |
| 59 | public static function getOrderStatuses(): array { |
| 60 | $statuses = wc_get_order_statuses(); |
| 61 | |
| 62 | return array_combine( |
| 63 | array_map( static fn( $k ) => str_replace( 'wc-', '', $k ), array_keys( $statuses ) ), |
| 64 | array_values( $statuses ) |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 |