PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.5.2
ShopBuilder – WooCommerce Builder For Elementor v2.5.2
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 2.5.2, at app/Modules/CheckoutEditor/GeneralCheckout.php

135 lines 5.4 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( $this->billing_settings['billing_address_1'] ) ) {
37 $fields['address_1'] = wp_parse_args( $this->billing_settings['billing_address_1'], $fields['address_1'] );
38 } elseif ( ! empty( $this->shipping_settings['shipping_address_1'] ) ) {
39 $fields['address_1'] = wp_parse_args( $this->shipping_settings['shipping_address_1'], $fields['address_1'] );
40 }
41 // address_2.
42 if ( ! empty( $this->billing_settings['billing_address_2'] ) ) {
43 $fields['address_2'] = wp_parse_args( $this->billing_settings['billing_address_2'], $fields['address_2'] );
44 } elseif ( ! empty( $this->shipping_settings['shipping_address_2'] ) ) {
45 $fields['address_2'] = wp_parse_args( $this->shipping_settings['shipping_address_2'], $fields['address_2'] );
46 }
47 // city.
48 if ( ! empty( $this->billing_settings['billing_city'] ) ) {
49 $fields['city'] = wp_parse_args( $this->billing_settings['billing_city'], $fields['city'] );
50 } elseif ( ! empty( $this->shipping_settings['shipping_city'] ) ) {
51 $fields['city'] = wp_parse_args( $this->shipping_settings['shipping_city'], $fields['city'] );
52 }
53 // state.
54 if ( ! empty( $this->billing_settings['billing_state'] ) ) {
55 $fields['state'] = wp_parse_args( $this->billing_settings['billing_state'], $fields['state'] );
56 } elseif ( ! empty( $this->shipping_settings['shipping_state'] ) ) {
57 $fields['state'] = wp_parse_args( $this->shipping_settings['shipping_state'], $fields['state'] );
58 }
59 // State.
60 if ( ! empty( $this->billing_settings['billing_postcode'] ) ) {
61 $fields['postcode'] = wp_parse_args( $this->billing_settings['billing_postcode'], $fields['postcode'] );
62 } elseif ( ! empty( $this->shipping_settings['shipping_postcode'] ) ) {
63 $fields['postcode'] = wp_parse_args( $this->shipping_settings['shipping_postcode'], $fields['postcode'] );
64 }
65 return $fields;
66 }
67
68 /**
69 * @param array $fields fields.
70 * @return array
71 */
72 public function country_locale( $fields ) {
73 // State.
74 if ( isset( $fields['postcode']['label'] ) ) {
75 if ( ! empty( $this->billing_settings['billing_postcode']['label'] ) ) {
76 $fields['postcode']['label'] = $this->billing_settings['billing_postcode']['label'];
77 } elseif ( ! empty( $this->shipping_settings['shipping_postcode']['label'] ) ) {
78 $fields['postcode']['label'] = $this->shipping_settings['shipping_postcode']['label'];
79 }
80 }
81 if ( isset( $fields['postcode']['required'] ) ) {
82 if ( isset( $this->billing_settings['billing_postcode']['required'] ) ) {
83 $fields['postcode']['required'] = $this->billing_settings['billing_postcode']['required'];
84 } elseif ( isset( $this->shipping_settings['shipping_postcode']['required'] ) ) {
85 $fields['postcode']['required'] = $this->shipping_settings['shipping_postcode']['required'];
86 }
87 }
88 // Billing state.
89 if ( isset( $fields['state']['label'] ) ) {
90 if ( ! empty( $this->billing_settings['billing_state'] ) ) {
91 $fields['state']['label'] = $this->billing_settings['billing_state']['label'] ?? $fields['postcode']['label'];
92 } elseif ( ! empty( $this->shipping_settings['shipping_state'] ) ) {
93 $fields['state']['label'] = $this->shipping_settings['shipping_state']['label'] ?? $fields['postcode']['label'];
94 }
95 }
96 if ( isset( $fields['state']['required'] ) ) {
97 if ( isset( $this->billing_settings['billing_state']['required'] ) ) {
98 $fields['state']['required'] = $this->billing_settings['billing_state']['required'];
99 } elseif ( isset( $this->shipping_settings['shipping_state']['required'] ) ) {
100 $fields['state']['required'] = $this->shipping_settings['shipping_state']['required'];
101 }
102 }
103
104 // Billing city.
105 if ( isset( $fields['city']['label'] ) ) {
106 if ( ! empty( $this->billing_settings['billing_city'] ) ) {
107 $fields['city']['label'] = $this->billing_settings['billing_city']['label'] ?? $fields['city']['label'];
108 } elseif ( ! empty( $this->shipping_settings['shipping_city'] ) ) {
109 $fields['city']['label'] = $this->shipping_settings['shipping_city'] ?? $fields['city']['label'];
110 }
111 }
112
113 if ( isset( $fields['city']['required'] ) ) {
114 if ( isset( $this->billing_settings['billing_city']['required'] ) ) {
115 $fields['city']['required'] = $this->billing_settings['billing_city']['required'];
116 } elseif ( isset( $this->shipping_settings['shipping_city']['required'] ) ) {
117 $fields['city']['required'] = $this->shipping_settings['shipping_city']['required'];
118 }
119 }
120
121 return $fields;
122 }
123
124 /**
125 * @param array $country local.
126 * @return array
127 */
128 public function get_country_locale( $country ) {
129 foreach ( $country as $key => $fields ) {
130 $country[ $key ] = $this->country_locale( $fields );
131 }
132 return $country;
133 }
134 }
135