| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | 7 | exit( 'This script cannot be accessed directly.' ); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | +use PhpParser\Node\Expr\Empty_; | |
| 10 | 11 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * CheckoutEditorInit |
| @@ -24,27 +25,10 @@ | ||
| 24 | 25 | private function __construct() { |
| 25 | 26 | parent::__construct(); |
| 26 | 27 | add_filter( 'woocommerce_get_country_locale', [ $this, 'get_country_locale' ] ); |
| 27 | 28 | add_filter( 'woocommerce_default_address_fields', [ $this, 'default_address_fields' ], 9999 ); |
| 28 | - add_filter( 'woocommerce_form_field_args', [ $this, 'customize_billing_state' ], 10, 3 ); // The hook will work for initial page load. | |
| 29 | 29 | } |
| 30 | 30 | /** |
| 31 | - * Customize the billing state field arguments on the initial page load. | |
| 32 | - * | |
| 33 | - * @param array $args The field arguments. | |
| 34 | - * @param string $key The field key. | |
| 35 | - * @param mixed $value The field value. | |
| 36 | - * @return array Modified field arguments. | |
| 37 | - */ | |
| 38 | - public function customize_billing_state( $args, $key, $value ) { | |
| 39 | - if ( 'billing_state' !== $key ) { | |
| 40 | - return $args; | |
| 41 | - } | |
| 42 | - $args['label'] = $this->billing_settings['billing_state']['label'] ?? esc_html__( 'State / Region', 'shopbuilder' ); | |
| 43 | - $args['placeholder'] = $this->billing_settings['billing_state']['placeholder'] ?? esc_html__( 'State / Region', 'shopbuilder' ); | |
| 44 | - return $args; | |
| 45 | - } | |
| 46 | - /** | |
| 47 | 31 | * @param array $fields fields. |
| 48 | 32 | * @return array |
| 49 | 33 | */ |
| 50 | 34 | public function default_address_fields( $fields ) { |
| @@ -85,23 +69,8 @@ | ||
| 85 | 69 | if ( ! empty( $this->billing_settings['billing_postcode'] ) ) { |
| 86 | 70 | $fields['postcode'] = wp_parse_args( $this->billing_settings['billing_postcode'], $fields['postcode'] ); |
| 87 | 71 | } elseif ( ! empty( $this->shipping_settings['shipping_postcode'] ) ) { |
| 88 | 72 | $fields['postcode'] = wp_parse_args( $this->shipping_settings['shipping_postcode'], $fields['postcode'] ); |
| 89 | - } | |
| 90 | - } | |
| 91 | - // Inject priority from saved settings order so WC's address-i18n.js does not re-sort locale-managed fields with core defaults. | |
| 92 | - $billing_keys = array_keys( $this->billing_settings ); | |
| 93 | - $shipping_keys = array_keys( $this->shipping_settings ); | |
| 94 | - foreach ( [ 'address_1', 'address_2', 'city', 'state', 'postcode' ] as $key ) { | |
| 95 | - if ( empty( $fields[ $key ] ) ) { | |
| 96 | - continue; | |
| 97 | - } | |
| 98 | - $billing_index = array_search( 'billing_' . $key, $billing_keys, true ); | |
| 99 | - $shipping_index = array_search( 'shipping_' . $key, $shipping_keys, true ); | |
| 100 | - if ( false !== $billing_index ) { | |
| 101 | - $fields[ $key ]['priority'] = ( absint( $billing_index ) + 1 ) * 10; | |
| 102 | - } elseif ( false !== $shipping_index ) { | |
| 103 | - $fields[ $key ]['priority'] = ( absint( $shipping_index ) + 1 ) * 10; | |
| 104 | 73 | } |
| 105 | 74 | } |
| 106 | 75 | return $fields; |
| 107 | 76 | } |