default.php
139 lines
| 1 | <?php |
| 2 | defined('ABSPATH') || exit; |
| 3 | add_filter('woocommerce_product_tabs', function ($tabs) { |
| 4 | |
| 5 | if(isset($tabs['description'])) { |
| 6 | $tabs['description']['callback'] = 'woocommerce_product_description_tab'; |
| 7 | } |
| 8 | |
| 9 | return $tabs; |
| 10 | }, 999); |
| 11 | |
| 12 | |
| 13 | \ShopEngine\Widgets\Widget_Helper::instance()->comment_template_filter_checker(); |
| 14 | |
| 15 | |
| 16 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_filter_by_match('woocommerce/single-product/tabs/tabs.php', 'templates/single-product/tabs/tabs.php'); |
| 17 | |
| 18 | $product = \ShopEngine\Widgets\Products::instance()->get_product($post_type); |
| 19 | |
| 20 | $product_tabs = apply_filters('woocommerce_product_tabs', []); |
| 21 | |
| 22 | $in_editor_mode = \ShopEngine\Core\Template_Cpt::TYPE == get_post_type(); |
| 23 | |
| 24 | if($in_editor_mode) { |
| 25 | |
| 26 | global $product, $post; |
| 27 | |
| 28 | $main_post = clone $post; |
| 29 | |
| 30 | $product = \ShopEngine\Widgets\Products::instance()->get_product($post_type); |
| 31 | $post = get_post($product->get_id()); |
| 32 | |
| 33 | add_filter('the_content', [\ShopEngine\Widgets\Products::instance(), 'product_tab_content_preview']); |
| 34 | |
| 35 | $product_tabs = woocommerce_default_product_tabs(); |
| 36 | } |
| 37 | |
| 38 | // Remove Auxin Shop template loader filter |
| 39 | |
| 40 | if ( is_plugin_active('auxin-shop/auxin-shop.php') ) { |
| 41 | |
| 42 | remove_filter('wc_get_template', 'auxshp_get_wc_template', 11, 2); |
| 43 | remove_filter( 'woocommerce_product_review_comment_form_args', 'auxshp_modern_form_ouput', 10, 1 ); |
| 44 | |
| 45 | // Remove Auxin Shop template loader filter |
| 46 | global $wp_filter; |
| 47 | if (isset($wp_filter['woocommerce_locate_template'])) { |
| 48 | foreach ($wp_filter['woocommerce_locate_template']->callbacks as $priority => $callbacks) { |
| 49 | foreach ($callbacks as $key => $callback) { |
| 50 | if (is_array($callback['function']) && |
| 51 | is_object($callback['function'][0]) && |
| 52 | get_class($callback['function'][0]) === 'AUXSHP_Template_Loader' && |
| 53 | $callback['function'][1] === 'load_templates') { |
| 54 | unset($wp_filter['woocommerce_locate_template']->callbacks[$priority][$key]); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | ?> |
| 62 | |
| 63 | <div class="shopengine-product-tabs"> |
| 64 | <?php |
| 65 | // Get widget settings |
| 66 | $settings = isset($settings) ? $settings : []; |
| 67 | $enable_attribute_links = isset($settings['shopengine_product_tabs_enable_attribute_links']) ? $settings['shopengine_product_tabs_enable_attribute_links'] : 'yes'; |
| 68 | $link_target = isset($settings['shopengine_product_tabs_attribute_link_target']) ? $settings['shopengine_product_tabs_attribute_link_target'] : ''; |
| 69 | |
| 70 | // Add a temporary filter so attribute values link to the shop page with a filter query param |
| 71 | $shop_attribute_link_filter = null; |
| 72 | |
| 73 | if ($enable_attribute_links === 'yes') { |
| 74 | $shop_attribute_link_filter = function($html, $attribute, $values) use ($link_target) { |
| 75 | if ( is_object($attribute) && method_exists($attribute, 'is_taxonomy') ) { |
| 76 | $shop_url = ''; |
| 77 | if ( function_exists('wc_get_page_permalink') ) { |
| 78 | $shop_url = wc_get_page_permalink('shop'); |
| 79 | } |
| 80 | if ( empty($shop_url) ) { |
| 81 | $shop_url = get_post_type_archive_link('product'); |
| 82 | } |
| 83 | |
| 84 | $linked = []; |
| 85 | $target_attr = $link_target === '_blank' ? ' target="_blank" rel="noopener"' : ''; |
| 86 | |
| 87 | if ( $attribute->is_taxonomy() ) { |
| 88 | // Handle taxonomy attributes (pa_color, pa_size, etc) |
| 89 | $taxonomy = $attribute->get_name(); // e.g. pa_color |
| 90 | foreach ($values as $v) { |
| 91 | if ( is_object($v) && isset($v->slug) ) { |
| 92 | $term_slug = $v->slug; |
| 93 | $term_name = $v->name; |
| 94 | } else { |
| 95 | $term_name = wp_strip_all_tags((string)$v); |
| 96 | $term_slug = sanitize_title($term_name); |
| 97 | } |
| 98 | $param_name = 'filter_' . $taxonomy; |
| 99 | $url = add_query_arg($param_name, $term_slug, $shop_url); |
| 100 | $linked[] = sprintf('<a href="%s" rel="tag"%s>%s</a>', esc_url($url), $target_attr, esc_html($term_name)); |
| 101 | } |
| 102 | } else { |
| 103 | // Handle custom attributes (stored in postmeta) |
| 104 | $attr_name = $attribute->get_name(); // e.g. 'Material', 'Brand' |
| 105 | $slug = sanitize_title($attr_name); |
| 106 | foreach ($values as $v) { |
| 107 | $value_text = is_object($v) ? $v->name : wp_strip_all_tags((string)$v); |
| 108 | $value_slug = sanitize_title($value_text); |
| 109 | $param_name = 'filter_custom_' . $slug; |
| 110 | $url = add_query_arg($param_name, $value_slug, $shop_url); |
| 111 | $linked[] = sprintf('<a href="%s" rel="tag"%s>%s</a>', esc_url($url), $target_attr, esc_html($value_text)); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return wpautop(wptexturize(implode(', ', $linked))); |
| 116 | } |
| 117 | |
| 118 | return $html; |
| 119 | }; |
| 120 | |
| 121 | add_filter('woocommerce_attribute', $shop_attribute_link_filter, 10, 3); |
| 122 | } |
| 123 | |
| 124 | woocommerce_output_product_data_tabs(); |
| 125 | |
| 126 | // Remove our temporary filter so it doesn't affect other outputs |
| 127 | if ($shop_attribute_link_filter !== null) { |
| 128 | remove_filter('woocommerce_attribute', $shop_attribute_link_filter, 10, 3); |
| 129 | } |
| 130 | ?> |
| 131 | </div> |
| 132 | |
| 133 | <?php |
| 134 | |
| 135 | if($in_editor_mode) { |
| 136 | |
| 137 | $post = $main_post; |
| 138 | } |
| 139 |