action.php
5 years ago
api.php
5 years ago
base.php
5 years ago
hooks.php
5 years ago
templates.php
5 years ago
base.php
238 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Core\Builders; |
| 4 | |
| 5 | use ShopEngine\Base\Common; |
| 6 | use ShopEngine\Core\Page_Templates\Hooks\Account; |
| 7 | use ShopEngine\Core\Page_Templates\Hooks\Account_Address; |
| 8 | use ShopEngine\Core\Page_Templates\Hooks\Account_Details; |
| 9 | use ShopEngine\Core\Page_Templates\Hooks\Account_Downloads; |
| 10 | use ShopEngine\Core\Page_Templates\Hooks\Account_Login; |
| 11 | use ShopEngine\Core\Page_Templates\Hooks\Account_Orders; |
| 12 | use ShopEngine\Core\Page_Templates\Hooks\Account_Orders_View; |
| 13 | use ShopEngine\Core\Page_Templates\Hooks\Archive; |
| 14 | use ShopEngine\Core\Page_Templates\Hooks\Cart; |
| 15 | use ShopEngine\Core\Page_Templates\Hooks\Checkout; |
| 16 | use ShopEngine\Core\Page_Templates\Hooks\Empty_Cart; |
| 17 | use ShopEngine\Core\Page_Templates\Hooks\Shop; |
| 18 | use ShopEngine\Core\Page_Templates\Hooks\Single; |
| 19 | use ShopEngine\Core\Page_Templates\Hooks\Thank_You; |
| 20 | use ShopEngine\Core\Template_Cpt; |
| 21 | use ShopEngine\Traits\Singleton; |
| 22 | use ShopEngine\Utils\Elementor_Data_Map; |
| 23 | |
| 24 | defined('ABSPATH') || exit; |
| 25 | |
| 26 | class Base extends Common |
| 27 | { |
| 28 | |
| 29 | use Singleton; |
| 30 | |
| 31 | // $api variable call for Cpt Class Instance |
| 32 | public $form; |
| 33 | |
| 34 | // $api variable call for Api Class Instance |
| 35 | public $api; |
| 36 | |
| 37 | public function get_dir() { |
| 38 | |
| 39 | return dirname(__FILE__); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | * |
| 47 | */ |
| 48 | public function init() { |
| 49 | |
| 50 | $this->api = new Api(); |
| 51 | |
| 52 | #Registering custom post type |
| 53 | Template_Cpt::instance()->init(); |
| 54 | |
| 55 | #All hooks..................... |
| 56 | Hooks::instance()->init(); |
| 57 | |
| 58 | Shop::instance()->init(); |
| 59 | |
| 60 | Archive::instance()->init(); |
| 61 | |
| 62 | Single::instance()->init(); |
| 63 | |
| 64 | Cart::instance()->init(); |
| 65 | |
| 66 | Empty_Cart::instance()->init(); |
| 67 | |
| 68 | Checkout::instance()->init(); |
| 69 | |
| 70 | Thank_You::instance()->init(); |
| 71 | |
| 72 | Account::instance()->init(); |
| 73 | |
| 74 | Account_Orders::instance()->init(); |
| 75 | |
| 76 | Account_Orders_View::instance()->init(); |
| 77 | |
| 78 | Account_Downloads::instance()->init(); |
| 79 | |
| 80 | Account_Address::instance()->init(); |
| 81 | |
| 82 | Account_Details::instance()->init(); |
| 83 | |
| 84 | Account_Login::instance()->init(); |
| 85 | |
| 86 | add_filter('woocommerce_checkout_fields', [$this, 'disabling_fields'], 999); |
| 87 | } |
| 88 | |
| 89 | public function disabling_fields($fields) { |
| 90 | |
| 91 | // checkout page |
| 92 | // - is any checkout template active ? |
| 93 | // - - then it is overriding the template |
| 94 | // - - - then add the filter |
| 95 | |
| 96 | if(is_checkout()) { |
| 97 | |
| 98 | $template_id = $this->get_template_id('checkout', 0); |
| 99 | |
| 100 | if(!empty($template_id)) { |
| 101 | |
| 102 | $current_page_id = get_the_ID(); |
| 103 | $mapper = new Elementor_Data_Map(); |
| 104 | |
| 105 | $dt = $mapper->get_elementor_data($template_id); |
| 106 | $els = $mapper->get_widget_data('shopengine-checkout-form-billing', $dt); |
| 107 | |
| 108 | if(!empty($els[0]->settings)) { |
| 109 | |
| 110 | $obj = $els[0]->settings; |
| 111 | unset($els); |
| 112 | |
| 113 | if(!empty($obj->shopengine_hide_billing_first_name_field)) { |
| 114 | |
| 115 | unset($fields['billing']['billing_first_name']); |
| 116 | } |
| 117 | |
| 118 | if(!empty($obj->shopengine_hide_billing_last_name_field)) { |
| 119 | |
| 120 | unset($fields['billing']['billing_last_name']); |
| 121 | } |
| 122 | |
| 123 | if(!empty($obj->shopengine_hide_billing_company_field)) { |
| 124 | |
| 125 | unset($fields['billing']['billing_company']); |
| 126 | } |
| 127 | |
| 128 | if(!empty($obj->shopengine_hide_billing_country_field)) { |
| 129 | |
| 130 | unset($fields['billing']['billing_country']); |
| 131 | } |
| 132 | |
| 133 | if(!empty($obj->shopengine_hide_billing_address_1_field)) { |
| 134 | |
| 135 | unset($fields['billing']['billing_address_1']); |
| 136 | } |
| 137 | |
| 138 | if(!empty($obj->shopengine_hide_billing_address_2_field)) { |
| 139 | |
| 140 | unset($fields['billing']['billing_address_2']); |
| 141 | } |
| 142 | |
| 143 | if(!empty($obj->shopengine_hide_billing_city_field)) { |
| 144 | |
| 145 | unset($fields['billing']['billing_city']); |
| 146 | } |
| 147 | |
| 148 | if(!empty($obj->shopengine_hide_billing_state_field)) { |
| 149 | |
| 150 | unset($fields['billing']['billing_state']); |
| 151 | } |
| 152 | |
| 153 | if(!empty($obj->shopengine_hide_billing_postcode_field)) { |
| 154 | |
| 155 | unset($fields['billing']['billing_postcode']); |
| 156 | } |
| 157 | |
| 158 | if(!empty($obj->shopengine_hide_billing_phone_field)) { |
| 159 | |
| 160 | unset($fields['billing']['billing_phone']); |
| 161 | } |
| 162 | |
| 163 | if(!empty($obj->shopengine_hide_billing_email_field)) { |
| 164 | |
| 165 | unset($fields['billing']['billing_email']); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | $els = $mapper->get_widget_data('shopengine-checkout-form-shipping', $dt); |
| 170 | |
| 171 | if(!empty($els[0]->settings)) { |
| 172 | |
| 173 | $obj = $els[0]->settings; |
| 174 | unset($els); |
| 175 | |
| 176 | if(!empty($obj->shopengine_hide_billing_first_name_field)) { |
| 177 | |
| 178 | unset($fields['shipping']['shipping_first_name']); |
| 179 | } |
| 180 | |
| 181 | if(!empty($obj->shopengine_hide_shipping_last_name_field)) { |
| 182 | |
| 183 | unset($fields['shipping']['shipping_last_name']); |
| 184 | } |
| 185 | |
| 186 | if(!empty($obj->shopengine_hide_shipping_company_field)) { |
| 187 | |
| 188 | unset($fields['shipping']['shipping_company']); |
| 189 | } |
| 190 | |
| 191 | if(!empty($obj->shopengine_hide_shipping_country_field)) { |
| 192 | |
| 193 | unset($fields['shipping']['shipping_country']); |
| 194 | } |
| 195 | |
| 196 | if(!empty($obj->shopengine_hide_shipping_address_1_field)) { |
| 197 | |
| 198 | unset($fields['shipping']['shipping_address_1']); |
| 199 | } |
| 200 | |
| 201 | if(!empty($obj->shopengine_hide_shipping_address_2_field)) { |
| 202 | |
| 203 | unset($fields['shipping']['shipping_address_2']); |
| 204 | } |
| 205 | |
| 206 | if(!empty($obj->shopengine_hide_shipping_city_field)) { |
| 207 | |
| 208 | unset($fields['shipping']['shipping_city']); |
| 209 | } |
| 210 | |
| 211 | if(!empty($obj->shopengine_hide_shipping_state_field)) { |
| 212 | |
| 213 | unset($fields['shipping']['shipping_state']); |
| 214 | } |
| 215 | |
| 216 | if(!empty($obj->shopengine_hide_shipping_postcode_field)) { |
| 217 | |
| 218 | unset($fields['shipping']['shipping_postcode']); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | } else { |
| 223 | |
| 224 | // var_dump('ohh....... no checkout template is active!'); |
| 225 | |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | |
| 230 | return $fields; |
| 231 | } |
| 232 | |
| 233 | public function get_template_id($type, $def = '') { |
| 234 | |
| 235 | return get_option(Action::PK__SHOPENGINE_TEMPLATE . '__' . $type, $def); |
| 236 | } |
| 237 | } |
| 238 |