PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.3
ShopBuilder – WooCommerce Builder For Elementor v3.2.3
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Modules / CheckoutEditor / GeneralCheckout.php

GeneralCheckout.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.3, at app/Modules/CheckoutEditor/GeneralCheckout.php

145 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Modules\CheckoutEditor;
4
5 // Do not allow directly accessing this file.
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit( 'This script cannot be accessed directly.' );
8 }
9
10 use PhpParser\Node\Expr\Empty_;
11 use RadiusTheme\SB\Traits\SingletonTrait;
12
13 /**
14 * CheckoutEditorInit
15 */
16 class GeneralCheckout extends CheckoutEditorBase {
17 /**
18 * Singleton Trait.
19 */
20 use SingletonTrait;
21
22 /**
23 * Notifications hooks.
24 */
25 private function __construct() {
26 parent::__construct();
27 add_filter( 'woocommerce_get_country_locale', [ $this, 'get_country_locale' ] );
28 add_filter( 'woocommerce_default_address_fields', [ $this, 'default_address_fields' ], 9999 );
29 }
30 /**
31 * @param array $fields fields.
32 * @return array
33 */
34 public function default_address_fields( $fields ) {
35 // address_1.
36 if ( ! empty( $fields['address_1'] ) ) {
37 if ( ! empty( $this->billing_settings['billing_address_1'] ) ) {
38 $fields['address_1'] = wp_parse_args( $this->billing_settings['billing_address_1'], $fields['address_1'] );
39 } elseif ( ! empty( $this->shipping_settings['shipping_address_1'] ) ) {
40 $fields['address_1'] = wp_parse_args( $this->shipping_settings['shipping_address_1'], $fields['address_1'] );
41 }
42 }
43 if ( ! empty( $fields['address_2'] ) ) {
44 // address_2.
45 if ( ! empty( $this->billing_settings['billing_address_2'] ) ) {
46 $fields['address_2'] = wp_parse_args( $this->billing_settings['billing_address_2'], $fields['address_2'] );
47 } elseif ( ! empty( $this->shipping_settings['shipping_address_2'] ) ) {
48 $fields['address_2'] = wp_parse_args( $this->shipping_settings['shipping_address_2'], $fields['address_2'] );
49 }
50 }
51 if ( ! empty( $fields['city'] ) ) {
52 // city.
53 if ( ! empty( $this->billing_settings['billing_city'] ) ) {
54 $fields['city'] = wp_parse_args( $this->billing_settings['billing_city'], $fields['city'] );
55 } elseif ( ! empty( $this->shipping_settings['shipping_city'] ) ) {
56 $fields['city'] = wp_parse_args( $this->shipping_settings['shipping_city'], $fields['city'] );
57 }
58 }
59 if ( ! empty( $fields['state'] ) ) {
60 // state.
61 if ( ! empty( $this->billing_settings['billing_state'] ) ) {
62 $fields['state'] = wp_parse_args( $this->billing_settings['billing_state'], $fields['state'] );
63 } elseif ( ! empty( $this->shipping_settings['shipping_state'] ) ) {
64 $fields['state'] = wp_parse_args( $this->shipping_settings['shipping_state'], $fields['state'] );
65 }
66 }
67 if ( ! empty( $fields['postcode'] ) ) {
68 // State.
69 if ( ! empty( $this->billing_settings['billing_postcode'] ) ) {
70 $fields['postcode'] = wp_parse_args( $this->billing_settings['billing_postcode'], $fields['postcode'] );
71 } elseif ( ! empty( $this->shipping_settings['shipping_postcode'] ) ) {
72 $fields['postcode'] = wp_parse_args( $this->shipping_settings['shipping_postcode'], $fields['postcode'] );
73 }
74 }
75 return $fields;
76 }
77
78 /**
79 * @param array $fields fields.
80 * @return array
81 */
82 public function country_locale( $fields ) {
83 // State.
84 if ( isset( $fields['postcode']['label'] ) ) {
85 if ( ! empty( $this->billing_settings['billing_postcode']['label'] ) ) {
86 $fields['postcode']['label'] = $this->billing_settings['billing_postcode']['label'];
87 } elseif ( ! empty( $this->shipping_settings['shipping_postcode']['label'] ) ) {
88 $fields['postcode']['label'] = $this->shipping_settings['shipping_postcode']['label'];
89 }
90 }
91 if ( isset( $fields['postcode']['required'] ) ) {
92 if ( isset( $this->billing_settings['billing_postcode']['required'] ) ) {
93 $fields['postcode']['required'] = $this->billing_settings['billing_postcode']['required'];
94 } elseif ( isset( $this->shipping_settings['shipping_postcode']['required'] ) ) {
95 $fields['postcode']['required'] = $this->shipping_settings['shipping_postcode']['required'];
96 }
97 }
98 // Billing state.
99 if ( isset( $fields['state']['label'] ) ) {
100 if ( ! empty( $this->billing_settings['billing_state'] ) ) {
101 $fields['state']['label'] = $this->billing_settings['billing_state']['label'] ?? $fields['postcode']['label'];
102 } elseif ( ! empty( $this->shipping_settings['shipping_state'] ) ) {
103 $fields['state']['label'] = $this->shipping_settings['shipping_state']['label'] ?? $fields['postcode']['label'];
104 }
105 }
106 if ( isset( $fields['state']['required'] ) ) {
107 if ( isset( $this->billing_settings['billing_state']['required'] ) ) {
108 $fields['state']['required'] = $this->billing_settings['billing_state']['required'];
109 } elseif ( isset( $this->shipping_settings['shipping_state']['required'] ) ) {
110 $fields['state']['required'] = $this->shipping_settings['shipping_state']['required'];
111 }
112 }
113
114 // Billing city.
115 if ( isset( $fields['city']['label'] ) ) {
116 if ( ! empty( $this->billing_settings['billing_city'] ) ) {
117 $fields['city']['label'] = $this->billing_settings['billing_city']['label'] ?? $fields['city']['label'];
118 } elseif ( ! empty( $this->shipping_settings['shipping_city'] ) ) {
119 $fields['city']['label'] = $this->shipping_settings['shipping_city'] ?? $fields['city']['label'];
120 }
121 }
122
123 if ( isset( $fields['city']['required'] ) ) {
124 if ( isset( $this->billing_settings['billing_city']['required'] ) ) {
125 $fields['city']['required'] = $this->billing_settings['billing_city']['required'];
126 } elseif ( isset( $this->shipping_settings['shipping_city']['required'] ) ) {
127 $fields['city']['required'] = $this->shipping_settings['shipping_city']['required'];
128 }
129 }
130
131 return $fields;
132 }
133
134 /**
135 * @param array $country local.
136 * @return array
137 */
138 public function get_country_locale( $country ) {
139 foreach ( $country as $key => $fields ) {
140 $country[ $key ] = $this->country_locale( $fields );
141 }
142 return $country;
143 }
144 }
145