default.php
104 lines
| 1 | <?php $data_attr = apply_filters('shopengine/add_to_cart_widget/optional_tooltip_data_attr', ''); ?> |
| 2 | |
| 3 | <div class='shopengine-swatches' <?php echo esc_attr($data_attr)?>> |
| 4 | |
| 5 | <?php |
| 6 | |
| 7 | $editor_mode = (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview()); |
| 8 | |
| 9 | if(get_post_type() == \ShopEngine\Core\Template_Cpt::TYPE) { |
| 10 | |
| 11 | if($product->get_stock_status() != 'instock') { |
| 12 | |
| 13 | echo esc_html__('To see the add to cart button , please set stock status as instock for - .', 'shopengine') . '"' . esc_html( $product->get_name() ) . '"'; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | /* |
| 18 | --------------------------------------------- |
| 19 | Add action for woocommerce quantity button |
| 20 | -------------------------------------------- |
| 21 | */ |
| 22 | |
| 23 | if(!$product->is_sold_individually()) { |
| 24 | |
| 25 | $stock_quantity = $product->get_stock_quantity(); |
| 26 | |
| 27 | if($stock_quantity != 1){ |
| 28 | |
| 29 | // plus minus button |
| 30 | |
| 31 | $btn_arg = [ |
| 32 | 'plus_icon' => $shopengine_quantity_plus_icon, |
| 33 | 'minus_icon' => $shopengine_quantity_minus_icon, |
| 34 | 'position' => $shopengine_quantity_btn_position, |
| 35 | ]; |
| 36 | |
| 37 | add_action('woocommerce_before_add_to_cart_quantity', function () use ($btn_arg) { |
| 38 | |
| 39 | echo wp_kses(sprintf('<div class="quantity-wrap %1$s">', $btn_arg['position']), \ShopEngine\Utils\Helper::get_kses_array()); |
| 40 | |
| 41 | |
| 42 | if($btn_arg['position'] === 'before') { ?> |
| 43 | <div class="shopengine-qty-btn"> |
| 44 | <button type="button" |
| 45 | class="plus"> <?php \Elementor\Icons_Manager::render_icon($btn_arg['plus_icon'], ['aria-hidden' => 'true']); ?> </button> |
| 46 | <button type="button" |
| 47 | class="minus"> <?php \Elementor\Icons_Manager::render_icon($btn_arg['minus_icon'], ['aria-hidden' => 'true']); ?> </button> |
| 48 | </div> |
| 49 | <?php |
| 50 | } |
| 51 | |
| 52 | if($btn_arg['position'] === 'both') { ?> |
| 53 | <button type="button" |
| 54 | class="minus"> <?php \Elementor\Icons_Manager::render_icon($btn_arg['minus_icon'], ['aria-hidden' => 'true']); ?> </button> |
| 55 | <?php |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | add_action('woocommerce_after_add_to_cart_quantity', function () use ($btn_arg) { |
| 60 | |
| 61 | if($btn_arg['position'] === 'after') { ?> |
| 62 | <div class="shopengine-qty-btn"> |
| 63 | <button type="button" |
| 64 | class="plus"> <?php \Elementor\Icons_Manager::render_icon($btn_arg['plus_icon'], ['aria-hidden' => 'true']); ?> </button> |
| 65 | <button type="button" |
| 66 | class="minus"> <?php \Elementor\Icons_Manager::render_icon($btn_arg['minus_icon'], ['aria-hidden' => 'true']); ?> </button> |
| 67 | </div> |
| 68 | <?php |
| 69 | } |
| 70 | |
| 71 | if($btn_arg['position'] === 'both') { ?> |
| 72 | <button type="button" |
| 73 | class="plus"> <?php \Elementor\Icons_Manager::render_icon($btn_arg['plus_icon'], ['aria-hidden' => 'true']); ?> </button> |
| 74 | <?php |
| 75 | } |
| 76 | |
| 77 | echo '</div>'; |
| 78 | }); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if($editor_mode) { |
| 83 | |
| 84 | global $wp_query, $post;; |
| 85 | $main_query = clone $wp_query; |
| 86 | $main_post = clone $post; |
| 87 | |
| 88 | $wp_query = new \WP_Query([]); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | do_action('woocommerce_' . $product->get_type() . '_add_to_cart'); |
| 93 | |
| 94 | if($editor_mode) { |
| 95 | $wp_query = $main_query; |
| 96 | $post = $main_post; |
| 97 | wp_reset_query(); |
| 98 | wp_reset_postdata(); |
| 99 | } |
| 100 | |
| 101 | ?> |
| 102 | |
| 103 | </div> |
| 104 |