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