PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / trunk
پارسی دیت – Parsi Date vtrunk
6.2.1 6.2 6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / inc / Helper / WooCommerce.php
wp-parsidate / inc / Helper Last commit date
Assets.php 1 month ago Cache.php 2 months ago Date.php 1 month ago Debug.php 1 month ago FeedReader.php 1 month ago HTML.php 1 month ago Helper.php 2 months ago JSON.php 2 months ago Nonce.php 2 months ago Notice.php 1 month ago Number.php 2 months ago NumberConverter.php 1 month ago Param.php 2 months ago Sanitizing.php 1 month ago Strip.php 2 months ago Templates.php 2 months ago User.php 2 months ago Validating.php 2 months ago WooCommerce.php 2 months ago WordPress.php 1 month 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