default.php
147 lines
| 1 | <?php defined('ABSPATH') || exit; |
| 2 | |
| 3 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_filter(); |
| 4 | |
| 5 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_part_filter_by_match('woocommerce/content-product.php', 'templates/content-product.php'); |
| 6 | |
| 7 | $upsell_ids = $product->get_upsell_ids(); |
| 8 | |
| 9 | $upsells = array_filter(array_map('wc_get_product', $upsell_ids), 'wc_products_array_filter_visible'); |
| 10 | |
| 11 | $editor_mode = (\Elementor\Plugin::$instance->editor->is_edit_mode() || is_preview()); |
| 12 | |
| 13 | if($editor_mode) { |
| 14 | |
| 15 | global $wp_query, $post;; |
| 16 | $main_query = clone $wp_query; |
| 17 | $main_post = clone $post; |
| 18 | |
| 19 | $wp_query = new \WP_Query([]); |
| 20 | |
| 21 | $args = [ |
| 22 | 'type' => ['simple'], |
| 23 | 'limit' => $shopengine_up_sells_product_to_show, |
| 24 | ]; |
| 25 | |
| 26 | $upsells = wc_get_products($args); |
| 27 | |
| 28 | unset($args, $upsell_ids); |
| 29 | } |
| 30 | |
| 31 | // woostify theme compatibility |
| 32 | $theme_name = get_template(); |
| 33 | if ($theme_name == 'woostify') { |
| 34 | |
| 35 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_wrapper_open', 10 ); |
| 36 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_print_out_of_stock_label', 15 ); |
| 37 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_image_wrapper_open', 20 ); |
| 38 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_change_sale_flash', 23 ); |
| 39 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_product_loop_item_action', 25 ); |
| 40 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_link_open', 30 ); |
| 41 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_hover_image', 40 ); |
| 42 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_image', 50 ); |
| 43 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_link_close', 60 ); |
| 44 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_add_to_cart_on_image', 70 ); |
| 45 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_product_loop_item_wishlist_icon_bottom', 80 ); |
| 46 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_image_wrapper_close', 90 ); |
| 47 | remove_action( 'woocommerce_before_shop_loop_item_title', 'woostify_loop_product_content_open', 100 ); |
| 48 | |
| 49 | remove_action( 'woocommerce_shop_loop_item_title', 'woostify_add_template_loop_product_category', 5 ); |
| 50 | remove_action( 'woocommerce_shop_loop_item_title', 'woostify_add_template_loop_product_title', 10 ); |
| 51 | |
| 52 | remove_action( 'woocommerce_after_shop_loop_item_title', 'woostify_loop_product_rating', 2 ); |
| 53 | remove_action( 'woocommerce_after_shop_loop_item_title', 'woostify_loop_product_meta_open', 5 ); |
| 54 | remove_action( 'woocommerce_after_shop_loop_item_title', 'woostify_loop_product_price', 10 ); |
| 55 | |
| 56 | remove_action( 'woocommerce_after_shop_loop_item', 'woostify_loop_product_add_to_cart_button', 10 ); |
| 57 | remove_action( 'woocommerce_after_shop_loop_item', 'woostify_loop_product_meta_close', 20 ); |
| 58 | remove_action( 'woocommerce_after_shop_loop_item', 'woostify_loop_product_content_close', 50 ); |
| 59 | remove_action( 'woocommerce_after_shop_loop_item', 'woostify_loop_product_wrapper_close', 100 ); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | if (is_plugin_active('auxin-shop/auxin-shop.php')) { |
| 64 | |
| 65 | remove_action( 'woocommerce_after_shop_loop_item_title', 'auxshp_loop_product_meta', 12 ); |
| 66 | remove_action( 'woocommerce_after_shop_loop_item' , 'auxshp_loop_product_tools', 12 ); |
| 67 | remove_action( 'woocommerce_archive_description' , 'auxshp_archive_page_title_description', 1 ); |
| 68 | remove_action( 'woocommerce_before_shop_loop_item_title', 'auxshp_get_product_thumbnail', 11 ); |
| 69 | } |
| 70 | |
| 71 | if(empty($upsells)) { |
| 72 | |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | $is_slider_enable = ($shopengine_up_sells_product_enable_slider == "yes") ? true : false; |
| 77 | $init_slider = ($shopengine_up_sells_product_to_show > $shopengine_up_sells_product_slider_perview) && (count($upsells) > $shopengine_up_sells_product_slider_perview) ; |
| 78 | |
| 79 | |
| 80 | $shopengine_up_sells_product_column_gap = $this->get_settings_for_display('shopengine_up_sells_product_column_gap'); |
| 81 | $shopengine_up_sells_product_column_gap = isset($shopengine_up_sells_product_column_gap['size']) ? $shopengine_up_sells_product_column_gap : ['size' => 10]; |
| 82 | |
| 83 | // slider controls for the template file |
| 84 | $slider_options = [ |
| 85 | 'slider_enabled' => $is_slider_enable, |
| 86 | 'slides_to_show' => $shopengine_up_sells_product_slider_perview, |
| 87 | 'slider_loop' => ($init_slider && $shopengine_up_sells_product_slider_loop === "yes") ? true : false, |
| 88 | 'slider_autoplay' => ($shopengine_up_sells_product_slider_autoplay === "yes") ? true : false, |
| 89 | 'slider_autoplay_delay' => $shopengine_up_sells_product_slider_autoplay_delay, |
| 90 | 'slider_space_between' => $shopengine_up_sells_product_column_gap['size'], |
| 91 | ]; |
| 92 | |
| 93 | $columns = $is_slider_enable ? $shopengine_up_sells_product_slider_perview : $shopengine_up_sells_product_column_gap['size']; |
| 94 | |
| 95 | ?> |
| 96 | |
| 97 | <div class="shopengine-up-sells <?php echo ($is_slider_enable ? 'slider-enabled' : 'slider-disabled'); ?>" data-controls="<?php echo esc_attr(json_encode($slider_options)); ?>"> |
| 98 | |
| 99 | <?php if( isset($shopengine_up_sells_product_show_products_heading) && $shopengine_up_sells_product_show_products_heading == 'yes' ) : ?> |
| 100 | <h2 class="shopengine-up-sells-products-heading"><?php echo esc_html($shopengine_up_sells_product_show_products_heading_title ?? ''); ?></h2> |
| 101 | <?php endif; ?> |
| 102 | |
| 103 | <?php |
| 104 | if($post_type == \ShopEngine\Core\Template_Cpt::TYPE) { |
| 105 | wc_get_template( |
| 106 | 'single-product/up-sells.php', |
| 107 | [ |
| 108 | 'upsells' => $upsells, |
| 109 | 'posts_per_page' => $shopengine_up_sells_product_to_show, |
| 110 | 'orderby' => $shopengine_up_sells_product_orderby, |
| 111 | 'columns' => $columns, |
| 112 | ] |
| 113 | ); |
| 114 | } else { |
| 115 | woocommerce_upsell_display($shopengine_up_sells_product_to_show, $columns, $shopengine_up_sells_product_orderby, $shopengine_up_sells_product_order); |
| 116 | } |
| 117 | |
| 118 | if($init_slider && $is_slider_enable && $shopengine_up_sells_product_slider_show_dots) { |
| 119 | echo '<div class="swiper-pagination" style="width: 100%;"></div>'; |
| 120 | } |
| 121 | |
| 122 | if($init_slider && $is_slider_enable && $shopengine_up_sells_product_slider_show_arrows) { |
| 123 | shopengine_content_render( |
| 124 | sprintf( |
| 125 | '<div class="swiper-button-prev">%1$s</div><div class="swiper-button-next">%2$s</div>', |
| 126 | $this->get_icon_html($shopengine_up_sells_product_slider_left_arrow_icon), |
| 127 | $this->get_icon_html($shopengine_up_sells_product_slider_right_arrow_icon) |
| 128 | ) |
| 129 | ); |
| 130 | } |
| 131 | ?> |
| 132 | </div> |
| 133 | |
| 134 | <?php |
| 135 | |
| 136 | if($editor_mode) { |
| 137 | |
| 138 | global $wp_query, $post;; |
| 139 | |
| 140 | $wp_query = $main_query; |
| 141 | $post = $main_post; |
| 142 | wp_reset_query(); |
| 143 | wp_reset_postdata(); |
| 144 | |
| 145 | unset($main_query, $main_post); |
| 146 | } |
| 147 |