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