default.php
167 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 | // Remove Auxin Shop template loader filter |
| 93 | if (is_plugin_active('auxin-shop/auxin-shop.php')) { |
| 94 | |
| 95 | remove_filter('wc_get_template', 'auxshp_get_wc_template', 11, 2); |
| 96 | |
| 97 | // Remove Auxin Shop template loader filter |
| 98 | global $wp_filter; |
| 99 | if (isset($wp_filter['woocommerce_locate_template'])) { |
| 100 | foreach ($wp_filter['woocommerce_locate_template']->callbacks as $priority => $callbacks) { |
| 101 | foreach ($callbacks as $key => $callback) { |
| 102 | if (is_array($callback['function']) && |
| 103 | is_object($callback['function'][0]) && |
| 104 | get_class($callback['function'][0]) === 'AUXSHP_Template_Loader' && |
| 105 | $callback['function'][1] === 'load_templates') { |
| 106 | unset($wp_filter['woocommerce_locate_template']->callbacks[$priority][$key]); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Get the current theme name |
| 114 | $themeName = get_template(); |
| 115 | |
| 116 | /* |
| 117 | --------------------------------------------- |
| 118 | Remove Envo Shop JS if Envo Shop is active |
| 119 | This is to prevent conflicts with ShopEngine's single product template |
| 120 | -------------------------------------------- |
| 121 | */ |
| 122 | if($themeName == 'envo-shop') { |
| 123 | |
| 124 | // Stop Envo Shop from rendering its own duplicate plus/minus buttons |
| 125 | remove_action('woocommerce_before_add_to_cart_quantity', 'envo_shop_display_quantity_minus'); |
| 126 | remove_action('woocommerce_after_add_to_cart_quantity', 'envo_shop_display_quantity_plus'); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | // Check if gift card plugin is active and enabled first |
| 131 | $gift_card_plugin_active = function_exists('is_plugin_active') ? is_plugin_active('wt-woocommerce-gift-cards/wt-woocommerce-gift-cards.php') : false; |
| 132 | $gift_card_class_exists = class_exists('Wt_Gc_Gift_Card_Purchase_Setup_Product_Page'); |
| 133 | $gift_card_support_enabled = !empty($shopengine_woocommerce_gift_card_support) && $shopengine_woocommerce_gift_card_support === 'yes'; |
| 134 | |
| 135 | // Only proceed if gift card functionality is fully available |
| 136 | if ($gift_card_plugin_active && $gift_card_class_exists && $gift_card_support_enabled) { |
| 137 | $product_id = $product->get_id(); |
| 138 | $is_gift_card_product = metadata_exists( 'post', $product_id, '_wt_gc_gift_card_product' ) && get_post_meta( $product_id, '_wt_gc_gift_card_product', true ); |
| 139 | |
| 140 | if ($is_gift_card_product) { |
| 141 | $gift_card_setup = Wt_Gc_Gift_Card_Purchase_Setup_Product_Page::get_instance(); |
| 142 | |
| 143 | // Check if templates are enabled for this product |
| 144 | if (method_exists($gift_card_setup, 'is_templates_enabled') && $gift_card_setup::is_templates_enabled($product_id)) { |
| 145 | // Use the complete gift card template design when support is enabled |
| 146 | $gift_card_setup->shop_single_page_design(); |
| 147 | } |
| 148 | } else { |
| 149 | // For regular products when gift card plugin is active, use standard WooCommerce action |
| 150 | do_action('woocommerce_' . $product->get_type() . '_add_to_cart'); |
| 151 | } |
| 152 | } else { |
| 153 | // When gift card plugin is not active, use standard WooCommerce action |
| 154 | do_action('woocommerce_' . $product->get_type() . '_add_to_cart'); |
| 155 | } |
| 156 | |
| 157 | if($editor_mode) { |
| 158 | $wp_query = $main_query; |
| 159 | $post = $main_post; |
| 160 | wp_reset_query(); |
| 161 | wp_reset_postdata(); |
| 162 | } |
| 163 | |
| 164 | ?> |
| 165 | |
| 166 | </div> |
| 167 |