default.php
44 lines
| 1 | <?php |
| 2 | defined('ABSPATH') || exit; |
| 3 | if(get_post_type() == \ShopEngine\Core\Template_Cpt::TYPE) { |
| 4 | wc()->frontend_includes(); |
| 5 | |
| 6 | if(empty(WC()->cart->cart_contents)) { |
| 7 | |
| 8 | WC()->session = new WC_Session_Handler(); |
| 9 | WC()->session->init(); |
| 10 | WC()->customer = new WC_Customer(get_current_user_id(), true); |
| 11 | WC()->cart = new WC_Cart(); |
| 12 | |
| 13 | $demo_products = get_posts( |
| 14 | array( |
| 15 | 'post_type' => 'product', |
| 16 | 'numberposts' => 1, |
| 17 | 'post_status' => 'publish', |
| 18 | 'fields' => 'ids', |
| 19 | 'orderby' => 'ID', |
| 20 | 'order' => 'DESC' |
| 21 | ) |
| 22 | ); |
| 23 | |
| 24 | if(!empty($demo_products)) { |
| 25 | foreach($demo_products as $id) { |
| 26 | WC()->cart->add_to_cart($id); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | WC()->cart->calculate_totals(); |
| 33 | $editor_mode = (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview()); |
| 34 | |
| 35 | if(WC()->cart->is_empty() && $editor_mode){ |
| 36 | $file = '/view.php'; |
| 37 | }elseif(WC()->cart->is_empty() && !$editor_mode){ |
| 38 | $file = '/empty.php'; |
| 39 | }else{ |
| 40 | $file = '/cart.php'; |
| 41 | } |
| 42 | |
| 43 | wc_get_template($file, ['settings' => $settings], __DIR__, __DIR__); |
| 44 |