Changeset 3377998
- Timestamp:
- 10/14/2025 09:59:55 AM (4 months ago)
- Location:
- ecommerce-product-catalog/trunk
- Files:
-
- 7 edited
-
ecommerce-product-catalog.php (modified) (1 diff)
-
functions/content-functions.php (modified) (1 diff)
-
modules/attributes/attributes-shortcodes.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
templates/full/product-page-inside.php (modified) (4 diffs)
-
templates/shortcode-catalog.php (modified) (3 diffs)
-
templates/templates-functions.php (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ecommerce-product-catalog/trunk/ecommerce-product-catalog.php
r3365848 r3377998 4 4 * Plugin URI: https://implecode.com/wordpress/product-catalog/#cam=in-plugin-urls&key=plugin-url 5 5 * Description: Easy to use, powerful and beautiful WordPress eCommerce plugin from impleCode. A Great choice if you want to sell easy and quick. Or beautifully present your products on a WordPress website. Full WordPress integration does a great job not only for Merchants but also for Developers and Theme Constructors. 6 * Version: 3.4.1 06 * Version: 3.4.11 7 7 * Author: impleCode 8 8 * Author URI: https://implecode.com/#cam=in-plugin-urls&key=author-url -
ecommerce-product-catalog/trunk/functions/content-functions.php
r3359160 r3377998 132 132 'loading' => get_site_url() . '/wp-includes/js/thickbox/loadingAnimation.gif', 133 133 ) ); 134 if ( is_user_logged_in() ) {135 $localize['nonce'] = wp_create_nonce( 'ic-ajax-nonce' );136 }134 //if ( is_user_logged_in() ) { 135 $localize['nonce'] = wp_create_nonce( 'ic-ajax-nonce' ); 136 //} 137 137 wp_localize_script( 'al_product_scripts', 'product_object', $localize ); 138 138 } -
ecommerce-product-catalog/trunk/modules/attributes/attributes-shortcodes.php
r2878961 r3377998 1 1 <?php 2 2 3 if ( ! defined( 'ABSPATH' ) ) {3 if ( ! defined( 'ABSPATH' ) ) { 4 4 exit; // Exit if accessed directly 5 5 } … … 9 9 * Here all product attributes are defined and managed. 10 10 * 11 * @version 1.0.012 * @package ecommerce-product-catalog/includes13 * @author impleCode11 * @version 1.0.0 12 * @package ecommerce-product-catalog/includes 13 * @author impleCode 14 14 */ 15 15 add_shortcode( 'product_attributes', 'ic_product_attributes' ); … … 19 19 * 20 20 * @param type $atts 21 * 21 22 * @return string 22 23 */ 23 24 function ic_product_attributes( $atts ) { 25 $args = shortcode_atts( array( 26 'product' => get_the_ID(), 27 ), $atts ); 28 $product_id = intval( $args['product'] ); 29 if ( empty( $product_id ) ) { 30 return ''; 31 } 32 33 return get_product_attributes( $product_id ); 34 } 35 36 add_shortcode( 'product_weight', 'ic_product_weight_shortcode' ); 37 38 /** 39 * Shows product weight 40 * 41 * @param type $atts 42 * 43 * @return string 44 */ 45 function ic_product_weight_shortcode( $atts ) { 24 46 $args = shortcode_atts( array( 25 47 'product' => get_the_ID(), 26 48 ), $atts ); 27 return get_product_attributes( $args[ 'product' ] ); 49 50 $product_id = intval( $args['product'] ); 51 if ( empty( $product_id ) ) { 52 return ''; 53 } 54 55 return ic_get_product_weight( $product_id ); 28 56 } 57 58 add_shortcode( 'product_size', 'ic_product_size_shortcode' ); 59 60 /** 61 * Shows product size 62 * 63 * @param type $atts 64 * 65 * @return string 66 */ 67 function ic_product_size_shortcode( $atts ) { 68 $args = shortcode_atts( array( 69 'product' => get_the_ID(), 70 ), $atts ); 71 72 $product_id = intval( $args['product'] ); 73 if ( empty( $product_id ) ) { 74 return ''; 75 } 76 77 return ic_get_product_size( $product_id ); 78 } -
ecommerce-product-catalog/trunk/readme.txt
r3365848 r3377998 6 6 Tested up to: 6.8 7 7 Requires PHP: 5.6 8 Stable tag: 3.4.1 08 Stable tag: 3.4.11 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 390 390 Use [EPC Translate Project](https://translate.wordpress.org/projects/wp-plugins/ecommerce-product-catalog "eCommerce Product Catalog Translation Project") to add new or fix the existing translations in eCommerce Product Catalog. Use [Premium EPC Translation Project](https://translate.implecode.com/projects/ "eCommerce Product Catalog Translation Project") for all the extensions. 391 391 392 = 3.4.11 - 14/10/2025 = 393 394 * Added [product_size] shortcode 395 * Added [product_weight] shortcode 396 * Fixed checkout state field 397 392 398 = 3.4.10 - 22/09/2025 = 393 399 -
ecommerce-product-catalog/trunk/templates/full/product-page-inside.php
r3137415 r3377998 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly3 exit; // Exit if accessed directly 4 4 } 5 5 … … 19 19 $this_product_id = ic_get_product_id(); 20 20 if ( $this_product_id && $this_product_id !== $product_id ) { 21 $product_id = $this_product_id;22 $product = get_post( $product_id );23 setup_postdata( $product );21 $product_id = $this_product_id; 22 $product = get_post( $product_id ); 23 setup_postdata( $product ); 24 24 } 25 25 if ( empty( $product ) ) { 26 return;26 return; 27 27 } 28 28 $taxonomy = get_current_screen_tax(); … … 32 32 33 33 <div id="product_details_container"> 34 <?php35 do_action( 'before_product_details', $product_id, $single_options );36 $details_class = product_gallery_enabled( $single_options['enable_product_gallery'], $single_options['enable_product_gallery_only_when_exist'], $product );37 ?>34 <?php 35 do_action( 'before_product_details', $product_id, $single_options ); 36 $details_class = product_gallery_enabled( $single_options['enable_product_gallery'], $single_options['enable_product_gallery_only_when_exist'], $product ); 37 ?> 38 38 <div id="product_details" class="product-details <?php echo $details_class; ?>"> 39 <?php40 do_action( 'product_details', $product, $single_names );41 ?>39 <?php 40 do_action( 'product_details', $product, $single_names ); 41 ?> 42 42 </div> 43 <?php44 do_action( 'product_details_container_end', $product, $single_names );45 ?>43 <?php 44 do_action( 'product_details_container_end', $product, $single_names ); 45 ?> 46 46 </div> 47 47 <?php 48 48 if ( current_user_can( 'edit_products' ) ) { 49 do_action( 'ic_product_admin_actions', $product );49 do_action( 'ic_product_admin_actions', $product ); 50 50 } 51 51 ob_start(); … … 53 53 $after_product_details = ob_get_clean(); 54 54 if ( ! empty( $after_product_details ) ) { 55 ?>55 ?> 56 56 <div id="after-product-details" class="after-product-details"> 57 <?php echo $after_product_details ?>57 <?php echo $after_product_details ?> 58 58 </div> 59 <?php59 <?php 60 60 } 61 61 do_action( "after_after_product_details", $product, $single_names ); 62 62 ?> 63 63 <div class="after-product-description"> 64 <?php do_action( 'single_product_end', $product, $single_names, $taxonomy ); ?>64 <?php do_action( 'single_product_end', $product, $single_names, $taxonomy ); ?> 65 65 </div> 66 66 -
ecommerce-product-catalog/trunk/templates/shortcode-catalog.php
r3359160 r3377998 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly3 exit; // Exit if accessed directly 4 4 } 5 5 … … 13 13 class ic_shortcode_catalog { 14 14 15 private $multiple_settings, $status = 'catalog', $title = '', $after_header = 0, $loop_started = 0, $settings = array(), $the_content_filters = array(), $shortcode_listing_generated = 0, $post_type = ''; 16 17 function __construct() { 18 add_shortcode( 'show_product_catalog', array( $this, 'catalog_shortcode' ) ); 19 add_action( 'init', array( $this, 'init' ) ); 20 } 21 22 function init() { 23 add_action( 'wp_ajax_ic_assign_listing', array( $this, 'assign_listing' ) ); 24 if ( ! is_ic_shortcode_integration() ) { 25 return; 26 } 27 $this->settings = ic_get_shortcode_mode_settings(); 28 add_action( 'ic_catalog_wp', array( $this, 'hooks' ) ); 29 30 add_action( 'ic_shortcode_mode_settings_html', array( $this, 'settings_html' ) ); 31 add_action( 'ic_after_main_catalog_page_setting_html', array( $this, 'main_catalog_page_warning' ) ); 32 add_filter( 'ic_archive_multiple_settings_validation', array( $this, 'update_template' ) ); 33 add_action( 'ic_ajax_self_submit_init', array( $this, 'is_ajax_inside_shortcode' ), 10, 3 ); 34 do_action( 'ic_shortcode_integration_init' ); 35 } 36 37 function hooks() { 38 if ( ! is_ic_catalog_page() || apply_filters( 'ic_shortcode_catalog_apply', false ) ) { 39 return; 40 } 41 $this->get_pre_shortcode_query(); 42 $this->get_pre_shortcode_post(); 43 remove_all_actions( 'loop_no_results' ); 44 add_action( 'loop_no_results', array( $this, 'no_results_show_catalog' ) ); 45 46 add_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 47 48 add_action( 'ic_catalog_template_redirect', array( $this, 'overwrite_query' ), 999 ); 49 add_action( 'get_header', array( $this, 'catalog_query' ), 999, 0 ); 50 add_filter( 'ic_catalog_body_class_start', array( $this, 'overwrite_query' ), 1 ); 51 ////add_filter( 'ic_catalog_single_body_class', array( $this, 'catalog_query' ), 99, 1 ); 52 ////add_filter( 'ic_catalog_tax_body_class', array( $this, 'catalog_query' ), 98, 1 ); 53 add_filter( 'ic_catalog_tax_body_class', array( $this, 'tax_body_class' ), 98, 1 ); 54 add_filter( 'ic_catalog_single_body_class', array( $this, 'single_body_class' ), 98, 1 ); 15 private $multiple_settings, $status = 'catalog', $title = '', $after_header = 0, $loop_started = 0, $settings = array(), $the_content_filters = array(), $shortcode_listing_generated = 0, $post_type = ''; 16 17 function __construct() { 18 add_shortcode( 'show_product_catalog', array( $this, 'catalog_shortcode' ) ); 19 add_action( 'init', array( $this, 'init' ) ); 20 } 21 22 function init() { 23 add_action( 'wp_ajax_ic_assign_listing', array( $this, 'assign_listing' ) ); 24 if ( ! is_ic_shortcode_integration() ) { 25 return; 26 } 27 $this->settings = ic_get_shortcode_mode_settings(); 28 add_action( 'ic_catalog_wp', array( $this, 'hooks' ) ); 29 30 add_action( 'ic_shortcode_mode_settings_html', array( $this, 'settings_html' ) ); 31 add_action( 'ic_after_main_catalog_page_setting_html', array( $this, 'main_catalog_page_warning' ) ); 32 add_filter( 'ic_archive_multiple_settings_validation', array( $this, 'update_template' ) ); 33 add_action( 'ic_ajax_self_submit_init', array( $this, 'is_ajax_inside_shortcode' ), 10, 3 ); 34 do_action( 'ic_shortcode_integration_init' ); 35 } 36 37 function hooks() { 38 if ( ! is_ic_catalog_page() || apply_filters( 'ic_shortcode_catalog_apply', false ) ) { 39 return; 40 } 41 $this->get_pre_shortcode_query(); 42 $this->get_pre_shortcode_post(); 43 remove_all_actions( 'loop_no_results' ); 44 add_action( 'loop_no_results', array( $this, 'no_results_show_catalog' ) ); 45 46 add_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 47 48 add_action( 'ic_catalog_template_redirect', array( $this, 'overwrite_query' ), 999 ); 49 add_action( 'get_header', array( $this, 'catalog_query' ), 999, 0 ); 50 add_filter( 'body_class', array( $this, 'body_class' ), 1, 2 ); 51 add_filter( 'ic_catalog_body_class_start', array( $this, 'overwrite_query' ), 1 ); 52 ////add_filter( 'ic_catalog_single_body_class', array( $this, 'catalog_query' ), 99, 1 ); 53 ////add_filter( 'ic_catalog_tax_body_class', array( $this, 'catalog_query' ), 98, 1 ); 54 add_filter( 'ic_catalog_tax_body_class', array( $this, 'tax_body_class' ), 98, 1 ); 55 add_filter( 'ic_catalog_single_body_class', array( $this, 'single_body_class' ), 98, 1 ); 55 56 //add_filter( 'ic_catalog_body_class', array( $this, 'catalog_query' ), 98 ); 56 //add_filter( 'get_custom_logo', array( $this, 'catalog_query' ), 98 );57 58 add_filter( 'ic_catalog_pre_nav_menu', array( $this, 'remove_overwrite_filters' ), 99 );57 //add_filter( 'get_custom_logo', array( $this, 'catalog_query' ), 98 ); 58 59 add_filter( 'ic_catalog_pre_nav_menu', array( $this, 'remove_overwrite_filters' ), 99 ); 59 60 //add_filter( 'ic_catalog_tax_nav_menu', array( $this, 'fake_tax_first_post' ), 99 ); 60 61 //add_filter( 'ic_catalog_tax_nav_menu', array( $this, 'overwrite_query' ), 99 ); 61 add_filter( 'ic_catalog_pre_nav_menu_items', array( $this, 'remove_title_override' ) );62 add_filter( 'ic_catalog_pre_nav_menu', array( $this, 'remove_title_override' ), - 2 );63 add_filter( 'ic_catalog_nav_menu_items', array( $this, 'add_title_override' ) );64 add_filter( 'wp_list_pages_excludes', array( $this, 'remove_title_override' ), - 2 );65 add_filter( 'wp_list_pages', array( $this, 'add_title_override' ), 999 );66 add_filter( 'ic_catalog_nav_menu', array( $this, 'add_title_override' ), 99 );67 ////add_filter( 'ic_catalog_single_nav_menu', array( $this, 'catalog_query' ), 99 );68 add_filter( 'breadcrumb_trail_args', array( $this, 'remove_title_override' ) );69 add_filter( 'breadcrumb_trail_args', array( $this, 'catalog_query' ), 99 );70 //add_filter( 'breadcrumb_trail', array( $this, 'overwrite_query' ), 99 );71 add_filter( 'breadcrumb_trail', array( $this, 'add_title_override' ), 99 );72 73 74 add_filter( 'ic_catalog_listing_nav_menu', array( $this, 'fake_listing_first_post' ), 99 );75 add_action( 'get_template_part', array( $this, 'overwrite_query' ), 99, 0 );76 add_action( 'wp_after_load_template', array( $this, 'overwrite_query' ), 99, 0 );77 //add_action( 'get_template_part', array( $this, 'break_query' ), 100, 0 ); // Shows no content when multiple loops present62 add_filter( 'ic_catalog_pre_nav_menu_items', array( $this, 'remove_title_override' ) ); 63 add_filter( 'ic_catalog_pre_nav_menu', array( $this, 'remove_title_override' ), - 2 ); 64 add_filter( 'ic_catalog_nav_menu_items', array( $this, 'add_title_override' ) ); 65 add_filter( 'wp_list_pages_excludes', array( $this, 'remove_title_override' ), - 2 ); 66 add_filter( 'wp_list_pages', array( $this, 'add_title_override' ), 999 ); 67 add_filter( 'ic_catalog_nav_menu', array( $this, 'add_title_override' ), 99 ); 68 ////add_filter( 'ic_catalog_single_nav_menu', array( $this, 'catalog_query' ), 99 ); 69 add_filter( 'breadcrumb_trail_args', array( $this, 'remove_title_override' ) ); 70 add_filter( 'breadcrumb_trail_args', array( $this, 'catalog_query' ), 99 ); 71 //add_filter( 'breadcrumb_trail', array( $this, 'overwrite_query' ), 99 ); 72 add_filter( 'breadcrumb_trail', array( $this, 'add_title_override' ), 99 ); 73 74 75 add_filter( 'ic_catalog_listing_nav_menu', array( $this, 'fake_listing_first_post' ), 99 ); 76 add_action( 'get_template_part', array( $this, 'overwrite_query' ), 99, 0 ); 77 add_action( 'wp_after_load_template', array( $this, 'overwrite_query' ), 99, 0 ); 78 //add_action( 'get_template_part', array( $this, 'break_query' ), 100, 0 ); // Shows no content when multiple loops present 78 79 //add_action( 'get_template_part_content', array( $this, 'overwrite_query' ), 101, 0 ); 79 80 //add_action( 'get_template_part_loop', array( $this, 'overwrite_query' ), 101, 0 ); 80 81 //add_action( 'get_template_part_index', array( $this, 'overwrite_query' ), 101, 0 ); 81 82 //( 'get_template_part_page', array( $this, 'overwrite_query' ), 101, 0 ); 82 //add_filter( 'post_class', array( $this, 'catalog_query' ), -2 );83 add_filter( 'post_class', array( $this, 'overwrite_query' ), - 2 );84 add_filter( 'post_class', array( $this, 'check_post_class' ), 99 );85 //add_filter( 'post_class', array( $this, 'overwrite_query' ), 999 );86 //add_filter( 'post_class', array( $this, 'catalog_query' ), 999 ); //Better to add it only for some themes87 if ( ! empty( $this->settings['show_everywhere'] ) ) {88 add_action( 'ic_catalog_wp_head_start', array( $this, 'catalog_query_force' ), - 1, 0 );89 } else {90 add_action( 'ic_catalog_wp_head_start', array( $this, 'catalog_query' ), - 1, 0 );91 }92 add_action( 'ic_catalog_wp_head', array( $this, 'set_after_header' ), 9999, 0 );83 //add_filter( 'post_class', array( $this, 'catalog_query' ), -2 ); 84 add_filter( 'post_class', array( $this, 'overwrite_query' ), - 2 ); 85 add_filter( 'post_class', array( $this, 'check_post_class' ), 99 ); 86 //add_filter( 'post_class', array( $this, 'overwrite_query' ), 999 ); 87 //add_filter( 'post_class', array( $this, 'catalog_query' ), 999 ); //Better to add it only for some themes 88 if ( ! empty( $this->settings['show_everywhere'] ) ) { 89 add_action( 'ic_catalog_wp_head_start', array( $this, 'catalog_query_force' ), - 1, 0 ); 90 } else { 91 add_action( 'ic_catalog_wp_head_start', array( $this, 'catalog_query' ), - 1, 0 ); 92 } 93 add_action( 'ic_catalog_wp_head', array( $this, 'set_after_header' ), 9999, 0 ); 93 94 //add_action( 'ic_catalog_listing_wp_head', array( $this, 'overwrite_query' ), 999 ); 94 add_action( 'ic_catalog_search_wp_head', array( $this, 'overwrite_query' ), 999 );95 96 add_filter( 'single_post_title', array( $this, 'product_page_title' ), 99, 1 );97 98 add_action( 'loop_start', array( $this, 'loop_start' ), 10, 1 );99 add_action( 'loop_end', array( $this, 'loop_end' ) );100 101 add_action( 'shortcode_catalog_init', array( $this, 'catalog_query' ), 10, 0 );102 add_action( 'shortcode_catalog_init', array( $this, 'remove_overwrite_filters' ) );103 add_action( 'product_listing_begin', array( $this, 'remove_overwrite_filters' ) );104 105 add_action( 'admin_bar_menu', array( $this, 'catalog_query' ), - 1, 0 );106 add_action( 'admin_bar_menu', array( $this, 'overwrite_query' ), 9999, 0 );107 108 add_action( 'wp_footer', array( $this, 'catalog_query' ), - 1, 0 );109 add_action( 'wp_footer', array( $this, 'overwrite_query' ), 9999, 0 );110 111 add_action( 'ic_before_widget', array( $this, 'widget_switch_before' ) );112 add_action( 'ic_after_widget', array( $this, 'widget_switch_after' ) );113 114 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );115 116 //add_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99999999 );117 add_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99 );118 119 add_filter( 'the_content', array( $this, 'the_content_filter' ), - 999 );120 121 add_filter( 'next_post_link', array( $this, 'next_previous_post_link' ) );122 add_filter( 'previous_post_link', array( $this, 'next_previous_post_link' ) );123 124 add_filter( 'comments_open', array( $this, 'disable_comments' ), 10, 2 );125 126 add_action( 'ic_catalog_set_product_id', array( $this, 'catalog_query' ), - 1, 0 );127 128 add_filter( 'ic_catalog_force_product_header', array( $this, 'force_product_header' ) );129 add_filter( 'ic_catalog_force_category_header', array( $this, 'force_category_header' ) );130 $this->default_the_content();131 $this->theme_specific();132 do_action( 'ic_shortcode_catalog_hooks_added', $this );133 }134 135 function is_ajax_inside_shortcode( $ajax_query_vars, $params, $pre_ajax_query_vars ) {136 if ( ! empty( $pre_ajax_query_vars['page_id'] ) ) {137 $listing_id = get_product_listing_id();138 if ( $listing_id == $pre_ajax_query_vars['page_id'] ) {139 140 return;141 }142 $post = get_post( $pre_ajax_query_vars['page_id'] );143 if ( isset( $post->post_content ) && ic_has_page_catalog_shortcode( $post ) && is_product_filters_active() ) {144 ic_save_global( 'inside_show_catalog_shortcode', 1 );145 }146 }147 }148 149 function default_the_content() {150 $this->the_content_filters = array();151 $to_remove = array( 'basic_social_share_buttons' );152 foreach ( $to_remove as $remove ) {153 if ( ! function_exists( $remove ) ) {154 continue;155 }156 remove_filter( 'the_content', $remove );157 $this->the_content_filters[] = $remove;158 }159 /*160 remove_all_filters( 'the_content' );161 if ( function_exists( 'do_blocks' ) ) {162 add_filter( 'the_content', 'do_blocks', 9 );163 }164 add_filter( 'the_content', 'wptexturize' );165 add_filter( 'the_content', 'convert_smilies', 20 );166 add_filter( 'the_content', 'wpautop' );167 add_filter( 'the_content', 'shortcode_unautop' );168 add_filter( 'the_content', 'prepend_attachment' );169 if ( function_exists( 'wp_filter_content_tags' ) ) {170 add_filter( 'the_content', 'wp_filter_content_tags' );171 }172 if ( function_exists( 'wp_replace_insecure_home_url' ) ) {173 add_filter( 'the_content', 'wp_replace_insecure_home_url' );174 }175 add_filter( 'the_content', 'capital_P_dangit', 11 );176 add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop().177 *178 */179 }180 181 function reset_the_content() {182 if ( empty( $this->the_content_filters ) ) {183 return;184 }185 foreach ( $this->the_content_filters as $filter_name ) {186 add_filter( 'the_content', $filter_name );187 }188 }189 190 function the_content_filter( $return ) {191 if ( $this->status == 'page' ) {192 $this->catalog_query();193 add_filter( 'the_content', array( $this, 'overwrite_query' ), 999 );194 } else {195 remove_filter( 'the_content', array( $this, 'overwrite_query' ), 999 );196 }197 198 return $return;199 }200 201 function remove_title_override( $nav_menu ) {202 remove_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 );203 204 return $nav_menu;205 }206 207 function add_title_override( $nav_menu ) {208 add_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 );209 210 return $nav_menu;211 }212 213 function settings_html( $settings ) {214 215 if ( ! $this->no_page_id() ) {216 $available_templates = $this->available_templates();217 if ( is_array( $available_templates ) && ! empty( $available_templates ) ) {218 $current_template = $this->get_true_listing_template();219 $settings['template'] = $current_template;220 implecode_settings_dropdown( __( 'Template', 'ecommerce-product-catalog' ), 'archive_multiple_settings[shortcode_mode][template]', $settings['template'], array_merge( array( '0' => __( 'Default Template', 'ecommerce-product-catalog' ) ), $this->available_templates() ), 1, null, __( 'Choose one of the available page templates to display catalog pages.', 'ecommerce-product-catalog' ) );221 }222 }223 }224 225 function main_catalog_page_warning() {226 if ( $this->no_page_id() ) {227 $available_templates = $this->available_templates();228 if ( is_array( $available_templates ) && ! empty( $available_templates ) ) {229 echo '<br>';230 implecode_warning( __( "Select an existing page or create new to have an option to choose different page template.", 'ecommerce-product-catalog' ) );231 }232 }233 }234 235 function force_product_header( $force ) {236 if ( ! empty( $this->settings['force_name'] ) ) {237 $force = true;238 }239 240 return $force;241 }242 243 function force_category_header( $force ) {244 if ( ! empty( $this->settings['force_category_name'] ) ) {245 $force = true;246 }247 248 return $force;249 }250 251 function set_after_header() {252 $this->after_header = 1;253 }254 255 function set_loop_started() {256 $this->loop_started = 1;257 }258 259 function disable_comments( $open, $page_id ) {260 $listing_id = get_product_listing_id();261 if ( $page_id === $listing_id ) {262 return false;263 }264 265 return $open;266 }267 268 function next_previous_post_link( $link ) {269 if ( is_ic_product_listing() || is_ic_taxonomy_page() || is_ic_product_search() ) {270 return '';271 }272 273 return $link;274 }275 276 function auto_add_shortcode( $content ) {277 if ( is_ic_product_listing() && ! $this->has_listing_shortcode() ) {278 if ( ! $this->is_page_builder_edit() ) {279 $content .= do_shortcode( '[show_product_catalog]' );280 }281 }282 283 return $content;284 }285 286 function clear_known( $content ) {287 if ( empty( $this->settings['show_everywhere'] ) ) {288 $content = '';289 }290 291 if ( empty( $content ) ) {292 return $content;293 }294 add_filter( 'strip_shortcodes_tagnames', array( $this, 'known_shortcodes' ) );295 $content = strip_shortcodes( $content );296 remove_filter( 'strip_shortcodes_tagnames', array( $this, 'known_shortcodes' ) );297 298 $content = $this->strip_blocks( $content );299 300 return $content;301 }302 303 function known_shortcodes() {304 return array( 'show_products', 'show_categories' );305 }306 307 function strip_blocks( $content ) {308 if ( empty( $content ) ) {309 return $content;310 }311 $block_start = '<!-- wp:';312 $block_end = '/-->';313 $known_blocks = $this->known_blocks();314 foreach ( $known_blocks as $block_name ) {315 $start = strpos( $content, $block_start . $block_name );316 if ( $start !== false ) {317 $end = strpos( $content, $block_end, $start );318 if ( $end !== false ) {319 $strip = substr( $content, $start, $end + strlen( $block_end ) - $start );320 $content = trim( str_replace( $strip, '', $content ) );321 }322 }323 }324 325 return $content;326 }327 328 function known_blocks() {329 if ( function_exists( 'register_block_type' ) ) {330 return array( 'ic-epc/show-products', 'ic-epc/show-categories' );331 }332 333 return array();334 }335 336 function forced_meta() {337 if ( empty( $this->settings['show_everywhere'] ) ) {338 return array();339 } else {340 return array(341 'et_',342 '_avia',343 '_builder',344 'cs_'345 );346 }347 }348 349 function included_meta() {350 return array(351 '_wp_page_template',352 );353 }354 355 function included_meta_contains() {356 return array(357 'sidebar',358 'layout',359 );360 }361 362 function is_forced_meta( $meta_key ) {363 $forced_meta = $this->forced_meta();364 if ( in_array( $meta_key, $forced_meta ) ) {365 return true;366 } else {367 foreach ( $forced_meta as $part ) {368 if ( ic_string_contains( $meta_key, $part ) ) {369 return true;370 }371 }372 }373 374 return false;375 }376 377 function is_included_meta( $meta_key ) {378 if ( $this->is_forced_meta( $meta_key ) || in_array( $meta_key, $this->included_meta() ) ) {379 return true;380 } else {381 $excluded_parts = $this->included_meta_contains();382 foreach ( $excluded_parts as $part ) {383 if ( ic_string_contains( $meta_key, $part ) ) {384 return true;385 }386 }387 }388 389 return false;390 }391 392 function listing_metadata( $value, $object_id, $meta_key, $single ) {393 if ( empty( $meta_key ) ) {394 return $value;395 }396 $listing_id = get_product_listing_id();397 if ( ! is_ic_admin() && $this->is_included_meta( $meta_key ) && ! $this->no_page_id() && ( is_ic_product( $object_id ) || is_ic_product_category( $object_id ) ) ) {398 remove_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );399 $listing_meta = get_post_meta( $listing_id, $meta_key, $single );400 if ( ! empty( $listing_meta ) ) {401 $custom_keys = get_post_custom_keys( $object_id );402 if ( is_array( $custom_keys ) && in_array( $meta_key, $custom_keys ) ) {403 $this_meta = get_post_meta( $object_id, $meta_key, $single );404 if ( empty( $this_meta ) && $this->is_forced_meta( $meta_key ) ) {405 unset( $this_meta );406 }407 }408 if ( ! isset( $this_meta ) ) {409 if ( $single && is_array( $listing_meta ) ) {410 $listing_meta = array( $listing_meta );411 }412 $value = $listing_meta;413 }414 } else if ( $meta_key === '_wp_page_template' ) {415 $catalog_template = $this->get_template();416 if ( ! empty( $catalog_template ) ) {417 return $catalog_template;418 }419 }420 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );421 } else if ( $object_id == $listing_id && $meta_key === '_wp_page_template' ) {422 $catalog_template = $this->get_template();423 if ( ! empty( $catalog_template ) || is_numeric( $catalog_template ) ) {424 return $catalog_template;425 }426 } else if ( $meta_key === '_thumbnail_id' && empty( $this->settings['show_everywhere'] ) && $object_id == $listing_id && ! is_ic_product_listing() ) {427 $value = '';428 }429 430 return $value;431 }432 433 function get_template() {434 $current_template = $this->get_true_listing_template();435 $this->settings['template'] = $current_template;436 437 return apply_filters( 'ic_catalog_shortcode_mode_template', $this->settings['template'] );438 }439 440 function get_true_listing_template() {441 if ( $this->no_page_id() ) {442 return 0;443 }444 $listing_id = get_product_listing_id();445 remove_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );446 $current_template = get_post_meta( $listing_id, '_wp_page_template', true );447 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );448 449 return $current_template;450 }451 452 function available_templates() {453 $theme = wp_get_theme();454 if ( $theme->exists() ) {455 $available_templates = $theme->get_page_templates( null, 'page' );456 } else {457 $available_templates = array();458 }459 460 return $available_templates;461 }462 463 function update_template( $new_settings ) {464 if ( isset( $new_settings['shortcode_mode']['template'] ) ) {465 $available_templates = $this->available_templates();466 if ( $new_settings['shortcode_mode']['template'] === '0' || isset( $available_templates[ $new_settings['shortcode_mode']['template'] ] ) ) {467 $listing_id = get_product_listing_id();468 if ( ! empty( $listing_id ) ) {469 if ( empty( $new_settings['shortcode_mode']['template'] ) && ! is_numeric( $new_settings['shortcode_mode']['template'] ) ) {470 delete_post_meta( $listing_id, '_wp_page_template' );471 } else {472 update_post_meta( $listing_id, '_wp_page_template', $new_settings['shortcode_mode']['template'] );473 }474 }475 }476 }477 478 return $new_settings;479 }480 481 function theme_specific() {482 if ( function_exists( 'genesis_load_framework' ) || function_exists( 'awada_customizer_config' ) ) {483 remove_filter( 'post_class', array( $this, 'catalog_query' ), 999 );484 }485 486 //Customizr487 add_action( '__before_content', array( $this, 'overwrite_query' ), 99, 0 );488 489 //theme.co490 add_action( 'x_get_view', array( $this, 'overwrite_query' ) );491 492 //Astra493 add_filter( 'astra_dynamic_theme_css', array( $this, 'overwrite_query' ), - 99 );494 add_filter( 'astra_dynamic_theme_css', array( $this, 'catalog_query' ), 99 );495 496 add_filter( 'astra_breadcrumb_trail_args', array( $this, 'remove_title_override' ) );497 add_filter( 'astra_breadcrumb_trail_args', array( $this, 'catalog_query' ), 99 );498 add_filter( 'astra_breadcrumb_trail', array( $this, 'add_title_override' ), 99 );499 //add_filter( 'astra_get_post_id', 'ic_get_product_id', 99 );500 //DIVI501 if ( function_exists( 'et_setup_theme' ) ) {502 add_action( 'wp', array( $this, 'overwrite_query' ), 998 ); // for the dynamic CSS to work correctly503 add_action( 'wp', array( $this, 'overwrite_query' ), 1 ); // for the custom header template to work504 }505 }506 507 function fix_title( $title, $id = null ) {508 if ( is_ic_taxonomy_page() || is_ic_product_page() ) {509 if ( ! empty( $this->title ) && ( empty( $id ) || $id == get_product_listing_id() ) ) {510 $title = $this->title;95 add_action( 'ic_catalog_search_wp_head', array( $this, 'overwrite_query' ), 999 ); 96 97 add_filter( 'single_post_title', array( $this, 'product_page_title' ), 99, 1 ); 98 99 add_action( 'loop_start', array( $this, 'loop_start' ), 10, 1 ); 100 add_action( 'loop_end', array( $this, 'loop_end' ) ); 101 102 add_action( 'shortcode_catalog_init', array( $this, 'catalog_query' ), 10, 0 ); 103 add_action( 'shortcode_catalog_init', array( $this, 'remove_overwrite_filters' ) ); 104 add_action( 'product_listing_begin', array( $this, 'remove_overwrite_filters' ) ); 105 106 add_action( 'admin_bar_menu', array( $this, 'catalog_query' ), - 1, 0 ); 107 add_action( 'admin_bar_menu', array( $this, 'overwrite_query' ), 9999, 0 ); 108 109 add_action( 'wp_footer', array( $this, 'catalog_query' ), - 1, 0 ); 110 add_action( 'wp_footer', array( $this, 'overwrite_query' ), 9999, 0 ); 111 112 add_action( 'ic_before_widget', array( $this, 'widget_switch_before' ) ); 113 add_action( 'ic_after_widget', array( $this, 'widget_switch_after' ) ); 114 115 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 116 117 //add_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99999999 ); 118 add_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99 ); 119 120 add_filter( 'the_content', array( $this, 'the_content_filter' ), - 999 ); 121 122 add_filter( 'next_post_link', array( $this, 'next_previous_post_link' ) ); 123 add_filter( 'previous_post_link', array( $this, 'next_previous_post_link' ) ); 124 125 add_filter( 'comments_open', array( $this, 'disable_comments' ), 10, 2 ); 126 127 add_action( 'ic_catalog_set_product_id', array( $this, 'catalog_query' ), - 1, 0 ); 128 129 add_filter( 'ic_catalog_force_product_header', array( $this, 'force_product_header' ) ); 130 add_filter( 'ic_catalog_force_category_header', array( $this, 'force_category_header' ) ); 131 $this->default_the_content(); 132 $this->theme_specific(); 133 do_action( 'ic_shortcode_catalog_hooks_added', $this ); 134 } 135 136 function is_ajax_inside_shortcode( $ajax_query_vars, $params, $pre_ajax_query_vars ) { 137 if ( ! empty( $pre_ajax_query_vars['page_id'] ) ) { 138 $listing_id = get_product_listing_id(); 139 if ( $listing_id == $pre_ajax_query_vars['page_id'] ) { 140 141 return; 142 } 143 $post = get_post( $pre_ajax_query_vars['page_id'] ); 144 if ( isset( $post->post_content ) && ic_has_page_catalog_shortcode( $post ) && is_product_filters_active() ) { 145 ic_save_global( 'inside_show_catalog_shortcode', 1 ); 146 } 147 } 148 } 149 150 function default_the_content() { 151 $this->the_content_filters = array(); 152 $to_remove = array( 'basic_social_share_buttons' ); 153 foreach ( $to_remove as $remove ) { 154 if ( ! function_exists( $remove ) ) { 155 continue; 156 } 157 remove_filter( 'the_content', $remove ); 158 $this->the_content_filters[] = $remove; 159 } 160 /* 161 remove_all_filters( 'the_content' ); 162 if ( function_exists( 'do_blocks' ) ) { 163 add_filter( 'the_content', 'do_blocks', 9 ); 164 } 165 add_filter( 'the_content', 'wptexturize' ); 166 add_filter( 'the_content', 'convert_smilies', 20 ); 167 add_filter( 'the_content', 'wpautop' ); 168 add_filter( 'the_content', 'shortcode_unautop' ); 169 add_filter( 'the_content', 'prepend_attachment' ); 170 if ( function_exists( 'wp_filter_content_tags' ) ) { 171 add_filter( 'the_content', 'wp_filter_content_tags' ); 172 } 173 if ( function_exists( 'wp_replace_insecure_home_url' ) ) { 174 add_filter( 'the_content', 'wp_replace_insecure_home_url' ); 175 } 176 add_filter( 'the_content', 'capital_P_dangit', 11 ); 177 add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop(). 178 * 179 */ 180 } 181 182 function reset_the_content() { 183 if ( empty( $this->the_content_filters ) ) { 184 return; 185 } 186 foreach ( $this->the_content_filters as $filter_name ) { 187 add_filter( 'the_content', $filter_name ); 188 } 189 } 190 191 function the_content_filter( $return ) { 192 if ( $this->status == 'page' ) { 193 $this->catalog_query(); 194 add_filter( 'the_content', array( $this, 'overwrite_query' ), 999 ); 195 } else { 196 remove_filter( 'the_content', array( $this, 'overwrite_query' ), 999 ); 197 } 198 199 return $return; 200 } 201 202 function remove_title_override( $nav_menu ) { 203 remove_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 204 205 return $nav_menu; 206 } 207 208 function add_title_override( $nav_menu ) { 209 add_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 210 211 return $nav_menu; 212 } 213 214 function settings_html( $settings ) { 215 216 if ( ! $this->no_page_id() ) { 217 $available_templates = $this->available_templates(); 218 if ( is_array( $available_templates ) && ! empty( $available_templates ) ) { 219 $current_template = $this->get_true_listing_template(); 220 $settings['template'] = $current_template; 221 implecode_settings_dropdown( __( 'Template', 'ecommerce-product-catalog' ), 'archive_multiple_settings[shortcode_mode][template]', $settings['template'], array_merge( array( '0' => __( 'Default Template', 'ecommerce-product-catalog' ) ), $this->available_templates() ), 1, null, __( 'Choose one of the available page templates to display catalog pages.', 'ecommerce-product-catalog' ) ); 222 } 223 } 224 } 225 226 function main_catalog_page_warning() { 227 if ( $this->no_page_id() ) { 228 $available_templates = $this->available_templates(); 229 if ( is_array( $available_templates ) && ! empty( $available_templates ) ) { 230 echo '<br>'; 231 implecode_warning( __( "Select an existing page or create new to have an option to choose different page template.", 'ecommerce-product-catalog' ) ); 232 } 233 } 234 } 235 236 function force_product_header( $force ) { 237 if ( ! empty( $this->settings['force_name'] ) ) { 238 $force = true; 239 } 240 241 return $force; 242 } 243 244 function force_category_header( $force ) { 245 if ( ! empty( $this->settings['force_category_name'] ) ) { 246 $force = true; 247 } 248 249 return $force; 250 } 251 252 function set_after_header() { 253 $this->after_header = 1; 254 } 255 256 function set_loop_started() { 257 $this->loop_started = 1; 258 } 259 260 function disable_comments( $open, $page_id ) { 261 $listing_id = get_product_listing_id(); 262 if ( $page_id === $listing_id ) { 263 return false; 264 } 265 266 return $open; 267 } 268 269 function next_previous_post_link( $link ) { 270 if ( is_ic_product_listing() || is_ic_taxonomy_page() || is_ic_product_search() ) { 271 return ''; 272 } 273 274 return $link; 275 } 276 277 function auto_add_shortcode( $content ) { 278 if ( is_ic_product_listing() && ! $this->has_listing_shortcode() ) { 279 if ( ! $this->is_page_builder_edit() ) { 280 $content .= do_shortcode( '[show_product_catalog]' ); 281 } 282 } 283 284 return $content; 285 } 286 287 function clear_known( $content ) { 288 if ( empty( $this->settings['show_everywhere'] ) ) { 289 $content = ''; 290 } 291 292 if ( empty( $content ) ) { 293 return $content; 294 } 295 add_filter( 'strip_shortcodes_tagnames', array( $this, 'known_shortcodes' ) ); 296 $content = strip_shortcodes( $content ); 297 remove_filter( 'strip_shortcodes_tagnames', array( $this, 'known_shortcodes' ) ); 298 299 $content = $this->strip_blocks( $content ); 300 301 return $content; 302 } 303 304 function known_shortcodes() { 305 return array( 'show_products', 'show_categories' ); 306 } 307 308 function strip_blocks( $content ) { 309 if ( empty( $content ) ) { 310 return $content; 311 } 312 $block_start = '<!-- wp:'; 313 $block_end = '/-->'; 314 $known_blocks = $this->known_blocks(); 315 foreach ( $known_blocks as $block_name ) { 316 $start = strpos( $content, $block_start . $block_name ); 317 if ( $start !== false ) { 318 $end = strpos( $content, $block_end, $start ); 319 if ( $end !== false ) { 320 $strip = substr( $content, $start, $end + strlen( $block_end ) - $start ); 321 $content = trim( str_replace( $strip, '', $content ) ); 322 } 323 } 324 } 325 326 return $content; 327 } 328 329 function known_blocks() { 330 if ( function_exists( 'register_block_type' ) ) { 331 return array( 'ic-epc/show-products', 'ic-epc/show-categories' ); 332 } 333 334 return array(); 335 } 336 337 function forced_meta() { 338 if ( empty( $this->settings['show_everywhere'] ) ) { 339 return array(); 340 } else { 341 return array( 342 'et_', 343 '_avia', 344 '_builder', 345 'cs_' 346 ); 347 } 348 } 349 350 function included_meta() { 351 return array( 352 '_wp_page_template', 353 ); 354 } 355 356 function included_meta_contains() { 357 return array( 358 'sidebar', 359 'layout', 360 ); 361 } 362 363 function is_forced_meta( $meta_key ) { 364 $forced_meta = $this->forced_meta(); 365 if ( in_array( $meta_key, $forced_meta ) ) { 366 return true; 367 } else { 368 foreach ( $forced_meta as $part ) { 369 if ( ic_string_contains( $meta_key, $part ) ) { 370 return true; 371 } 372 } 373 } 374 375 return false; 376 } 377 378 function is_included_meta( $meta_key ) { 379 if ( $this->is_forced_meta( $meta_key ) || in_array( $meta_key, $this->included_meta() ) ) { 380 return true; 381 } else { 382 $excluded_parts = $this->included_meta_contains(); 383 foreach ( $excluded_parts as $part ) { 384 if ( ic_string_contains( $meta_key, $part ) ) { 385 return true; 386 } 387 } 388 } 389 390 return false; 391 } 392 393 function listing_metadata( $value, $object_id, $meta_key, $single ) { 394 if ( empty( $meta_key ) ) { 395 return $value; 396 } 397 $listing_id = get_product_listing_id(); 398 if ( ! is_ic_admin() && $this->is_included_meta( $meta_key ) && ! $this->no_page_id() && ( is_ic_product( $object_id ) || is_ic_product_category( $object_id ) ) ) { 399 remove_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 400 $listing_meta = get_post_meta( $listing_id, $meta_key, $single ); 401 if ( ! empty( $listing_meta ) ) { 402 $custom_keys = get_post_custom_keys( $object_id ); 403 if ( is_array( $custom_keys ) && in_array( $meta_key, $custom_keys ) ) { 404 $this_meta = get_post_meta( $object_id, $meta_key, $single ); 405 if ( empty( $this_meta ) && $this->is_forced_meta( $meta_key ) ) { 406 unset( $this_meta ); 407 } 408 } 409 if ( ! isset( $this_meta ) ) { 410 if ( $single && is_array( $listing_meta ) ) { 411 $listing_meta = array( $listing_meta ); 412 } 413 $value = $listing_meta; 414 } 415 } else if ( $meta_key === '_wp_page_template' ) { 416 $catalog_template = $this->get_template(); 417 if ( ! empty( $catalog_template ) ) { 418 return $catalog_template; 419 } 420 } 421 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 422 } else if ( $object_id == $listing_id && $meta_key === '_wp_page_template' ) { 423 $catalog_template = $this->get_template(); 424 if ( ! empty( $catalog_template ) || is_numeric( $catalog_template ) ) { 425 return $catalog_template; 426 } 427 } else if ( $meta_key === '_thumbnail_id' && empty( $this->settings['show_everywhere'] ) && $object_id == $listing_id && ! is_ic_product_listing() ) { 428 $value = ''; 429 } 430 431 return $value; 432 } 433 434 function get_template() { 435 $current_template = $this->get_true_listing_template(); 436 $this->settings['template'] = $current_template; 437 438 return apply_filters( 'ic_catalog_shortcode_mode_template', $this->settings['template'] ); 439 } 440 441 function get_true_listing_template() { 442 if ( $this->no_page_id() ) { 443 return 0; 444 } 445 $listing_id = get_product_listing_id(); 446 remove_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 447 $current_template = get_post_meta( $listing_id, '_wp_page_template', true ); 448 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 449 450 return $current_template; 451 } 452 453 function available_templates() { 454 $theme = wp_get_theme(); 455 if ( $theme->exists() ) { 456 $available_templates = $theme->get_page_templates( null, 'page' ); 457 } else { 458 $available_templates = array(); 459 } 460 461 return $available_templates; 462 } 463 464 function update_template( $new_settings ) { 465 if ( isset( $new_settings['shortcode_mode']['template'] ) ) { 466 $available_templates = $this->available_templates(); 467 if ( $new_settings['shortcode_mode']['template'] === '0' || isset( $available_templates[ $new_settings['shortcode_mode']['template'] ] ) ) { 468 $listing_id = get_product_listing_id(); 469 if ( ! empty( $listing_id ) ) { 470 if ( empty( $new_settings['shortcode_mode']['template'] ) && ! is_numeric( $new_settings['shortcode_mode']['template'] ) ) { 471 delete_post_meta( $listing_id, '_wp_page_template' ); 472 } else { 473 update_post_meta( $listing_id, '_wp_page_template', $new_settings['shortcode_mode']['template'] ); 474 } 475 } 476 } 477 } 478 479 return $new_settings; 480 } 481 482 function theme_specific() { 483 if ( function_exists( 'genesis_load_framework' ) || function_exists( 'awada_customizer_config' ) ) { 484 remove_filter( 'post_class', array( $this, 'catalog_query' ), 999 ); 485 } 486 487 //Customizr 488 add_action( '__before_content', array( $this, 'overwrite_query' ), 99, 0 ); 489 490 //theme.co 491 add_action( 'x_get_view', array( $this, 'overwrite_query' ) ); 492 493 //Astra 494 add_filter( 'astra_dynamic_theme_css', array( $this, 'overwrite_query' ), - 99 ); 495 add_filter( 'astra_dynamic_theme_css', array( $this, 'catalog_query' ), 99 ); 496 497 add_filter( 'astra_breadcrumb_trail_args', array( $this, 'remove_title_override' ) ); 498 add_filter( 'astra_breadcrumb_trail_args', array( $this, 'catalog_query' ), 99 ); 499 add_filter( 'astra_breadcrumb_trail', array( $this, 'add_title_override' ), 99 ); 500 //add_filter( 'astra_get_post_id', 'ic_get_product_id', 99 ); 501 //DIVI 502 if ( function_exists( 'et_setup_theme' ) ) { 503 add_action( 'wp', array( $this, 'overwrite_query' ), 998 ); // for the dynamic CSS to work correctly 504 add_action( 'wp', array( $this, 'overwrite_query' ), 1 ); // for the custom header template to work 505 } 506 } 507 508 function fix_title( $title, $id = null ) { 509 if ( is_ic_taxonomy_page() || is_ic_product_page() ) { 510 if ( ! empty( $this->title ) && ( empty( $id ) || $id == get_product_listing_id() ) ) { 511 $title = $this->title; 511 512 //$title = ''; 512 }513 }514 515 //remove_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 );516 return $title;517 }518 519 function widget_switch_before() {520 if ( ! is_filter_bar() && ! $this->is_inside_shortcode() ) {521 $this->catalog_query();522 }523 }524 525 function widget_switch_after() {526 if ( ! is_filter_bar() && ! $this->is_inside_shortcode() ) {527 $this->overwrite_query();528 }529 }530 531 function loop_start( &$wp_query ) {532 if ( empty( $this->after_header ) ) {533 return $wp_query;534 }535 if ( $this->is_main_query( $wp_query ) ) {536 $this->set_loop_started();537 add_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 );538 remove_action( 'loop_start', array( $this, 'loop_start' ), 10, 1 );539 $this->widget_switch_before();540 $this->breadcrumbs();541 } else if ( empty( $this->settings['show_everywhere'] ) && is_ic_product_listing( $wp_query ) && is_ic_product_page() ) {542 $pre_wp_query = $this->get_pre_shortcode_query();543 foreach ( $wp_query as $name => $val ) {544 if ( isset( $pre_wp_query->$name ) ) {545 $wp_query->$name = $pre_wp_query->$name;546 }547 }548 }549 550 return $wp_query;551 }552 553 function breadcrumbs() {554 if ( ! empty( $this->settings['move_breadcrumbs'] ) ) {555 remove_action( 'single_product_begin', 'add_product_breadcrumbs' );556 remove_action( 'product_listing_begin', 'add_product_breadcrumbs' );557 add_product_breadcrumbs();558 }559 }560 561 function loop_end( &$wp_query ) {562 if ( empty( $this->after_header ) ) {563 return $wp_query;564 }565 if ( $this->is_main_query( $wp_query ) ) {566 $this->set_loop_started();567 }568 569 return $wp_query;570 }571 572 function is_main_query( $query = null ) {573 if ( empty( $query ) ) {574 global $wp_query;575 $query = $wp_query;576 }577 $pre_query = $this->get_pre_shortcode_query();578 if ( $pre_query && $pre_query === $query ) {579 return true;580 } else if ( ! $pre_query && $query->is_main_query() ) {581 return true;582 } else if ( ! empty( $query->ic_main_page_query ) ) {583 return true;584 } else if ( ic_get_global( 'ic_shortcode_new_query' ) === $query ) {585 return true;586 }587 588 return false;589 }590 591 function shortcode_init() {592 ic_save_global( 'inside_show_catalog_shortcode', 1 );593 $this->multiple_settings = get_multiple_settings();594 if ( ! is_ic_catalog_page() ) {595 return;596 }597 $this->reset_the_content();598 remove_action( 'loop_no_results', array( $this, 'no_results_show_catalog' ) );599 remove_filter( 'the_title', array( $this, 'title' ), 99, 2 );600 601 remove_filter( 'the_content', array( $this, 'set_content' ), 99999999 );602 remove_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99 );603 remove_filter( 'the_content', array( $this, 'catalog_query' ), - 999 );604 remove_filter( 'the_content', array( $this, 'overwrite_query' ), 999 );605 remove_all_filters( 'loop_start' );606 remove_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 );607 add_action( 'before_shortcode_catalog', array( $this, 'setup_postdata' ) );608 add_action( 'before_shortcode_catalog', array( $this, 'setup_loop' ) );609 add_action( 'after_shortcode_catalog', array( $this, 'end_query' ) );513 } 514 } 515 516 //remove_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 517 return $title; 518 } 519 520 function widget_switch_before() { 521 if ( ! is_filter_bar() && ! $this->is_inside_shortcode() ) { 522 $this->catalog_query(); 523 } 524 } 525 526 function widget_switch_after() { 527 if ( ! is_filter_bar() && ! $this->is_inside_shortcode() ) { 528 $this->overwrite_query(); 529 } 530 } 531 532 function loop_start( &$wp_query ) { 533 if ( empty( $this->after_header ) ) { 534 return $wp_query; 535 } 536 if ( $this->is_main_query( $wp_query ) ) { 537 $this->set_loop_started(); 538 add_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 539 remove_action( 'loop_start', array( $this, 'loop_start' ), 10, 1 ); 540 $this->widget_switch_before(); 541 $this->breadcrumbs(); 542 } else if ( empty( $this->settings['show_everywhere'] ) && is_ic_product_listing( $wp_query ) && is_ic_product_page() ) { 543 $pre_wp_query = $this->get_pre_shortcode_query(); 544 foreach ( $wp_query as $name => $val ) { 545 if ( isset( $pre_wp_query->$name ) ) { 546 $wp_query->$name = $pre_wp_query->$name; 547 } 548 } 549 } 550 551 return $wp_query; 552 } 553 554 function breadcrumbs() { 555 if ( ! empty( $this->settings['move_breadcrumbs'] ) ) { 556 remove_action( 'single_product_begin', 'add_product_breadcrumbs' ); 557 remove_action( 'product_listing_begin', 'add_product_breadcrumbs' ); 558 add_product_breadcrumbs(); 559 } 560 } 561 562 function loop_end( &$wp_query ) { 563 if ( empty( $this->after_header ) ) { 564 return $wp_query; 565 } 566 if ( $this->is_main_query( $wp_query ) ) { 567 $this->set_loop_started(); 568 } 569 570 return $wp_query; 571 } 572 573 function is_main_query( $query = null ) { 574 if ( empty( $query ) ) { 575 global $wp_query; 576 $query = $wp_query; 577 } 578 $pre_query = $this->get_pre_shortcode_query(); 579 if ( $pre_query && $pre_query === $query ) { 580 return true; 581 } else if ( ! $pre_query && $query->is_main_query() ) { 582 return true; 583 } else if ( ! empty( $query->ic_main_page_query ) ) { 584 return true; 585 } else if ( ic_get_global( 'ic_shortcode_new_query' ) === $query ) { 586 return true; 587 } 588 589 return false; 590 } 591 592 function shortcode_init() { 593 ic_save_global( 'inside_show_catalog_shortcode', 1 ); 594 $this->multiple_settings = get_multiple_settings(); 595 if ( ! is_ic_catalog_page() ) { 596 return; 597 } 598 $this->reset_the_content(); 599 remove_action( 'loop_no_results', array( $this, 'no_results_show_catalog' ) ); 600 remove_filter( 'the_title', array( $this, 'title' ), 99, 2 ); 601 602 remove_filter( 'the_content', array( $this, 'set_content' ), 99999999 ); 603 remove_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99 ); 604 remove_filter( 'the_content', array( $this, 'catalog_query' ), - 999 ); 605 remove_filter( 'the_content', array( $this, 'overwrite_query' ), 999 ); 606 remove_all_filters( 'loop_start' ); 607 remove_filter( 'the_title', array( $this, 'fix_title' ), 10, 2 ); 608 add_action( 'before_shortcode_catalog', array( $this, 'setup_postdata' ) ); 609 add_action( 'before_shortcode_catalog', array( $this, 'setup_loop' ) ); 610 add_action( 'after_shortcode_catalog', array( $this, 'end_query' ) ); 610 611 //add_action( 'the_content', array( $this, 'end_query' ) ); 611 612 612 add_action( 'product_page_inside', 'content_product_adder_single_content' );613 614 remove_filter( 'post_class', array( $this, 'catalog_query' ), - 2 );615 remove_filter( 'post_class', array( $this, 'overwrite_query' ), - 2 );616 remove_filter( 'post_class', array( $this, 'check_post_class' ), 99 );617 remove_filter( 'post_class', array( $this, 'overwrite_query' ), 999 );618 remove_filter( 'post_class', array( $this, 'catalog_query' ), 999 );619 620 remove_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );621 622 $this->catalog_query( '', true );623 624 ic_enqueue_main_catalog_js_css();625 do_action( 'shortcode_catalog_init' );626 if ( ! is_ic_product_listing() || $this->no_page_id() ) {627 rewind_posts();628 }629 }630 631 function catalog_shortcode() {632 if ( $this->is_inside_shortcode() ) {633 return;634 }635 $cache_meta = 'ic_catalog_shortcode_output';636 $content = ic_get_global( $cache_meta );637 638 if ( $content === false ) {639 $this->shortcode_init();640 ob_start();641 do_action( 'before_shortcode_catalog' );642 $this->shortcode_product_adder();643 do_action( 'after_shortcode_catalog' );644 $content = ob_get_clean();645 ic_save_global( 'inside_show_catalog_shortcode', 0 );646 ic_save_global( $cache_meta, $content );647 }648 649 return $content;650 }651 652 function show_catalog_shortcode() {653 echo $this->catalog_shortcode();654 }655 656 function no_results_show_catalog( $query ) {657 if ( $this->is_main_query( $query ) ) {658 $this->show_catalog_shortcode();659 }660 }661 662 function is_inside_shortcode() {663 $test = ic_get_global( 'inside_show_catalog_shortcode' );664 if ( ! empty( $test ) ) {665 return true;666 }667 668 return false;669 }670 671 function advanced_integration_type() {672 return 'advanced';673 }674 675 function is_page_builder_edit() {676 if ( ! empty( $_POST['is_fb_preview'] ) || ! empty( $_GET['et_fb'] ) ) {677 // DIVI PAGE BUILDER DETECTED678 return true;679 }680 if ( ! empty( $_GET['elementor-preview'] ) || ( ! empty( $_GET['action'] ) && $_GET['action'] === 'elementor' ) ) {681 // ELEMENTOR PAGE BUILDER DETECTED682 683 return true;684 }685 if ( ! empty( $_GET['ct_builder'] ) ) {686 // OXYGEN PAGE BUILDER DETECTED687 return true;688 }689 690 if ( class_exists( 'Elementor\Plugin' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) {691 // ELEMENTOR PAGE BUILDER DETECTED692 693 return true;694 }695 696 return false;697 }698 699 function default_message() {700 if ( ! current_user_can( 'manage_product_settings' ) || ic_is_rendering_catalog_block() ) {701 return;702 }703 $page_url = product_listing_url();704 $listing_id = get_product_listing_id();705 $page_id = get_the_ID();706 $post_type = get_post_type();707 if ( $this->is_page_builder_edit() ) {708 return;709 }710 if ( $listing_id == $page_id || ic_string_contains( $post_type, 'al_product' ) ) {711 return;712 }713 echo "<style>.ic_spinner{background: url(" . admin_url() . "/images/spinner.gif) no-repeat;display:none;width:20px;height:20px;margin-left:2px;vertical-align:middle;</style>";714 if ( ! empty( $page_url ) ) {715 $message = '<p style="margin-bottom: 5px;font-weight: normal;">' . sprintf( __( 'Currently %sanother page%s is set to show main product listing. Would you like to show product listing here instead?', 'ecommerce-product-catalog' ), '<a href="' . $page_url . '">', '</a>' ) . '</p>';716 } else {717 $message = '<p style="margin-bottom: 5px;font-weight: normal;">' . __( 'Currently, no page is set to show the main product listing. Would you like to show product listing here?', 'ecommerce-product-catalog' ) . '</p>';718 }719 if ( ! empty( $message ) && ! empty( $page_id ) ) {720 ic_enqueue_main_catalog_js_css();721 $message .= '<p style="margin-bottom: 5px;">' . __( 'All your individual product pages will include this page slug as a parent.', 'ecommerce-product-catalog' ) . '</p>';722 $message .= '<button style="margin-bottom: 5px;" type="button" class="button assign-listing-button ' . design_schemes( 'box', 0 ) . '">' . __( 'Yes', 'ecommerce-product-catalog' ) . '</button><div class="ic_spinner"></div>';613 add_action( 'product_page_inside', 'content_product_adder_single_content' ); 614 615 remove_filter( 'post_class', array( $this, 'catalog_query' ), - 2 ); 616 remove_filter( 'post_class', array( $this, 'overwrite_query' ), - 2 ); 617 remove_filter( 'post_class', array( $this, 'check_post_class' ), 99 ); 618 remove_filter( 'post_class', array( $this, 'overwrite_query' ), 999 ); 619 remove_filter( 'post_class', array( $this, 'catalog_query' ), 999 ); 620 621 remove_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 622 623 $this->catalog_query( '', true ); 624 625 ic_enqueue_main_catalog_js_css(); 626 do_action( 'shortcode_catalog_init' ); 627 if ( ! is_ic_product_listing() || $this->no_page_id() ) { 628 rewind_posts(); 629 } 630 } 631 632 function catalog_shortcode() { 633 if ( $this->is_inside_shortcode() ) { 634 return; 635 } 636 $cache_meta = 'ic_catalog_shortcode_output'; 637 $content = ic_get_global( $cache_meta ); 638 639 if ( $content === false ) { 640 $this->shortcode_init(); 641 ob_start(); 642 do_action( 'before_shortcode_catalog' ); 643 $this->shortcode_product_adder(); 644 do_action( 'after_shortcode_catalog' ); 645 $content = ob_get_clean(); 646 ic_save_global( 'inside_show_catalog_shortcode', 0 ); 647 ic_save_global( $cache_meta, $content ); 648 } 649 650 return $content; 651 } 652 653 function show_catalog_shortcode() { 654 echo $this->catalog_shortcode(); 655 } 656 657 function no_results_show_catalog( $query ) { 658 if ( $this->is_main_query( $query ) ) { 659 $this->show_catalog_shortcode(); 660 } 661 } 662 663 function is_inside_shortcode() { 664 $test = ic_get_global( 'inside_show_catalog_shortcode' ); 665 if ( ! empty( $test ) ) { 666 return true; 667 } 668 669 return false; 670 } 671 672 function advanced_integration_type() { 673 return 'advanced'; 674 } 675 676 function is_page_builder_edit() { 677 if ( ! empty( $_POST['is_fb_preview'] ) || ! empty( $_GET['et_fb'] ) ) { 678 // DIVI PAGE BUILDER DETECTED 679 return true; 680 } 681 if ( ! empty( $_GET['elementor-preview'] ) || ( ! empty( $_GET['action'] ) && $_GET['action'] === 'elementor' ) ) { 682 // ELEMENTOR PAGE BUILDER DETECTED 683 684 return true; 685 } 686 if ( ! empty( $_GET['ct_builder'] ) ) { 687 // OXYGEN PAGE BUILDER DETECTED 688 return true; 689 } 690 691 if ( class_exists( 'Elementor\Plugin' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { 692 // ELEMENTOR PAGE BUILDER DETECTED 693 694 return true; 695 } 696 697 return false; 698 } 699 700 function default_message() { 701 if ( ! current_user_can( 'manage_product_settings' ) || ic_is_rendering_catalog_block() ) { 702 return; 703 } 704 $page_url = product_listing_url(); 705 $listing_id = get_product_listing_id(); 706 $page_id = get_the_ID(); 707 $post_type = get_post_type(); 708 if ( $this->is_page_builder_edit() ) { 709 return; 710 } 711 if ( $listing_id == $page_id || ic_string_contains( $post_type, 'al_product' ) ) { 712 return; 713 } 714 echo "<style>.ic_spinner{background: url(" . admin_url() . "/images/spinner.gif) no-repeat;display:none;width:20px;height:20px;margin-left:2px;vertical-align:middle;</style>"; 715 if ( ! empty( $page_url ) ) { 716 $message = '<p style="margin-bottom: 5px;font-weight: normal;">' . sprintf( __( 'Currently %sanother page%s is set to show main product listing. Would you like to show product listing here instead?', 'ecommerce-product-catalog' ), '<a href="' . $page_url . '">', '</a>' ) . '</p>'; 717 } else { 718 $message = '<p style="margin-bottom: 5px;font-weight: normal;">' . __( 'Currently, no page is set to show the main product listing. Would you like to show product listing here?', 'ecommerce-product-catalog' ) . '</p>'; 719 } 720 if ( ! empty( $message ) && ! empty( $page_id ) ) { 721 ic_enqueue_main_catalog_js_css(); 722 $message .= '<p style="margin-bottom: 5px;">' . __( 'All your individual product pages will include this page slug as a parent.', 'ecommerce-product-catalog' ) . '</p>'; 723 $message .= '<button style="margin-bottom: 5px;" type="button" class="button assign-listing-button ' . design_schemes( 'box', 0 ) . '">' . __( 'Yes', 'ecommerce-product-catalog' ) . '</button><div class="ic_spinner"></div>'; 723 724 //$message .= '<p style="font-size: 0.8em">* ' . sprintf( __( 'Please remove the %s shortcode to disable this info.', 'ecommerce-product-catalog' ), '[show_product_catalog]' ) . '</p>'; 724 $message .= '<p style="font-size: 0.8em">* ' . sprintf( __( 'Use the %s or %s shortcode if you just want to display products or categories.', 'ecommerce-product-catalog' ), '<code>[[[show_products]]]</code>', '<code>[[[show_categories]]]</code>' ) . '</p>';725 implecode_info( $message );726 echo "<script>jQuery('.assign-listing-button').click(function() {" . $this->assing_listing_script( $page_id ) . "});</script>";727 }728 }729 730 function assing_listing_script( $page_id ) {731 return "var data = {725 $message .= '<p style="font-size: 0.8em">* ' . sprintf( __( 'Use the %s or %s shortcode if you just want to display products or categories.', 'ecommerce-product-catalog' ), '<code>[[[show_products]]]</code>', '<code>[[[show_categories]]]</code>' ) . '</p>'; 726 implecode_info( $message ); 727 echo "<script>jQuery('.assign-listing-button').click(function() {" . $this->assing_listing_script( $page_id ) . "});</script>"; 728 } 729 } 730 731 function assing_listing_script( $page_id ) { 732 return "var data = { 732 733 'action': 'ic_assign_listing', 733 734 'page_id': '" . $page_id . "', … … 738 739 window.location.reload(false); 739 740 });"; 740 }741 742 function assign_listing() {743 if ( ! empty( $_POST['page_id'] ) ) {744 $page_id = intval( $_POST['page_id'] );745 if ( ! empty( $page_id ) && is_ic_shortcode_integration( $page_id ) ) {746 update_option( 'product_archive_page_id', $page_id );747 update_option( 'product_archive', $page_id );748 permalink_options_update();749 }750 }751 wp_die();752 }753 754 function shortcode_product_adder() {755 $query = $this->get_pre_shortcode_query();756 if ( is_ic_product_listing_enabled() && empty( $query ) ) {757 $listing_id = intval( get_product_listing_id() );758 $id = 'product_listing';759 if ( ! empty( $listing_id ) && $this->multiple_settings['product_listing_cats'] !== 'forced_cats_only' ) {760 global $wp_query, $paged;761 if ( empty( $paged ) ) {762 $page = 1;763 } else {764 $page = $paged;765 }766 $wp_query = $query = new WP_Query( array( 'page_id' => $listing_id, 'paged' => $page ) );767 }768 $this->default_message();769 }770 $listing_status = ic_get_product_listing_status();771 if ( empty( $id ) ) {772 if ( is_archive() || is_search() || is_home_archive() || is_ic_product_listing( $query ) || is_ic_taxonomy_page( $query ) || is_ic_product_search( $query ) ) {773 if ( ! is_ic_product_listing( $query ) || ( is_ic_product_listing( $query ) && ( $listing_status === 'publish' || current_user_can( 'edit_private_products' ) ) ) ) {774 $id = 'product_listing';775 }776 } else if ( is_ic_product_page() ) {777 $id = 'product_page';778 }779 }780 if ( empty( $id ) ) {781 if ( is_admin() ) {782 echo '<br>';783 }784 785 return;786 }787 $class_exists = ic_get_global( 'ic_post_class_exists' );788 if ( is_ic_admin() ) {789 $class_exists = true;790 }791 if ( $class_exists === false ) {792 ?>741 } 742 743 function assign_listing() { 744 if ( ! empty( $_POST['page_id'] ) ) { 745 $page_id = intval( $_POST['page_id'] ); 746 if ( ! empty( $page_id ) && is_ic_shortcode_integration( $page_id ) ) { 747 update_option( 'product_archive_page_id', $page_id ); 748 update_option( 'product_archive', $page_id ); 749 permalink_options_update(); 750 } 751 } 752 wp_die(); 753 } 754 755 function shortcode_product_adder() { 756 $query = $this->get_pre_shortcode_query(); 757 if ( is_ic_product_listing_enabled() && empty( $query ) ) { 758 $listing_id = intval( get_product_listing_id() ); 759 $id = 'product_listing'; 760 if ( ! empty( $listing_id ) && $this->multiple_settings['product_listing_cats'] !== 'forced_cats_only' ) { 761 global $wp_query, $paged; 762 if ( empty( $paged ) ) { 763 $page = 1; 764 } else { 765 $page = $paged; 766 } 767 $wp_query = $query = new WP_Query( array( 'page_id' => $listing_id, 'paged' => $page ) ); 768 } 769 $this->default_message(); 770 } 771 $listing_status = ic_get_product_listing_status(); 772 if ( empty( $id ) ) { 773 if ( is_archive() || is_search() || is_home_archive() || is_ic_product_listing( $query ) || is_ic_taxonomy_page( $query ) || is_ic_product_search( $query ) ) { 774 if ( ! is_ic_product_listing( $query ) || ( is_ic_product_listing( $query ) && ( $listing_status === 'publish' || current_user_can( 'edit_private_products' ) ) ) ) { 775 $id = 'product_listing'; 776 } 777 } else if ( is_ic_product_page() ) { 778 $id = 'product_page'; 779 } 780 } 781 if ( empty( $id ) ) { 782 if ( is_admin() ) { 783 echo '<br>'; 784 } 785 786 return; 787 } 788 $class_exists = ic_get_global( 'ic_post_class_exists' ); 789 if ( is_ic_admin() ) { 790 $class_exists = true; 791 } 792 if ( $class_exists === false ) { 793 ?> 793 794 <div id="<?php echo $id ?>" <?php post_class() ?>> 794 <?php795 }796 //echo '<div class="ic-catalog-container alignwide">';797 echo '<div class="ic-catalog-container">';798 if ( $id === 'product_listing' ) {799 $this->product_listing();800 } else {801 $this->product_page();802 }803 echo '</div>';804 805 if ( $class_exists === false ) {806 ?>795 <?php 796 } 797 //echo '<div class="ic-catalog-container alignwide">'; 798 echo '<div class="ic-catalog-container">'; 799 if ( $id === 'product_listing' ) { 800 $this->product_listing(); 801 } else { 802 $this->product_page(); 803 } 804 echo '</div>'; 805 806 if ( $class_exists === false ) { 807 ?> 807 808 </div> 808 <?php809 }810 }811 812 function product_page() {813 do_action( 'before_product_page' );814 $path = $this->get_custom_product_page_path();815 if ( file_exists( $path ) ) {816 ob_start();817 include apply_filters( 'content_product_adder_path', $path );818 $product_page = ob_get_clean();819 echo do_shortcode( $product_page );820 } else {821 include apply_filters( 'content_product_adder_path', AL_BASE_TEMPLATES_PATH . '/templates/full/shortcode-product-page.php' );822 }823 do_action( 'after_product_page' );824 }825 826 function get_custom_product_page_path() {827 $folder = get_custom_templates_folder();828 829 return $folder . 'shortcode-product-page.php';830 }831 832 function product_listing() {833 if ( ! empty( $this->shortcode_listing_generated ) ) {834 return;835 }836 if ( empty( $this->multiple_settings ) ) {837 $this->multiple_settings = get_multiple_settings();838 }839 $archive_template = get_product_listing_template();840 do_action( 'product_listing_begin', $this->multiple_settings );841 do_action( 'before_product_archive' );842 do_action( 'before_product_listing_entry' );843 844 do_action( 'product_listing_entry_inside', $archive_template, $this->multiple_settings );845 846 do_action( 'product_listing_end', $archive_template, $this->multiple_settings );847 do_action( 'after_product_archive' );848 $this->shortcode_listing_generated = 1;849 }850 851 function catalog_query_force( $return = null ) {852 return $this->catalog_query( $return, true );853 }854 855 function catalog_query( $return = null, $force = false ) {856 if ( is_ic_shortcode_integration() && ( $this->status == 'page' || $force ) && is_ic_catalog_page() ) {857 $pre_query = $this->get_pre_shortcode_query();858 $check_query = null;859 if ( $pre_query !== false ) {860 $check_query = $pre_query;861 }862 if ( is_ic_product_listing( $check_query ) && ! $this->no_page_id() ) {863 return $return;864 }865 866 $this->status = 'catalog';867 global $wp_query, $wp_the_query, $post;868 $pre_post = $this->get_pre_shortcode_post();869 if ( empty( $pre_query ) || empty( $pre_post ) ) {870 return;871 }872 $wp_query = $pre_query;809 <?php 810 } 811 } 812 813 function product_page() { 814 do_action( 'before_product_page' ); 815 $path = $this->get_custom_product_page_path(); 816 if ( file_exists( $path ) ) { 817 ob_start(); 818 include apply_filters( 'content_product_adder_path', $path ); 819 $product_page = ob_get_clean(); 820 echo do_shortcode( $product_page ); 821 } else { 822 include apply_filters( 'content_product_adder_path', AL_BASE_TEMPLATES_PATH . '/templates/full/shortcode-product-page.php' ); 823 } 824 do_action( 'after_product_page' ); 825 } 826 827 function get_custom_product_page_path() { 828 $folder = get_custom_templates_folder(); 829 830 return $folder . 'shortcode-product-page.php'; 831 } 832 833 function product_listing() { 834 if ( ! empty( $this->shortcode_listing_generated ) ) { 835 return; 836 } 837 if ( empty( $this->multiple_settings ) ) { 838 $this->multiple_settings = get_multiple_settings(); 839 } 840 $archive_template = get_product_listing_template(); 841 do_action( 'product_listing_begin', $this->multiple_settings ); 842 do_action( 'before_product_archive' ); 843 do_action( 'before_product_listing_entry' ); 844 845 do_action( 'product_listing_entry_inside', $archive_template, $this->multiple_settings ); 846 847 do_action( 'product_listing_end', $archive_template, $this->multiple_settings ); 848 do_action( 'after_product_archive' ); 849 $this->shortcode_listing_generated = 1; 850 } 851 852 function catalog_query_force( $return = null ) { 853 return $this->catalog_query( $return, true ); 854 } 855 856 function catalog_query( $return = null, $force = false ) { 857 if ( is_ic_shortcode_integration() && ( $this->status == 'page' || $force ) && is_ic_catalog_page() ) { 858 $pre_query = $this->get_pre_shortcode_query(); 859 $check_query = null; 860 if ( $pre_query !== false ) { 861 $check_query = $pre_query; 862 } 863 if ( is_ic_product_listing( $check_query ) && ! $this->no_page_id() ) { 864 return $return; 865 } 866 867 $this->status = 'catalog'; 868 global $wp_query, $wp_the_query, $post; 869 $pre_post = $this->get_pre_shortcode_post(); 870 if ( empty( $pre_query ) || empty( $pre_post ) ) { 871 return; 872 } 873 $wp_query = $pre_query; 873 874 // if ( !$this->ended_query() ) { 874 $wp_the_query = $pre_query;875 $wp_the_query = $pre_query; 875 876 // } 876 877 877 if ( ( is_ic_product_page() || is_ic_taxonomy_page() ) && ( ( ! is_ic_taxonomy_page() && empty( $this->settings['show_everywhere'] ) ) || $force || $this->is_inside_shortcode() ) ) { // added show everywhere check to keep Elementor HTML output878 $post = $pre_post;879 }880 881 if ( empty( $wp_query->posts ) && is_ic_only_main_cats() ) {882 $listing_id = intval( get_product_listing_id() );883 if ( ! empty( $listing_id ) ) {884 $post = $this->listing_post();885 $wp_query->posts = array();886 $wp_query->posts[0] = $post;887 }888 $wp_query->post_count = 1;889 add_action( 'shortcode_catalog_init', array( $this, 'clear_posts' ) );890 }891 if ( is_ic_product_page() ) {892 $wp_query->is_page = true;893 }894 895 /*896 $wp_query->is_page = true;897 898 if ( !isset( $wp_query->queried_object->ID ) && $this->no_page_id() && !is_ic_taxonomy_page() ) {899 $args = $this->empty_post_args();900 foreach ( $args as $key => $value ) {901 if ( !isset( $wp_query->queried_object->$key ) ) {902 $wp_query->queried_object->$key = $value;903 }904 }905 $wp_query->queried_object->ancestors = array();906 }907 *908 */909 do_action( 'ic_catalog_shortcode_catalog_query' );910 }911 912 return $return;913 }914 915 function fake_tax_first_post( $return = null ) {916 if ( ! is_ic_shortcode_integration() || ( is_ic_product_listing() && ! $this->no_page_id() ) ) {917 return $return;918 }919 global $wp_query;920 if ( ! empty( $wp_query->queried_object->name ) || is_ic_taxonomy_page( $wp_query ) ) {878 if ( ( is_ic_product_page() || is_ic_taxonomy_page() ) && ( ( ! is_ic_taxonomy_page() && empty( $this->settings['show_everywhere'] ) ) || $force || $this->is_inside_shortcode() ) ) { // added show everywhere check to keep Elementor HTML output 879 $post = $pre_post; 880 } 881 882 if ( empty( $wp_query->posts ) && is_ic_only_main_cats() ) { 883 $listing_id = intval( get_product_listing_id() ); 884 if ( ! empty( $listing_id ) ) { 885 $post = $this->listing_post(); 886 $wp_query->posts = array(); 887 $wp_query->posts[0] = $post; 888 } 889 $wp_query->post_count = 1; 890 add_action( 'shortcode_catalog_init', array( $this, 'clear_posts' ) ); 891 } 892 if ( is_ic_product_page() ) { 893 $wp_query->is_page = true; 894 } 895 896 /* 897 $wp_query->is_page = true; 898 899 if ( !isset( $wp_query->queried_object->ID ) && $this->no_page_id() && !is_ic_taxonomy_page() ) { 900 $args = $this->empty_post_args(); 901 foreach ( $args as $key => $value ) { 902 if ( !isset( $wp_query->queried_object->$key ) ) { 903 $wp_query->queried_object->$key = $value; 904 } 905 } 906 $wp_query->queried_object->ancestors = array(); 907 } 908 * 909 */ 910 do_action( 'ic_catalog_shortcode_catalog_query' ); 911 } 912 913 return $return; 914 } 915 916 function fake_tax_first_post( $return = null ) { 917 if ( ! is_ic_shortcode_integration() || ( is_ic_product_listing() && ! $this->no_page_id() ) ) { 918 return $return; 919 } 920 global $wp_query; 921 if ( ! empty( $wp_query->queried_object->name ) || is_ic_taxonomy_page( $wp_query ) ) { 921 922 //add_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 ); 922 923 //add_filter( 'the_title', array( $this, 'title' ), 99, 2 ); 923 }924 925 return $return;926 }927 928 function fake_listing_first_post( $return = null ) {929 if ( ! is_ic_shortcode_integration() || ( is_ic_product_listing() && ! $this->no_page_id() ) ) {930 return $return;931 }932 global $wp_query;933 $listing_id = get_product_listing_id();934 if ( ( ! empty( $wp_query->queried_object->ID ) && $wp_query->queried_object->ID == $listing_id ) || is_ic_product_listing( $wp_query ) ) {935 add_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 );936 }937 938 return $return;939 }940 941 function fake_post_title( $title, $id = null ) {942 if ( ! empty( $id ) ) {943 global $wp_query;944 $post = get_post();945 $listing_id = get_product_listing_id();946 if ( is_ic_product_listing( $wp_query ) ) {947 remove_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 );948 $title = get_product_listing_title();949 } else if ( ( $post->ID == $id && $listing_id != $id ) || is_ic_taxonomy_page( $wp_query ) ) {924 } 925 926 return $return; 927 } 928 929 function fake_listing_first_post( $return = null ) { 930 if ( ! is_ic_shortcode_integration() || ( is_ic_product_listing() && ! $this->no_page_id() ) ) { 931 return $return; 932 } 933 global $wp_query; 934 $listing_id = get_product_listing_id(); 935 if ( ( ! empty( $wp_query->queried_object->ID ) && $wp_query->queried_object->ID == $listing_id ) || is_ic_product_listing( $wp_query ) ) { 936 add_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 ); 937 } 938 939 return $return; 940 } 941 942 function fake_post_title( $title, $id = null ) { 943 if ( ! empty( $id ) ) { 944 global $wp_query; 945 $post = get_post(); 946 $listing_id = get_product_listing_id(); 947 if ( is_ic_product_listing( $wp_query ) ) { 948 remove_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 ); 949 $title = get_product_listing_title(); 950 } else if ( ( $post->ID == $id && $listing_id != $id ) || is_ic_taxonomy_page( $wp_query ) ) { 950 951 //remove_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 ); 951 if ( ! empty( $wp_query->queried_object->name ) ) {952 $title = get_product_tax_title( $wp_query->queried_object->name );953 }954 }955 }956 957 return $title;958 }959 960 function product_page_title( $title ) {961 if ( is_ic_product_page() ) {962 return get_product_name();963 } else if ( is_ic_taxonomy_page() ) {964 $this->catalog_query();965 966 return get_product_tax_title( $title );967 }968 969 return $title;970 }971 972 function title( $title, $id = null ) {973 $listing_id = get_product_listing_id();974 if ( ! is_admin() && is_ic_catalog_page() && ! is_ic_product_page() && ! in_the_ic_loop() && ! is_filter_bar() && ( empty( $id ) || ( get_quasi_post_type( get_post_type( $id ) ) == 'al_product' ) ) || $listing_id == $id ) {975 if ( is_ic_product_page() ) {976 return get_product_name();977 } else if ( is_ic_taxonomy_page() && ( empty( $id ) || ! is_ic_product( $id ) ) ) {978 $this->catalog_query();979 980 return get_product_tax_title( $title );981 }982 }983 984 return $title;985 }986 987 function remove_overwrite_filters( $content = null ) {988 remove_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 );989 990 return $content;991 }992 993 function clear_posts() {994 if ( is_ic_only_main_cats() ) {995 global $wp_query;996 if ( $wp_query->post_count == 1 ) {997 $wp_query->post_count = 0;998 $wp_query->posts = array();999 }1000 }1001 }1002 1003 function end_query() {1004 if ( ( is_ic_product_listing() && ! $this->no_page_id() ) || ! is_ic_catalog_page() ) {1005 return;1006 }952 if ( ! empty( $wp_query->queried_object->name ) ) { 953 $title = get_product_tax_title( $wp_query->queried_object->name ); 954 } 955 } 956 } 957 958 return $title; 959 } 960 961 function product_page_title( $title ) { 962 if ( is_ic_product_page() ) { 963 return get_product_name(); 964 } else if ( is_ic_taxonomy_page() ) { 965 $this->catalog_query(); 966 967 return get_product_tax_title( $title ); 968 } 969 970 return $title; 971 } 972 973 function title( $title, $id = null ) { 974 $listing_id = get_product_listing_id(); 975 if ( ! is_admin() && is_ic_catalog_page() && ! is_ic_product_page() && ! in_the_ic_loop() && ! is_filter_bar() && ( empty( $id ) || ( get_quasi_post_type( get_post_type( $id ) ) == 'al_product' ) ) || $listing_id == $id ) { 976 if ( is_ic_product_page() ) { 977 return get_product_name(); 978 } else if ( is_ic_taxonomy_page() && ( empty( $id ) || ! is_ic_product( $id ) ) ) { 979 $this->catalog_query(); 980 981 return get_product_tax_title( $title ); 982 } 983 } 984 985 return $title; 986 } 987 988 function remove_overwrite_filters( $content = null ) { 989 remove_filter( 'the_title', array( $this, 'fake_post_title' ), 10, 2 ); 990 991 return $content; 992 } 993 994 function clear_posts() { 995 if ( is_ic_only_main_cats() ) { 996 global $wp_query; 997 if ( $wp_query->post_count == 1 ) { 998 $wp_query->post_count = 0; 999 $wp_query->posts = array(); 1000 } 1001 } 1002 } 1003 1004 function end_query() { 1005 if ( ( is_ic_product_listing() && ! $this->no_page_id() ) || ! is_ic_catalog_page() ) { 1006 return; 1007 } 1007 1008 //add_filter( 'the_content', array( $this, 'clear' ) ); 1008 global $wp_query, $wp_the_query, $ic_catalog_shortcode_query_ended;1009 if ( is_ic_taxonomy_page() || is_ic_product_search() ) {1010 $wp_query = $this->main_listing_query();1011 $wp_the_query = $wp_query;1012 }1013 1014 if ( ! empty( $wp_query->post ) ) {1015 global $post;1016 $post = $wp_query->post;1017 }1018 1019 if ( ! empty( $wp_query->post_count ) ) {1020 $wp_query->post_count = 0;1021 }1022 if ( ! empty( $wp_query->found_posts ) ) {1023 $wp_query->found_posts = 0;1024 }1025 $wp_query->posts = array();1026 if ( is_ic_product_listing() && $this->no_page_id() ) {1027 $wp_query->is_archive = false;1028 }1029 $this->status = 'page';1030 1031 ic_save_global( 'in_the_loop', 0 );1032 remove_filter( 'the_content', array( $this, 'set_content' ), 99999999 );1033 remove_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99 );1034 remove_filter( 'the_content', array( $this, 'catalog_query' ), - 999 );1035 remove_filter( 'the_content', array( $this, 'overwrite_query' ), 999 );1036 remove_filter( 'the_content', array( $this, 'the_content_filter' ), - 999 );1037 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 );1038 //remove_all_actions( 'the_content', 10 );1039 //remove_all_filters( 'the_content', 10 );1040 $ic_catalog_shortcode_query_ended = 1;1041 }1042 1043 function ended_query() {1044 global $ic_catalog_shortcode_query_ended;1045 if ( ! empty( $ic_catalog_shortcode_query_ended ) ) {1046 return true;1047 }1048 1049 return false;1050 }1051 1052 function main_listing_query() {1053 $listing_query = ic_get_global( 'ic_main_listing_query' );1054 if ( $listing_query ) {1055 return $listing_query;1056 }1057 $args = array( 'pagename' => $this->get_listing_slug() );1058 $listing_query = new WP_Query( $args );1059 ic_save_global( 'ic_main_listing_query', $listing_query );1060 1061 return $listing_query;1062 }1063 1064 function break_query() {1065 global $wp_query;1066 if ( ! empty( $this->after_header ) && ! empty( $this->loop_started ) && ! empty( $wp_query->query['pagename'] ) ) {1067 $wp_query->current_post = 0;1068 remove_action( 'get_template_part', array( $this, 'overwrite_query' ), 99, 0 );1069 }1070 }1071 1072 function overwrite_query( $return = null ) {1073 if ( $this->status == 'catalog' && is_ic_shortcode_integration() && is_ic_catalog_page() && ( ! is_ic_product_listing() || $this->no_page_id() ) ) {1074 $this->set_post_type();1075 $this->status = 'page';1076 $this->get_pre_shortcode_query();1077 $this->get_pre_shortcode_post();1078 $this->page_query();1079 if ( isset( $return->post ) ) {1080 global $wp_query;1081 $return = $wp_query;1082 }1083 }1084 1085 return $return;1086 }1087 1088 function set_post_type() {1089 add_filter( 'current_product_post_type', array( $this, 'post_type' ) );1090 $current_post_type = get_post_type();1091 if ( is_ic_catalog_post_type( $current_post_type ) && empty( $this->post_type ) ) {1092 $this->post_type = $current_post_type;1093 }1094 }1095 1096 function post_type( $post_type = null ) {1097 if ( ! empty( $this->post_type ) ) {1098 $post_type = $this->post_type;1099 }1100 1101 return $post_type;1102 }1103 1104 function get_pre_shortcode_query() {1105 if ( is_ic_catalog_page() && is_ic_shortcode_integration() ) {1106 $pre_query = ic_get_global( 'pre_shortcode_query' );1107 if ( $pre_query === false ) {1108 do_action( 'shortcode_catalog_query_first_save', $GLOBALS['wp_query'] );1109 ic_save_global( 'pre_shortcode_query', $GLOBALS['wp_query'] );1110 ic_set_catalog_query();1111 1112 return $GLOBALS['wp_query'];1113 }1114 1115 return $pre_query;1116 }1117 1118 return false;1119 }1120 1121 function main_listing_content() {1122 $listing_id = intval( get_product_listing_id() );1123 if ( ! empty( $listing_id ) ) {1124 $post = $this->listing_post();1125 if ( isset( $post->post_content ) ) {1126 return $post->post_content;1127 }1128 }1129 1130 return '';1131 }1132 1133 function has_listing_shortcode() {1134 return ic_has_listing_shortcode();1135 }1136 1137 function get_pre_shortcode_post() {1138 if ( is_ic_catalog_page() && is_ic_shortcode_integration() ) {1139 $pre_post = ic_get_global( 'pre_shortcode_post' );1140 if ( ! $pre_post ) {1141 if ( ( is_ic_taxonomy_page() || is_ic_product_page() ) && isset( $GLOBALS['post']->post_content ) ) {1142 $content = $this->main_listing_content();1143 if ( ! empty( $content ) ) {1144 //$listing_id = intval( get_product_listing_id() );1145 //if ( !empty( $listing_id ) && ic_has_page_catalog_shortcode( get_post( $listing_id ) ) ) {1146 $GLOBALS['post']->post_content = $content;1147 //}1148 }1149 }1150 do_action( 'shortcode_catalog_post_first_save', $GLOBALS['post'] );1151 ic_save_global( 'pre_shortcode_post', $GLOBALS['post'] );1152 1153 return $GLOBALS['post'];1154 }1155 1156 return $pre_post;1157 }1158 1159 return false;1160 }1161 1162 function listing_post() {1163 $listing_id = get_product_listing_id();1164 if ( $this->no_page_id() ) {1165 $listing_post = $this->empty_post();1166 } else {1167 $listing_post = get_post( $listing_id );1168 }1169 $pre_post = $this->get_pre_shortcode_query();1170 if ( ! is_ic_product_listing( $pre_post ) || $this->no_page_id() ) {1171 $listing_post->post_content = $this->clear_known( $listing_post->post_content );1172 if ( ! ic_has_page_catalog_shortcode( $listing_post ) ) {1173 $listing_post->post_content .= ic_catalog_shortcode();1174 }1175 }1176 1177 return $listing_post;1178 }1179 1180 function no_page_id() {1181 $listing_id = intval( get_product_listing_id() );1182 if ( empty( $listing_id ) ) {1183 return true;1184 }1185 $listing_post = get_post( $listing_id );1186 if ( empty( $listing_post ) ) {1187 return true;1188 }1189 1190 return false;1191 }1192 1193 function empty_post_args() {1194 $single_names = get_catalog_names();1195 $args = array(1196 'ID' => 0,1197 'post_status' => 'publish',1198 'post_author' => '',1199 'post_parent' => 0,1200 'post_type' => 'page',1201 'post_date' => '',1202 'post_date_gmt' => '',1203 'post_modified' => '',1204 'post_modified_gmt' => '',1205 'post_content' => '',1206 'post_title' => $single_names['plural'],1207 'post_excerpt' => '',1208 'post_content_filtered' => '',1209 'post_mime_type' => '',1210 'post_password' => '',1211 'post_name' => sanitize_title( $single_names['plural'] ),1212 'guid' => '',1213 'menu_order' => 0,1214 'pinged' => '',1215 'to_ping' => '',1216 'ping_status' => '',1217 'comment_status' => 'closed',1218 'comment_count' => 0,1219 'filter' => 'raw',1220 );1221 1222 return $args;1223 }1224 1225 function empty_post() {1226 $args = $this->empty_post_args();1227 $post = new WP_Post( (object) $args );1228 1229 return $post;1230 }1231 1232 function page_query( $return = null ) {1233 if ( ! is_admin() && is_ic_catalog_page() && is_ic_shortcode_integration() ) {1234 global $wp_query, $wp_the_query, $post;1235 $listing_slug = $this->get_listing_slug();1236 if ( ! empty( $wp_query->query['pagename'] ) && $wp_query->query['pagename'] === $listing_slug ) {1237 return $return;1238 }1239 $new_query = ic_get_global( 'ic_shortcode_new_query' );1240 $new_post = ic_get_global( 'ic_shortcode_new_post' );1241 if ( $new_query && $new_post ) {1242 $wp_query = $new_query;1243 $wp_the_query = $wp_query;1244 $post = $new_post;1245 setup_postdata( $post );1246 1247 return $return;1248 }1009 global $wp_query, $wp_the_query, $ic_catalog_shortcode_query_ended; 1010 if ( is_ic_taxonomy_page() || is_ic_product_search() ) { 1011 $wp_query = $this->main_listing_query(); 1012 $wp_the_query = $wp_query; 1013 } 1014 1015 if ( ! empty( $wp_query->post ) ) { 1016 global $post; 1017 $post = $wp_query->post; 1018 } 1019 1020 if ( ! empty( $wp_query->post_count ) ) { 1021 $wp_query->post_count = 0; 1022 } 1023 if ( ! empty( $wp_query->found_posts ) ) { 1024 $wp_query->found_posts = 0; 1025 } 1026 $wp_query->posts = array(); 1027 if ( is_ic_product_listing() && $this->no_page_id() ) { 1028 $wp_query->is_archive = false; 1029 } 1030 $this->status = 'page'; 1031 1032 ic_save_global( 'in_the_loop', 0 ); 1033 remove_filter( 'the_content', array( $this, 'set_content' ), 99999999 ); 1034 remove_filter( 'the_content', array( $this, 'auto_add_shortcode' ), 99 ); 1035 remove_filter( 'the_content', array( $this, 'catalog_query' ), - 999 ); 1036 remove_filter( 'the_content', array( $this, 'overwrite_query' ), 999 ); 1037 remove_filter( 'the_content', array( $this, 'the_content_filter' ), - 999 ); 1038 add_filter( 'get_post_metadata', array( $this, 'listing_metadata' ), 10, 4 ); 1039 //remove_all_actions( 'the_content', 10 ); 1040 //remove_all_filters( 'the_content', 10 ); 1041 $ic_catalog_shortcode_query_ended = 1; 1042 } 1043 1044 function ended_query() { 1045 global $ic_catalog_shortcode_query_ended; 1046 if ( ! empty( $ic_catalog_shortcode_query_ended ) ) { 1047 return true; 1048 } 1049 1050 return false; 1051 } 1052 1053 function main_listing_query() { 1054 $listing_query = ic_get_global( 'ic_main_listing_query' ); 1055 if ( $listing_query ) { 1056 return $listing_query; 1057 } 1058 $args = array( 'pagename' => $this->get_listing_slug() ); 1059 $listing_query = new WP_Query( $args ); 1060 ic_save_global( 'ic_main_listing_query', $listing_query ); 1061 1062 return $listing_query; 1063 } 1064 1065 function break_query() { 1066 global $wp_query; 1067 if ( ! empty( $this->after_header ) && ! empty( $this->loop_started ) && ! empty( $wp_query->query['pagename'] ) ) { 1068 $wp_query->current_post = 0; 1069 remove_action( 'get_template_part', array( $this, 'overwrite_query' ), 99, 0 ); 1070 } 1071 } 1072 1073 function overwrite_query( $return = null ) { 1074 if ( $this->status == 'catalog' && is_ic_shortcode_integration() && is_ic_catalog_page() && ( ! is_ic_product_listing() || $this->no_page_id() ) ) { 1075 $this->set_post_type(); 1076 $this->status = 'page'; 1077 $this->get_pre_shortcode_query(); 1078 $this->get_pre_shortcode_post(); 1079 $this->page_query(); 1080 if ( isset( $return->post ) ) { 1081 global $wp_query; 1082 $return = $wp_query; 1083 } 1084 } 1085 1086 return $return; 1087 } 1088 1089 function set_post_type() { 1090 add_filter( 'current_product_post_type', array( $this, 'post_type' ) ); 1091 $current_post_type = get_post_type(); 1092 if ( is_ic_catalog_post_type( $current_post_type ) && empty( $this->post_type ) ) { 1093 $this->post_type = $current_post_type; 1094 } 1095 } 1096 1097 function post_type( $post_type = null ) { 1098 if ( ! empty( $this->post_type ) ) { 1099 $post_type = $this->post_type; 1100 } 1101 1102 return $post_type; 1103 } 1104 1105 function get_pre_shortcode_query() { 1106 if ( is_ic_catalog_page() && is_ic_shortcode_integration() ) { 1107 $pre_query = ic_get_global( 'pre_shortcode_query' ); 1108 if ( $pre_query === false ) { 1109 do_action( 'shortcode_catalog_query_first_save', $GLOBALS['wp_query'] ); 1110 ic_save_global( 'pre_shortcode_query', $GLOBALS['wp_query'] ); 1111 ic_set_catalog_query(); 1112 1113 return $GLOBALS['wp_query']; 1114 } 1115 1116 return $pre_query; 1117 } 1118 1119 return false; 1120 } 1121 1122 function main_listing_content() { 1123 $listing_id = intval( get_product_listing_id() ); 1124 if ( ! empty( $listing_id ) ) { 1125 $post = $this->listing_post(); 1126 if ( isset( $post->post_content ) ) { 1127 return $post->post_content; 1128 } 1129 } 1130 1131 return ''; 1132 } 1133 1134 function has_listing_shortcode() { 1135 return ic_has_listing_shortcode(); 1136 } 1137 1138 function get_pre_shortcode_post() { 1139 if ( is_ic_catalog_page() && is_ic_shortcode_integration() ) { 1140 $pre_post = ic_get_global( 'pre_shortcode_post' ); 1141 if ( ! $pre_post ) { 1142 if ( ( is_ic_taxonomy_page() || is_ic_product_page() ) && isset( $GLOBALS['post']->post_content ) ) { 1143 $content = $this->main_listing_content(); 1144 if ( ! empty( $content ) ) { 1145 //$listing_id = intval( get_product_listing_id() ); 1146 //if ( !empty( $listing_id ) && ic_has_page_catalog_shortcode( get_post( $listing_id ) ) ) { 1147 $GLOBALS['post']->post_content = $content; 1148 //} 1149 } 1150 } 1151 do_action( 'shortcode_catalog_post_first_save', $GLOBALS['post'] ); 1152 ic_save_global( 'pre_shortcode_post', $GLOBALS['post'] ); 1153 1154 return $GLOBALS['post']; 1155 } 1156 1157 return $pre_post; 1158 } 1159 1160 return false; 1161 } 1162 1163 function listing_post() { 1164 $listing_id = get_product_listing_id(); 1165 if ( $this->no_page_id() ) { 1166 $listing_post = $this->empty_post(); 1167 } else { 1168 $listing_post = get_post( $listing_id ); 1169 } 1170 $pre_post = $this->get_pre_shortcode_query(); 1171 if ( ! is_ic_product_listing( $pre_post ) || $this->no_page_id() ) { 1172 $listing_post->post_content = $this->clear_known( $listing_post->post_content ); 1173 if ( ! ic_has_page_catalog_shortcode( $listing_post ) ) { 1174 $listing_post->post_content .= ic_catalog_shortcode(); 1175 } 1176 } 1177 1178 return $listing_post; 1179 } 1180 1181 function no_page_id() { 1182 $listing_id = intval( get_product_listing_id() ); 1183 if ( empty( $listing_id ) ) { 1184 return true; 1185 } 1186 $listing_post = get_post( $listing_id ); 1187 if ( empty( $listing_post ) ) { 1188 return true; 1189 } 1190 1191 return false; 1192 } 1193 1194 function empty_post_args() { 1195 $single_names = get_catalog_names(); 1196 $args = array( 1197 'ID' => 0, 1198 'post_status' => 'publish', 1199 'post_author' => '', 1200 'post_parent' => 0, 1201 'post_type' => 'page', 1202 'post_date' => '', 1203 'post_date_gmt' => '', 1204 'post_modified' => '', 1205 'post_modified_gmt' => '', 1206 'post_content' => '', 1207 'post_title' => $single_names['plural'], 1208 'post_excerpt' => '', 1209 'post_content_filtered' => '', 1210 'post_mime_type' => '', 1211 'post_password' => '', 1212 'post_name' => sanitize_title( $single_names['plural'] ), 1213 'guid' => '', 1214 'menu_order' => 0, 1215 'pinged' => '', 1216 'to_ping' => '', 1217 'ping_status' => '', 1218 'comment_status' => 'closed', 1219 'comment_count' => 0, 1220 'filter' => 'raw', 1221 ); 1222 1223 return $args; 1224 } 1225 1226 function empty_post() { 1227 $args = $this->empty_post_args(); 1228 $post = new WP_Post( (object) $args ); 1229 1230 return $post; 1231 } 1232 1233 function page_query( $return = null ) { 1234 if ( ! is_admin() && is_ic_catalog_page() && is_ic_shortcode_integration() ) { 1235 global $wp_query, $wp_the_query, $post; 1236 $listing_slug = $this->get_listing_slug(); 1237 if ( ! empty( $wp_query->query['pagename'] ) && $wp_query->query['pagename'] === $listing_slug ) { 1238 return $return; 1239 } 1240 $new_query = ic_get_global( 'ic_shortcode_new_query' ); 1241 $new_post = ic_get_global( 'ic_shortcode_new_post' ); 1242 if ( $new_query && $new_post ) { 1243 $wp_query = $new_query; 1244 $wp_the_query = $wp_query; 1245 $post = $new_post; 1246 setup_postdata( $post ); 1247 1248 return $return; 1249 } 1249 1250 1250 1251 //query_posts( $args ); 1251 $wp_query = $this->main_listing_query();1252 $listing_post = $this->listing_post();1253 $post = $listing_post;1252 $wp_query = $this->main_listing_query(); 1253 $listing_post = $this->listing_post(); 1254 $post = $listing_post; 1254 1255 1255 1256 //if ( !ic_has_page_catalog_shortcode( $post ) ) { 1256 1257 //$post->post_content .= apply_filters( 'ic_catalog_default_listing_content', '[show_product_catalog]' ); 1257 1258 //} 1258 $pre_post = $this->get_pre_shortcode_query();1259 $pre_post = $this->get_pre_shortcode_query(); 1259 1260 //generate_postdata( $listing_post ); 1260 $wp_query->post = $post;1261 $wp_query->queried_object = $post;1262 $wp_query->posts = array( 0 => $post );1261 $wp_query->post = $post; 1262 $wp_query->queried_object = $post; 1263 $wp_query->posts = array( 0 => $post ); 1263 1264 //if ( empty( $wp_query->post_count ) ) { 1264 $wp_query->post_count = 1;1265 $wp_query->post_count = 1; 1265 1266 //} 1266 1267 //if ( empty( $wp_query->found_posts ) ) { 1267 $wp_query->found_posts = 1;1268 $wp_query->found_posts = 1; 1268 1269 //$wp_query->current_post = 0; 1269 1270 //$wp_query->in_the_loop = true; 1270 1271 //} 1271 if ( is_ic_product_search( $pre_post ) ) {1272 $search_title = ic_get_search_page_title();1273 $this->title = $search_title;1274 } else if ( ! empty( $pre_post->queried_object->labels->name ) ) {1275 $this->title = $pre_post->queried_object->labels->name;1276 } else if ( is_ic_product_listing( $pre_post ) ) {1277 $this->title = $listing_post->post_title;1272 if ( is_ic_product_search( $pre_post ) ) { 1273 $search_title = ic_get_search_page_title(); 1274 $this->title = $search_title; 1275 } else if ( ! empty( $pre_post->queried_object->labels->name ) ) { 1276 $this->title = $pre_post->queried_object->labels->name; 1277 } else if ( is_ic_product_listing( $pre_post ) ) { 1278 $this->title = $listing_post->post_title; 1278 1279 //$wp_query->post->post_title = $listing_post->post_title; 1279 1280 //$wp_query->posts[ 0 ]->post_title = $listing_post->post_title; 1280 } else if ( ! empty( $pre_post->queried_object->name ) ) {1281 $tax_title = get_product_tax_title( $pre_post->queried_object->name );1282 $this->title = $tax_title;1283 $post->post_status = 'publish';1284 } else if ( ! empty( $pre_post->post->post_title ) ) {1285 $this->title = $pre_post->post->post_title;1286 $post->post_status = $pre_post->post->post_status;1287 }1288 if ( ! empty( $this->title ) ) {1289 $post->post_title = $this->title;1290 $wp_query->post->post_title = $this->title;1291 $wp_query->posts[0]->post_title = $this->title;1292 }1293 global $wp_version;1294 if ( version_compare( $wp_version, 6.1, '>=' ) ) {1295 $wp_query->ic_main_page_query = 1;1296 }1297 $wp_the_query = $wp_query;1298 ic_save_global( 'ic_shortcode_new_query', $wp_query );1299 ic_save_global( 'ic_shortcode_new_post', $post );1300 add_filter( 'the_content', array( $this, 'set_content' ), 99999999 );1301 setup_postdata( $post );1302 }1303 1304 return $return;1305 }1306 1307 function set_content( $content ) {1308 if ( empty( $this->loop_started ) ) {1309 return $content;1310 }1311 $listing_id = intval( get_product_listing_id() );1312 global $wp_query;1313 if ( empty( $listing_id ) || ( ! empty( $wp_query->queried_object->ID ) && $wp_query->queried_object->ID == $listing_id ) || is_ic_product_page() ) {1314 if ( is_ic_catalog_page() ) {1315 if ( ! $this->has_listing_shortcode() ) {1316 $content = do_shortcode( '[show_product_catalog]' );1317 }1318 }1319 1320 return $content;1321 }1322 $page = $this->listing_post();1323 $readd = false;1324 if ( has_filter( 'the_content', array( $this, 'set_content' ) ) ) {1325 remove_filter( 'the_content', array( $this, 'set_content' ), 99999999 );1326 $readd = true;1327 }1328 if ( ! ic_has_page_catalog_shortcode( $page ) ) {1329 if ( ! $this->has_listing_shortcode() ) {1330 $page->post_content = '';1331 } else {1332 $page->post_content = $this->clear_known( $page->post_content );1333 }1334 $page->post_content .= ic_catalog_shortcode();1335 }1281 } else if ( ! empty( $pre_post->queried_object->name ) ) { 1282 $tax_title = get_product_tax_title( $pre_post->queried_object->name ); 1283 $this->title = $tax_title; 1284 $post->post_status = 'publish'; 1285 } else if ( ! empty( $pre_post->post->post_title ) ) { 1286 $this->title = $pre_post->post->post_title; 1287 $post->post_status = $pre_post->post->post_status; 1288 } 1289 if ( ! empty( $this->title ) ) { 1290 $post->post_title = $this->title; 1291 $wp_query->post->post_title = $this->title; 1292 $wp_query->posts[0]->post_title = $this->title; 1293 } 1294 global $wp_version; 1295 if ( version_compare( $wp_version, 6.1, '>=' ) ) { 1296 $wp_query->ic_main_page_query = 1; 1297 } 1298 $wp_the_query = $wp_query; 1299 ic_save_global( 'ic_shortcode_new_query', $wp_query ); 1300 ic_save_global( 'ic_shortcode_new_post', $post ); 1301 add_filter( 'the_content', array( $this, 'set_content' ), 99999999 ); 1302 setup_postdata( $post ); 1303 } 1304 1305 return $return; 1306 } 1307 1308 function set_content( $content ) { 1309 if ( empty( $this->loop_started ) ) { 1310 return $content; 1311 } 1312 $listing_id = intval( get_product_listing_id() ); 1313 global $wp_query; 1314 if ( empty( $listing_id ) || ( ! empty( $wp_query->queried_object->ID ) && $wp_query->queried_object->ID == $listing_id ) || is_ic_product_page() ) { 1315 if ( is_ic_catalog_page() ) { 1316 if ( ! $this->has_listing_shortcode() ) { 1317 $content = do_shortcode( '[show_product_catalog]' ); 1318 } 1319 } 1320 1321 return $content; 1322 } 1323 $page = $this->listing_post(); 1324 $readd = false; 1325 if ( has_filter( 'the_content', array( $this, 'set_content' ) ) ) { 1326 remove_filter( 'the_content', array( $this, 'set_content' ), 99999999 ); 1327 $readd = true; 1328 } 1329 if ( ! ic_has_page_catalog_shortcode( $page ) ) { 1330 if ( ! $this->has_listing_shortcode() ) { 1331 $page->post_content = ''; 1332 } else { 1333 $page->post_content = $this->clear_known( $page->post_content ); 1334 } 1335 $page->post_content .= ic_catalog_shortcode(); 1336 } 1336 1337 //$content = apply_filters( 'the_content', $page->post_content ); 1337 1338 1338 if ( function_exists( 'do_blocks' ) ) {1339 add_filter( 'ic_catalog_shortcode_default_content', 'do_blocks' );1340 }1341 add_filter( 'ic_catalog_shortcode_default_content', 'wptexturize' );1342 add_filter( 'ic_catalog_shortcode_default_content', 'convert_smilies', 20 );1343 add_filter( 'ic_catalog_shortcode_default_content', 'wpautop' );1344 add_filter( 'ic_catalog_shortcode_default_content', 'shortcode_unautop' );1345 add_filter( 'ic_catalog_shortcode_default_content', 'prepend_attachment' );1346 if ( function_exists( 'wp_make_content_images_responsive' ) ) {1347 add_filter( 'ic_catalog_shortcode_default_content', 'wp_make_content_images_responsive' );1348 }1349 add_filter( 'ic_catalog_shortcode_default_content', 'do_shortcode', 11 );1350 $content = apply_filters( 'ic_catalog_shortcode_default_content', $page->post_content );1339 if ( function_exists( 'do_blocks' ) ) { 1340 add_filter( 'ic_catalog_shortcode_default_content', 'do_blocks' ); 1341 } 1342 add_filter( 'ic_catalog_shortcode_default_content', 'wptexturize' ); 1343 add_filter( 'ic_catalog_shortcode_default_content', 'convert_smilies', 20 ); 1344 add_filter( 'ic_catalog_shortcode_default_content', 'wpautop' ); 1345 add_filter( 'ic_catalog_shortcode_default_content', 'shortcode_unautop' ); 1346 add_filter( 'ic_catalog_shortcode_default_content', 'prepend_attachment' ); 1347 if ( function_exists( 'wp_make_content_images_responsive' ) ) { 1348 add_filter( 'ic_catalog_shortcode_default_content', 'wp_make_content_images_responsive' ); 1349 } 1350 add_filter( 'ic_catalog_shortcode_default_content', 'do_shortcode', 11 ); 1351 $content = apply_filters( 'ic_catalog_shortcode_default_content', $page->post_content ); 1351 1352 //$content = do_shortcode( '[show_product_catalog]' ); 1352 if ( ! $this->ended_query() ) { 1353 add_filter( 'the_content', array( $this, 'set_content' ), 99999999 ); 1354 } 1355 1356 return $content; 1357 } 1358 1359 function clear() { 1360 return ''; 1361 } 1362 1363 function get_listing_slug() { 1364 $listing_id = intval( get_product_listing_id() ); 1365 if ( ! empty( $listing_id ) ) { 1366 $post = get_post( $listing_id ); 1367 if ( ! empty( $post->post_name ) ) { 1368 return $post->post_name; 1369 } 1370 } 1371 if ( $this->no_page_id() ) { 1372 return sanitize_title( get_catalog_names( 'plural' ) ); 1373 } else { 1374 return false; 1375 } 1376 } 1377 1378 function setup_postdata() { 1379 global $post, $wp_query; 1380 if ( is_ic_catalog_page() ) { 1381 if ( is_ic_product_listing() && ! $this->no_page_id() ) { 1382 return; 1383 } 1384 if ( isset( $wp_query->queried_object->ID ) ) { 1385 $product_id = $wp_query->queried_object->ID; 1386 ic_set_product_id( $product_id ); 1387 $post = get_post( $product_id ); 1388 1389 if ( empty( $post->post_content ) ) { 1390 $post->post_content = ' '; 1391 } 1392 setup_postdata( $post ); 1393 } 1394 } else if ( ! is_ic_page() ) { 1395 $listing_id = intval( get_product_listing_id() ); 1396 if ( ! empty( $listing_id ) ) { 1397 $post = $this->listing_post(); 1398 $wp_query = $this->main_listing_query(); 1399 } 1400 } 1401 } 1402 1403 function setup_loop() { 1404 ic_save_global( 'in_the_loop', 1 ); 1405 } 1406 1407 function check_post_class( $class ) { 1408 ic_save_global( 'ic_post_class_exists', 1 ); 1409 $class[] = 'page'; 1410 $class[] = 'type-page'; 1411 remove_filter( 'ic_catalog_body_class_start', array( $this, 'overwrite_query' ), 1 ); 1412 remove_filter( 'ic_catalog_single_body_class', array( $this, 'catalog_query' ), 99, 1 ); 1413 remove_filter( 'ic_catalog_tax_body_class', array( $this, 'catalog_query' ), 98, 1 ); 1414 remove_filter( 'ic_catalog_tax_body_class', array( $this, 'tax_body_class' ), 98, 1 ); 1415 remove_filter( 'ic_catalog_single_body_class', array( $this, 'single_body_class' ), 98, 1 ); 1416 1417 return $class; 1418 } 1419 1420 function tax_body_class( $body_class ) { 1421 $key = array_search( 'archive', $body_class ); 1422 if ( $key !== false ) { 1423 unset( $body_class[ $key ] ); 1424 } 1425 1426 return $body_class; 1427 } 1428 1429 function single_body_class( $body_class ) { 1430 $key = array_search( 'single', $body_class ); 1431 if ( $key !== false ) { 1432 unset( $body_class[ $key ] ); 1433 } 1434 1435 return $body_class; 1436 } 1353 if ( ! $this->ended_query() ) { 1354 add_filter( 'the_content', array( $this, 'set_content' ), 99999999 ); 1355 } 1356 1357 return $content; 1358 } 1359 1360 function clear() { 1361 return ''; 1362 } 1363 1364 function get_listing_slug() { 1365 $listing_id = intval( get_product_listing_id() ); 1366 if ( ! empty( $listing_id ) ) { 1367 $post = get_post( $listing_id ); 1368 if ( ! empty( $post->post_name ) ) { 1369 return $post->post_name; 1370 } 1371 } 1372 if ( $this->no_page_id() ) { 1373 return sanitize_title( get_catalog_names( 'plural' ) ); 1374 } else { 1375 return false; 1376 } 1377 } 1378 1379 function setup_postdata() { 1380 global $post, $wp_query; 1381 if ( is_ic_catalog_page() ) { 1382 if ( is_ic_product_listing() && ! $this->no_page_id() ) { 1383 return; 1384 } 1385 if ( isset( $wp_query->queried_object->ID ) ) { 1386 $product_id = $wp_query->queried_object->ID; 1387 ic_set_product_id( $product_id ); 1388 $post = get_post( $product_id ); 1389 1390 if ( empty( $post->post_content ) ) { 1391 $post->post_content = ' '; 1392 } 1393 setup_postdata( $post ); 1394 } 1395 } else if ( ! is_ic_page() ) { 1396 $listing_id = intval( get_product_listing_id() ); 1397 if ( ! empty( $listing_id ) ) { 1398 $post = $this->listing_post(); 1399 $wp_query = $this->main_listing_query(); 1400 } 1401 } 1402 } 1403 1404 function setup_loop() { 1405 ic_save_global( 'in_the_loop', 1 ); 1406 } 1407 1408 function check_post_class( $class ) { 1409 ic_save_global( 'ic_post_class_exists', 1 ); 1410 $class[] = 'page'; 1411 $class[] = 'type-page'; 1412 remove_filter( 'ic_catalog_body_class_start', array( $this, 'overwrite_query' ), 1 ); 1413 remove_filter( 'ic_catalog_single_body_class', array( $this, 'catalog_query' ), 99, 1 ); 1414 remove_filter( 'ic_catalog_tax_body_class', array( $this, 'catalog_query' ), 98, 1 ); 1415 remove_filter( 'ic_catalog_tax_body_class', array( $this, 'tax_body_class' ), 98, 1 ); 1416 remove_filter( 'ic_catalog_single_body_class', array( $this, 'single_body_class' ), 98, 1 ); 1417 1418 return $class; 1419 } 1420 1421 function body_class( $class, $css_class = '' ) { 1422 $this->catalog_query(); 1423 remove_filter( 'body_class', array( $this, 'body_class' ), 1, 2 ); 1424 $class = get_body_class( $css_class ); 1425 add_filter( 'body_class', array( $this, 'body_class' ), 1, 2 ); 1426 $this->overwrite_query(); 1427 1428 return $class; 1429 } 1430 1431 function tax_body_class( $body_class ) { 1432 $key = array_search( 'archive', $body_class ); 1433 if ( $key !== false ) { 1434 unset( $body_class[ $key ] ); 1435 } 1436 1437 return $body_class; 1438 } 1439 1440 function single_body_class( $body_class ) { 1441 $key = array_search( 'single', $body_class ); 1442 if ( $key !== false ) { 1443 unset( $body_class[ $key ] ); 1444 } 1445 1446 return $body_class; 1447 } 1437 1448 1438 1449 } -
ecommerce-product-catalog/trunk/templates/templates-functions.php
r3339587 r3377998 2 2 3 3 if ( ! defined( 'ABSPATH' ) ) { 4 exit; // Exit if accessed directly4 exit; // Exit if accessed directly 5 5 } 6 6 … … 21 21 */ 22 22 function content_product_adder( $is_catalog = null ) { 23 if ( $is_catalog !== 'is_catalog' && ! is_ic_catalog_page() ) {24 return;25 }26 echo '<div class="ic-catalog-container">';27 if ( is_archive() || is_search() || is_home_archive() || is_ic_product_listing() ) {28 do_action( 'before_product_archive' );29 content_product_adder_archive();30 do_action( 'after_product_archive' );31 } else {32 do_action( 'before_product_page' );33 content_product_adder_single();34 do_action( 'after_product_page' );35 }36 echo '</div>';23 if ( $is_catalog !== 'is_catalog' && ! is_ic_catalog_page() ) { 24 return; 25 } 26 echo '<div class="ic-catalog-container">'; 27 if ( is_archive() || is_search() || is_home_archive() || is_ic_product_listing() ) { 28 do_action( 'before_product_archive' ); 29 content_product_adder_archive(); 30 do_action( 'after_product_archive' ); 31 } else { 32 do_action( 'before_product_page' ); 33 content_product_adder_single(); 34 do_action( 'after_product_page' ); 35 } 36 echo '</div>'; 37 37 } 38 38 39 39 function ic_redirect_to_same() { 40 $url = 'http';41 if ( is_ssl() ) {42 $url .= 's';43 }44 $url .= '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];45 wp_redirect( esc_url_raw( $url ) );46 exit;40 $url = 'http'; 41 if ( is_ssl() ) { 42 $url .= 's'; 43 } 44 $url .= '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 45 wp_redirect( esc_url_raw( $url ) ); 46 exit; 47 47 } 48 48 49 49 function content_product_adder_archive() { 50 $path = get_custom_product_listing_path();51 if ( file_exists( $path ) ) {52 ob_start();53 include apply_filters( 'content_product_adder_archive_path', $path );54 $product_listing = ob_get_clean();55 echo do_shortcode( $product_listing );56 } else {57 include apply_filters( 'content_product_adder_archive_path', AL_BASE_TEMPLATES_PATH . '/templates/full/product-listing.php' );58 }50 $path = get_custom_product_listing_path(); 51 if ( file_exists( $path ) ) { 52 ob_start(); 53 include apply_filters( 'content_product_adder_archive_path', $path ); 54 $product_listing = ob_get_clean(); 55 echo do_shortcode( $product_listing ); 56 } else { 57 include apply_filters( 'content_product_adder_archive_path', AL_BASE_TEMPLATES_PATH . '/templates/full/product-listing.php' ); 58 } 59 59 } 60 60 61 61 function content_product_adder_single() { 62 add_action( 'product_page_inside', 'content_product_adder_single_content' );63 $path = get_custom_product_page_path();64 if ( file_exists( $path ) ) {65 ob_start();66 include apply_filters( 'content_product_adder_path', $path );67 $product_page = ob_get_clean();68 echo do_shortcode( $product_page );69 } else {70 include apply_filters( 'content_product_adder_path', AL_BASE_TEMPLATES_PATH . '/templates/full/product-page.php' );71 }62 add_action( 'product_page_inside', 'content_product_adder_single_content' ); 63 $path = get_custom_product_page_path(); 64 if ( file_exists( $path ) ) { 65 ob_start(); 66 include apply_filters( 'content_product_adder_path', $path ); 67 $product_page = ob_get_clean(); 68 echo do_shortcode( $product_page ); 69 } else { 70 include apply_filters( 'content_product_adder_path', AL_BASE_TEMPLATES_PATH . '/templates/full/product-page.php' ); 71 } 72 72 } 73 73 74 74 function content_product_adder_single_content() { 75 $path = get_custom_product_page_inside_path();76 if ( file_exists( $path ) ) {77 ob_start();78 include $path;79 $product_page = ob_get_clean();80 echo do_shortcode( $product_page );81 } else {82 include AL_BASE_TEMPLATES_PATH . '/templates/full/product-page-inside.php';83 }75 $path = get_custom_product_page_inside_path(); 76 if ( file_exists( $path ) ) { 77 ob_start(); 78 include $path; 79 $product_page = ob_get_clean(); 80 echo do_shortcode( $product_page ); 81 } else { 82 include AL_BASE_TEMPLATES_PATH . '/templates/full/product-page-inside.php'; 83 } 84 84 } 85 85 86 86 function content_product_adder_archive_before() { 87 $page_id = apply_filters( 'before_archive_post_id', get_product_listing_id() );88 $page = empty( $page_id ) ? '' : get_post( $page_id );89 if ( $page != '' && ! is_ic_shortcode_integration() ) {90 if ( get_integration_type() != 'simple' ) {91 if ( ic_has_page_catalog_shortcode( $page ) ) {92 $page->post_content = str_replace( array(93 '<!-- wp:ic-epc/show-catalog /-->',94 '[show_product_catalog]'95 ), '', $page->post_content );96 }97 $content = apply_filters( "the_content", $page->post_content );98 } else {99 $content = $page->post_content;100 }101 } else {102 $content = '';103 }104 105 return '<div class="entry-summary">' . $content . '</div>';87 $page_id = apply_filters( 'before_archive_post_id', get_product_listing_id() ); 88 $page = empty( $page_id ) ? '' : get_post( $page_id ); 89 if ( $page != '' && ! is_ic_shortcode_integration() ) { 90 if ( get_integration_type() != 'simple' ) { 91 if ( ic_has_page_catalog_shortcode( $page ) ) { 92 $page->post_content = str_replace( array( 93 '<!-- wp:ic-epc/show-catalog /-->', 94 '[show_product_catalog]' 95 ), '', $page->post_content ); 96 } 97 $content = apply_filters( "the_content", $page->post_content ); 98 } else { 99 $content = $page->post_content; 100 } 101 } else { 102 $content = ''; 103 } 104 105 return '<div class="entry-summary">' . $content . '</div>'; 106 106 } 107 107 108 108 function content_product_adder_archive_before_title() { 109 $def_page_id = get_product_listing_id();110 $archive_names = get_archive_names();111 $page_id = apply_filters( 'before_archive_post_id', $def_page_id );112 $page = empty( $page_id ) ? '' : get_post( $page_id );113 if ( $page == '' ) {114 echo '<h1 class="entry-title">' . $archive_names['all_products'] . '</h1>';115 } else {116 echo '<h1 class="entry-title">' . $page->post_title . '</h1>';117 }109 $def_page_id = get_product_listing_id(); 110 $archive_names = get_archive_names(); 111 $page_id = apply_filters( 'before_archive_post_id', $def_page_id ); 112 $page = empty( $page_id ) ? '' : get_post( $page_id ); 113 if ( $page == '' ) { 114 echo '<h1 class="entry-title">' . $archive_names['all_products'] . '</h1>'; 115 } else { 116 echo '<h1 class="entry-title">' . $page->post_title . '</h1>'; 117 } 118 118 } 119 119 120 120 function show_products_outside_loop( $atts, $content = '' ) { 121 global $shortcode_query, $product_sort, $archive_template, $shortcode_args;122 ic_reset_listing_globals();123 ic_enqueue_main_catalog_js_css();124 ic_save_global( 'in_shortcode', 1, true );125 $available_args = apply_filters( 'show_products_shortcode_args', array(126 'post_type' => 'al_product',127 'category' => '',128 'product' => '',129 'exclude' => '',130 'products_limit' => 100,131 'archive_template' => get_product_listing_template(),132 'design_scheme' => '',133 'sort' => 0,134 'orderby' => '',135 'order' => '',136 'pagination' => 0,137 'page' => '',138 'per_row' => '',139 'empty' => '',140 ) );141 $args = shortcode_atts( $available_args, $atts );142 $shortcode_args = $args;143 $category = esc_html( $args['category'] );144 $product = esc_html( $args['product'] );145 $exclude = esc_html( $args['exclude'] );146 $products_limit = intval( $args['products_limit'] );147 $archive_template = esc_attr( $args['archive_template'] );148 $design_scheme = esc_attr( $args['design_scheme'] );149 $product_sort = intval( $args['sort'] );150 $per_row = intval( $args['per_row'] );151 $args['page'] = intval( $args['page'] );152 if ( ! empty( $per_row ) ) {153 ic_save_global( 'shortcode_per_row', $per_row, true );154 }155 $post_type = empty( $args['post_type'] ) ? 'al_product' : $args['post_type'];156 if ( ! empty( $product ) ) {157 $product_array = explode( ',', $product );158 $query_param = array(159 'post_type' => product_post_type_array(),160 'post__in' => $product_array,161 'posts_per_page' => $products_limit,162 );163 } else if ( ! empty( $category ) ) {164 $category_array = explode( ',', $category );165 $field = 'name';166 if ( is_numeric( $category_array[0] ) ) {167 $field = 'term_id';168 }169 $query_param = array(170 'post_type' => $post_type,171 'tax_query' => array(172 array(173 'taxonomy' => 'al_product-cat',174 'field' => $field,175 'terms' => $category_array,176 ),177 ),178 'posts_per_page' => $products_limit,179 );180 } else {181 $query_param = array(182 'post_type' => $post_type,183 'posts_per_page' => $products_limit,184 );185 if ( ! empty( $exclude ) ) {186 $query_param['post__not_in'] = explode( ',', $exclude );187 }188 }189 if ( $args['orderby'] == 'none' ) {190 $args['orderby'] = 'post__in';191 }192 if ( ! empty( $args['orderby'] ) ) {193 $query_param['orderby'] = esc_attr( $args['orderby'] );194 }195 if ( ! empty( $args['order'] ) ) {196 $query_param['order'] = esc_attr( $args['order'] );197 }198 if ( ! empty( $args['pagination'] ) ) {199 200 if ( get_query_var( 'paged' ) ) {201 $paged = absint( get_query_var( 'paged' ) );202 } elseif ( get_query_var( 'page' ) ) {203 $paged = absint( get_query_var( 'page' ) );204 } else if ( ! empty( $args['page'] ) ) {205 $paged = $args['page'];206 } else {207 $paged = 1;208 }209 $query_param['paged'] = $paged;210 }211 $query_param = apply_filters( 'shortcode_query', $query_param, $args, $post_type, $products_limit );212 remove_all_filters( 'pre_get_posts' );213 $shortcode_query = new WP_Query( $query_param );214 $shortcode_query->query['archive_template'] = $archive_template;215 $i = 0;216 ob_start();217 do_action( 'before_product_list', $archive_template );218 do_action( 'before_shortcode_product_list', $shortcode_query, $args, $archive_template );219 echo do_shortcode( $content );220 $before = ob_get_contents();221 ob_end_clean();222 $products_listed = false;223 $inside = apply_filters( 'pre_show_products_outside_loop_inside', '', $shortcode_query );224 if ( empty( $inside ) ) {225 while ( $shortcode_query->have_posts() ) : $shortcode_query->the_post();226 global $post;227 ic_set_product_id( $post->ID );228 $i ++;229 $inside .= get_catalog_template( $archive_template, $post, $i, $design_scheme );230 ic_reset_product_id();231 endwhile;232 }233 if ( ! empty( $inside ) ) {234 $products_listed = true;235 }236 $pagination = '';237 if ( ! empty( $args['pagination'] ) ) {238 ob_start();239 product_archive_pagination( $shortcode_query );240 $pagination = ob_get_clean();241 }242 if ( ! empty( $args['empty'] ) && ! $products_listed ) {243 $inside .= wp_kses_post( $args['empty'] );244 }245 $inside = apply_filters( 'product_list_ready', $inside, $archive_template, $args );246 wp_reset_postdata();247 if ( ! empty( $inside ) ) {248 $out_class = apply_filters( 'ic_show_products_container_class', 'product-list responsive ' . $archive_template . ' ' . product_list_class( $archive_template ), $args );249 $out = $before . '<div class="' . $out_class . '" ' . product_list_attr( $shortcode_query ) . '>' . $inside . '<div style="clear:both"></div></div>' . $pagination;250 } else {251 $out = '';252 }253 unset( $GLOBALS['shortcode_args'] );254 unset( $GLOBALS['shortcode_query'] );255 unset( $GLOBALS['archive_template'] );256 unset( $GLOBALS['product_sort'] );257 ic_delete_global( 'in_shortcode' );258 //ic_delete_global( 'shortcode_per_row' );259 reset_row_class();260 261 return $out;121 global $shortcode_query, $product_sort, $archive_template, $shortcode_args; 122 ic_reset_listing_globals(); 123 ic_enqueue_main_catalog_js_css(); 124 ic_save_global( 'in_shortcode', 1, true ); 125 $available_args = apply_filters( 'show_products_shortcode_args', array( 126 'post_type' => 'al_product', 127 'category' => '', 128 'product' => '', 129 'exclude' => '', 130 'products_limit' => 100, 131 'archive_template' => get_product_listing_template(), 132 'design_scheme' => '', 133 'sort' => 0, 134 'orderby' => '', 135 'order' => '', 136 'pagination' => 0, 137 'page' => '', 138 'per_row' => '', 139 'empty' => '', 140 ) ); 141 $args = shortcode_atts( $available_args, $atts ); 142 $shortcode_args = $args; 143 $category = esc_html( $args['category'] ); 144 $product = esc_html( $args['product'] ); 145 $exclude = esc_html( $args['exclude'] ); 146 $products_limit = intval( $args['products_limit'] ); 147 $archive_template = esc_attr( $args['archive_template'] ); 148 $design_scheme = esc_attr( $args['design_scheme'] ); 149 $product_sort = intval( $args['sort'] ); 150 $per_row = intval( $args['per_row'] ); 151 $args['page'] = intval( $args['page'] ); 152 if ( ! empty( $per_row ) ) { 153 ic_save_global( 'shortcode_per_row', $per_row, true ); 154 } 155 $post_type = empty( $args['post_type'] ) ? 'al_product' : $args['post_type']; 156 if ( ! empty( $product ) ) { 157 $product_array = explode( ',', $product ); 158 $query_param = array( 159 'post_type' => product_post_type_array(), 160 'post__in' => $product_array, 161 'posts_per_page' => $products_limit, 162 ); 163 } else if ( ! empty( $category ) ) { 164 $category_array = explode( ',', $category ); 165 $field = 'name'; 166 if ( is_numeric( $category_array[0] ) ) { 167 $field = 'term_id'; 168 } 169 $query_param = array( 170 'post_type' => $post_type, 171 'tax_query' => array( 172 array( 173 'taxonomy' => 'al_product-cat', 174 'field' => $field, 175 'terms' => $category_array, 176 ), 177 ), 178 'posts_per_page' => $products_limit, 179 ); 180 } else { 181 $query_param = array( 182 'post_type' => $post_type, 183 'posts_per_page' => $products_limit, 184 ); 185 if ( ! empty( $exclude ) ) { 186 $query_param['post__not_in'] = explode( ',', $exclude ); 187 } 188 } 189 if ( $args['orderby'] == 'none' ) { 190 $args['orderby'] = 'post__in'; 191 } 192 if ( ! empty( $args['orderby'] ) ) { 193 $query_param['orderby'] = esc_attr( $args['orderby'] ); 194 } 195 if ( ! empty( $args['order'] ) ) { 196 $query_param['order'] = esc_attr( $args['order'] ); 197 } 198 if ( ! empty( $args['pagination'] ) ) { 199 200 if ( get_query_var( 'paged' ) ) { 201 $paged = absint( get_query_var( 'paged' ) ); 202 } elseif ( get_query_var( 'page' ) ) { 203 $paged = absint( get_query_var( 'page' ) ); 204 } else if ( ! empty( $args['page'] ) ) { 205 $paged = $args['page']; 206 } else { 207 $paged = 1; 208 } 209 $query_param['paged'] = $paged; 210 } 211 $query_param = apply_filters( 'shortcode_query', $query_param, $args, $post_type, $products_limit ); 212 remove_all_filters( 'pre_get_posts' ); 213 $shortcode_query = new WP_Query( $query_param ); 214 $shortcode_query->query['archive_template'] = $archive_template; 215 $i = 0; 216 ob_start(); 217 do_action( 'before_product_list', $archive_template ); 218 do_action( 'before_shortcode_product_list', $shortcode_query, $args, $archive_template ); 219 echo do_shortcode( $content ); 220 $before = ob_get_contents(); 221 ob_end_clean(); 222 $products_listed = false; 223 $inside = apply_filters( 'pre_show_products_outside_loop_inside', '', $shortcode_query ); 224 if ( empty( $inside ) ) { 225 while ( $shortcode_query->have_posts() ) : $shortcode_query->the_post(); 226 global $post; 227 ic_set_product_id( $post->ID ); 228 $i ++; 229 $inside .= get_catalog_template( $archive_template, $post, $i, $design_scheme ); 230 ic_reset_product_id(); 231 endwhile; 232 } 233 if ( ! empty( $inside ) ) { 234 $products_listed = true; 235 } 236 $pagination = ''; 237 if ( ! empty( $args['pagination'] ) ) { 238 ob_start(); 239 product_archive_pagination( $shortcode_query ); 240 $pagination = ob_get_clean(); 241 } 242 if ( ! empty( $args['empty'] ) && ! $products_listed ) { 243 $inside .= wp_kses_post( $args['empty'] ); 244 } 245 $inside = apply_filters( 'product_list_ready', $inside, $archive_template, $args ); 246 wp_reset_postdata(); 247 if ( ! empty( $inside ) ) { 248 $out_class = apply_filters( 'ic_show_products_container_class', 'product-list responsive ' . $archive_template . ' ' . product_list_class( $archive_template ), $args ); 249 $out = $before . '<div class="' . $out_class . '" ' . product_list_attr( $shortcode_query ) . '>' . $inside . '<div style="clear:both"></div></div>' . $pagination; 250 } else { 251 $out = ''; 252 } 253 unset( $GLOBALS['shortcode_args'] ); 254 unset( $GLOBALS['shortcode_query'] ); 255 unset( $GLOBALS['archive_template'] ); 256 unset( $GLOBALS['product_sort'] ); 257 ic_delete_global( 'in_shortcode' ); 258 //ic_delete_global( 'shortcode_per_row' ); 259 reset_row_class(); 260 261 return $out; 262 262 } 263 263 … … 265 265 266 266 function single_scripts() { 267 if ( is_ic_product_page() && is_lightbox_enabled() ) {268 wp_enqueue_style( 'colorbox' );269 }267 if ( is_ic_product_page() && is_lightbox_enabled() ) { 268 wp_enqueue_style( 'colorbox' ); 269 } 270 270 } 271 271 … … 279 279 */ 280 280 function set_products_limit( $query ) { 281 $archive_multiple_settings = get_multiple_settings();282 //if ( !is_admin() && $query->is_main_query() && (is_ic_product_listing( $query ) || is_ic_taxonomy_page() || is_home_archive( $query ) || is_ic_product_search()) ) {283 $current_per_page = $query->get( 'posts_per_page' );284 if ( $current_per_page !== - 1 && ! isset( $query->query['post__in'] ) && empty( $query->query['suppress_filters'] ) ) {285 $query->set( 'posts_per_page', $archive_multiple_settings['archive_products_limit'] );286 }287 if ( ic_ic_catalog_archive( $query ) ) {288 $query->set( 'post_status', ic_visible_product_status() );289 }290 291 292 //do_action( 'pre_get_al_products', $query );293 //}281 $archive_multiple_settings = get_multiple_settings(); 282 //if ( !is_admin() && $query->is_main_query() && (is_ic_product_listing( $query ) || is_ic_taxonomy_page() || is_home_archive( $query ) || is_ic_product_search()) ) { 283 $current_per_page = $query->get( 'posts_per_page' ); 284 if ( $current_per_page !== - 1 && ! isset( $query->query['post__in'] ) && empty( $query->query['suppress_filters'] ) ) { 285 $query->set( 'posts_per_page', $archive_multiple_settings['archive_products_limit'] ); 286 } 287 if ( ic_ic_catalog_archive( $query ) ) { 288 $query->set( 'post_status', ic_visible_product_status() ); 289 } 290 291 292 //do_action( 'pre_get_al_products', $query ); 293 //} 294 294 } 295 295 … … 297 297 298 298 function set_category_products_limit( $query ) { 299 if ( ! is_admin() && $query->is_main_query() && is_ic_taxonomy_page( $query ) ) {300 $archive_multiple_settings = get_multiple_settings();301 $current_per_page = $query->get( 'posts_per_page' );302 if ( $current_per_page !== - 1 && ! isset( $query->query['post__in'] ) && empty( $query->query['suppress_filters'] ) ) {303 $query->set( 'posts_per_page', $archive_multiple_settings['archive_products_limit'] );304 }305 }299 if ( ! is_admin() && $query->is_main_query() && is_ic_taxonomy_page( $query ) ) { 300 $archive_multiple_settings = get_multiple_settings(); 301 $current_per_page = $query->get( 'posts_per_page' ); 302 if ( $current_per_page !== - 1 && ! isset( $query->query['post__in'] ) && empty( $query->query['suppress_filters'] ) ) { 303 $query->set( 'posts_per_page', $archive_multiple_settings['archive_products_limit'] ); 304 } 305 } 306 306 } 307 307 … … 316 316 */ 317 317 function product_archive_pagination( $wp_query = null ) { 318 /*319 if ( is_ic_only_main_cats() && !is_product_filters_active() && !is_ic_ajax() ) {320 return;321 }322 *323 */324 if ( ! isset( $wp_query ) || ! is_object( $wp_query ) ) {325 global $paged, $wp_query;326 }327 if ( $wp_query->max_num_pages <= 1 ) {328 return;329 }330 $multiple_settings = get_multiple_settings();331 if ( ! is_ic_ajax() && ( is_ic_product_listing( $wp_query ) || ! is_ic_catalog_page( $wp_query ) ) && $multiple_settings['product_listing_cats'] == 'forced_cats_only' ) {332 return;333 }334 if ( $wp_query->get( 'paged' ) ) {335 $paged = absint( $wp_query->get( 'paged' ) );336 } elseif ( $wp_query->get( 'page' ) ) {337 $paged = absint( $wp_query->get( 'page' ) );338 } else {339 $paged = 1;340 }341 $max = intval( $wp_query->max_num_pages );342 if ( $paged >= 1 ) {343 $links[] = $paged;344 }345 if ( $paged >= 3 ) {346 $links[] = $paged - 1;347 $links[] = $paged - 2;348 }349 if ( ( $paged + 2 ) <= $max ) {350 $links[] = $paged + 2;351 $links[] = $paged + 1;352 }353 $names = get_archive_names();354 echo '<div id="product_archive_nav" class="product-archive-nav ' . design_schemes( 'box', 0 ) . '"><ul>' . "\n";355 if ( get_previous_posts_link( $names['previous_products'] ) ) {356 $previous = $paged - 1;357 printf( '<li class="previous-page" data-page="' . $previous . '">%s</li> ' . "\n", get_previous_posts_link( '<span>' . $names['previous_products'] . '</span>' ) );358 }359 $pre_page_buttons = apply_filters( 'ic_product_archive_nav_buttons', '', $links, $max, $paged );360 if ( empty( $pre_page_buttons ) ) {361 if ( ! in_array( 1, $links ) ) {362 $class = 1 == $paged ? ' class="active first-num"' : ' class="first-num"';363 printf( '<li%s data-page="1"><a href="%s">%s</a></li> ' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );364 if ( ! in_array( 2, $links ) ) {365 echo '<li class="nav-dots">...</li>';366 }367 }368 sort( $links );369 foreach ( (array) $links as $link ) {370 $class = $paged == $link ? ' class="active"' : '';371 printf( '<li%s data-page="' . $link . '"><a href="%s">%s</a></li> ' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );372 }373 if ( ! in_array( $max, $links ) ) {374 if ( ! in_array( $max - 1, $links ) ) {375 echo '<li class="nav-dots">...</li>' . "\n";376 }377 $class = $paged == $max ? ' class="active last-num"' : ' class="last-num"';378 printf( '<li%s data-page="' . $max . '"><a href="%s">%s</a></li> ' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );379 }380 } else {381 echo $pre_page_buttons;382 }383 if ( get_next_posts_link( $names['next_products'], $max ) ) {384 $next = $paged + 1;385 printf( '<li class="next-page" data-page="' . $next . '">%s</li> ' . "\n", get_next_posts_link( '<span>' . $names['next_products'] . '</span>', $max ) );386 }387 echo '</ul></div>' . "\n";388 wp_reset_postdata();318 /* 319 if ( is_ic_only_main_cats() && !is_product_filters_active() && !is_ic_ajax() ) { 320 return; 321 } 322 * 323 */ 324 if ( ! isset( $wp_query ) || ! is_object( $wp_query ) ) { 325 global $paged, $wp_query; 326 } 327 if ( $wp_query->max_num_pages <= 1 ) { 328 return; 329 } 330 $multiple_settings = get_multiple_settings(); 331 if ( ! is_ic_ajax() && ( is_ic_product_listing( $wp_query ) || ! is_ic_catalog_page( $wp_query ) ) && $multiple_settings['product_listing_cats'] == 'forced_cats_only' ) { 332 return; 333 } 334 if ( $wp_query->get( 'paged' ) ) { 335 $paged = absint( $wp_query->get( 'paged' ) ); 336 } elseif ( $wp_query->get( 'page' ) ) { 337 $paged = absint( $wp_query->get( 'page' ) ); 338 } else { 339 $paged = 1; 340 } 341 $max = intval( $wp_query->max_num_pages ); 342 if ( $paged >= 1 ) { 343 $links[] = $paged; 344 } 345 if ( $paged >= 3 ) { 346 $links[] = $paged - 1; 347 $links[] = $paged - 2; 348 } 349 if ( ( $paged + 2 ) <= $max ) { 350 $links[] = $paged + 2; 351 $links[] = $paged + 1; 352 } 353 $names = get_archive_names(); 354 echo '<div id="product_archive_nav" class="product-archive-nav ' . design_schemes( 'box', 0 ) . '"><ul>' . "\n"; 355 if ( get_previous_posts_link( $names['previous_products'] ) ) { 356 $previous = $paged - 1; 357 printf( '<li class="previous-page" data-page="' . $previous . '">%s</li> ' . "\n", get_previous_posts_link( '<span>' . $names['previous_products'] . '</span>' ) ); 358 } 359 $pre_page_buttons = apply_filters( 'ic_product_archive_nav_buttons', '', $links, $max, $paged ); 360 if ( empty( $pre_page_buttons ) ) { 361 if ( ! in_array( 1, $links ) ) { 362 $class = 1 == $paged ? ' class="active first-num"' : ' class="first-num"'; 363 printf( '<li%s data-page="1"><a href="%s">%s</a></li> ' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' ); 364 if ( ! in_array( 2, $links ) ) { 365 echo '<li class="nav-dots">...</li>'; 366 } 367 } 368 sort( $links ); 369 foreach ( (array) $links as $link ) { 370 $class = $paged == $link ? ' class="active"' : ''; 371 printf( '<li%s data-page="' . $link . '"><a href="%s">%s</a></li> ' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link ); 372 } 373 if ( ! in_array( $max, $links ) ) { 374 if ( ! in_array( $max - 1, $links ) ) { 375 echo '<li class="nav-dots">...</li>' . "\n"; 376 } 377 $class = $paged == $max ? ' class="active last-num"' : ' class="last-num"'; 378 printf( '<li%s data-page="' . $max . '"><a href="%s">%s</a></li> ' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max ); 379 } 380 } else { 381 echo $pre_page_buttons; 382 } 383 if ( get_next_posts_link( $names['next_products'], $max ) ) { 384 $next = $paged + 1; 385 printf( '<li class="next-page" data-page="' . $next . '">%s</li> ' . "\n", get_next_posts_link( '<span>' . $names['next_products'] . '</span>', $max ) ); 386 } 387 echo '</ul></div>' . "\n"; 388 wp_reset_postdata(); 389 389 } 390 390 391 391 function get_catalog_template( $archive_template, $post, $i = null, $design_scheme = null ) { 392 $themes_array = apply_filters( 'ecommerce_catalog_templates', array(393 'default' => get_default_archive_theme( $post, $archive_template ),394 'list' => get_list_archive_theme( $post, $archive_template ),395 'grid' => get_grid_archive_theme( $post, $archive_template ),396 ), $post, $i, $design_scheme, $archive_template );397 $themes_array[ $archive_template ] = isset( $themes_array[ $archive_template ] ) ? $themes_array[ $archive_template ] : $themes_array['default'];398 $themes_array[ $archive_template ] = empty( $themes_array[ $archive_template ] ) ? get_default_archive_theme( $post, 'default' ) : $themes_array[ $archive_template ];399 400 return $themes_array[ $archive_template ];392 $themes_array = apply_filters( 'ecommerce_catalog_templates', array( 393 'default' => get_default_archive_theme( $post, $archive_template ), 394 'list' => get_list_archive_theme( $post, $archive_template ), 395 'grid' => get_grid_archive_theme( $post, $archive_template ), 396 ), $post, $i, $design_scheme, $archive_template ); 397 $themes_array[ $archive_template ] = isset( $themes_array[ $archive_template ] ) ? $themes_array[ $archive_template ] : $themes_array['default']; 398 $themes_array[ $archive_template ] = empty( $themes_array[ $archive_template ] ) ? get_default_archive_theme( $post, 'default' ) : $themes_array[ $archive_template ]; 399 400 return $themes_array[ $archive_template ]; 401 401 } 402 402 403 403 function get_product_category_template( $archive_template, $product_cat, $i = null, $design_scheme = null ) { 404 $themes_array = apply_filters( 'ecommerce_category_templates', array(405 'default' => get_default_category_theme( $product_cat, $archive_template ),406 'list' => get_list_category_theme( $product_cat, $archive_template ),407 'grid' => get_grid_category_theme( $product_cat, $archive_template ),408 ), $product_cat, $i, $design_scheme, $archive_template );409 $themes_array[ $archive_template ] = isset( $themes_array[ $archive_template ] ) ? $themes_array[ $archive_template ] : $themes_array['default'];410 if ( empty( $themes_array[ $archive_template ] ) ) {411 if ( empty( $themes_array['default'] ) ) {412 $themes_array[ $archive_template ] = get_default_category_theme( $product_cat, 'default' );413 } else {414 $themes_array[ $archive_template ] = $themes_array['default'];415 }416 }417 418 return $themes_array[ $archive_template ];404 $themes_array = apply_filters( 'ecommerce_category_templates', array( 405 'default' => get_default_category_theme( $product_cat, $archive_template ), 406 'list' => get_list_category_theme( $product_cat, $archive_template ), 407 'grid' => get_grid_category_theme( $product_cat, $archive_template ), 408 ), $product_cat, $i, $design_scheme, $archive_template ); 409 $themes_array[ $archive_template ] = isset( $themes_array[ $archive_template ] ) ? $themes_array[ $archive_template ] : $themes_array['default']; 410 if ( empty( $themes_array[ $archive_template ] ) ) { 411 if ( empty( $themes_array['default'] ) ) { 412 $themes_array[ $archive_template ] = get_default_category_theme( $product_cat, 'default' ); 413 } else { 414 $themes_array[ $archive_template ] = $themes_array['default']; 415 } 416 } 417 418 return $themes_array[ $archive_template ]; 419 419 } 420 420 421 421 function ic_get_available_templates() { 422 $templates = array(423 'default' => __( 'Modern Grid', 'ecommerce-product-catalog' ),424 'list' => __( 'Classic List', 'ecommerce-product-catalog' ),425 'grid' => __( 'Classic Grid', 'ecommerce-product-catalog' )426 );427 428 return apply_filters( 'ic_epc_available_templates', $templates );422 $templates = array( 423 'default' => __( 'Modern Grid', 'ecommerce-product-catalog' ), 424 'list' => __( 'Classic List', 'ecommerce-product-catalog' ), 425 'grid' => __( 'Classic Grid', 'ecommerce-product-catalog' ) 426 ); 427 428 return apply_filters( 'ic_epc_available_templates', $templates ); 429 429 } 430 430 431 431 function more_products() { 432 global $wp_query, $shortcode_query;433 $post_type = apply_filters( 'current_product_post_type', 'al_product' );434 $taxonomy = apply_filters( 'current_product_catalog_taxonomy', 'al_product-cat' );435 if ( empty( $wp_query->is_single ) && ( empty( $wp_query->is_page ) || ic_get_global( 'inside_show_catalog_shortcode' ) ) && ( ( isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == $post_type ) || ( isset( $wp_query->query_vars['post_type'] ) && is_array( $wp_query->query_vars['post_type'] ) && array_search( $post_type, $wp_query->query_vars['post_type'] ) !== false ) || ( is_string( $taxonomy ) && isset( $wp_query->query[ $taxonomy ] ) ) ) ) {436 $y_query = $wp_query;437 } else {438 $y_query = $shortcode_query;439 }440 if ( empty( $y_query ) ) {441 $y_query = $wp_query;442 }443 if ( ! empty( $y_query->posts ) && is_array( $y_query->posts ) && apply_filters( 'ic_query_check_if_product', true, $y_query ) ) {444 if ( ! empty( $y_query->posts[0]->ID ) && ! is_ic_product( $y_query->posts[0]->ID ) ) {445 446 return false;447 }448 }449 if ( isset( $y_query->current_post ) ) {450 return $y_query->current_post + 1 < $y_query->post_count;451 } else {452 453 return false;454 }432 global $wp_query, $shortcode_query; 433 $post_type = apply_filters( 'current_product_post_type', 'al_product' ); 434 $taxonomy = apply_filters( 'current_product_catalog_taxonomy', 'al_product-cat' ); 435 if ( empty( $wp_query->is_single ) && ( empty( $wp_query->is_page ) || ic_get_global( 'inside_show_catalog_shortcode' ) ) && ( ( isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == $post_type ) || ( isset( $wp_query->query_vars['post_type'] ) && is_array( $wp_query->query_vars['post_type'] ) && array_search( $post_type, $wp_query->query_vars['post_type'] ) !== false ) || ( is_string( $taxonomy ) && isset( $wp_query->query[ $taxonomy ] ) ) ) ) { 436 $y_query = $wp_query; 437 } else { 438 $y_query = $shortcode_query; 439 } 440 if ( empty( $y_query ) ) { 441 $y_query = $wp_query; 442 } 443 if ( ! empty( $y_query->posts ) && is_array( $y_query->posts ) && apply_filters( 'ic_query_check_if_product', true, $y_query ) ) { 444 if ( ! empty( $y_query->posts[0]->ID ) && ! is_ic_product( $y_query->posts[0]->ID ) ) { 445 446 return false; 447 } 448 } 449 if ( isset( $y_query->current_post ) ) { 450 return $y_query->current_post + 1 < $y_query->post_count; 451 } else { 452 453 return false; 454 } 455 455 } 456 456 457 457 function more_product_cats() { 458 global $cat_shortcode_query;459 if ( isset( $cat_shortcode_query['current'] ) ) {460 461 return $cat_shortcode_query['current'] + 1 < $cat_shortcode_query['count'];462 } else {463 return false;464 }458 global $cat_shortcode_query; 459 if ( isset( $cat_shortcode_query['current'] ) ) { 460 461 return $cat_shortcode_query['current'] + 1 < $cat_shortcode_query['count']; 462 } else { 463 return false; 464 } 465 465 } 466 466 467 467 function get_row_class( $grid_settings, $what = 'products' ) { 468 $row_class = 'full';469 if ( is_ic_shortcode_query() ) {470 $shortcode_per_row = ic_get_global( 'shortcode_per_row' );471 if ( $shortcode_per_row ) {472 $grid_settings['entries'] = $shortcode_per_row;473 $grid_settings['per-row-categories'] = $shortcode_per_row;474 }475 }476 if ( $what === 'products' ) {477 $per_row = $grid_settings['entries'];478 } else {479 $per_row = $grid_settings['per-row-categories'];480 }481 if ( $per_row != '' ) {482 global $ic_row;483 if ( $ic_row > $per_row || ! isset( $ic_row ) ) {484 $ic_row = 1;485 }486 487 $count = $ic_row - $per_row;488 if ( $ic_row == 1 ) {489 $row_class = 'first';490 } else if ( $count == 0 ) {491 $row_class = 'last';492 } else {493 $row_class = 'middle';494 }495 if ( more_products() || more_product_cats() ) {496 $ic_row ++;497 } else {498 $ic_row = 1;499 }500 }501 502 return $row_class;468 $row_class = 'full'; 469 if ( is_ic_shortcode_query() ) { 470 $shortcode_per_row = ic_get_global( 'shortcode_per_row' ); 471 if ( $shortcode_per_row ) { 472 $grid_settings['entries'] = $shortcode_per_row; 473 $grid_settings['per-row-categories'] = $shortcode_per_row; 474 } 475 } 476 if ( $what === 'products' ) { 477 $per_row = $grid_settings['entries']; 478 } else { 479 $per_row = $grid_settings['per-row-categories']; 480 } 481 if ( $per_row != '' ) { 482 global $ic_row; 483 if ( $ic_row > $per_row || ! isset( $ic_row ) ) { 484 $ic_row = 1; 485 } 486 487 $count = $ic_row - $per_row; 488 if ( $ic_row == 1 ) { 489 $row_class = 'first'; 490 } else if ( $count == 0 ) { 491 $row_class = 'last'; 492 } else { 493 $row_class = 'middle'; 494 } 495 if ( more_products() || more_product_cats() ) { 496 $ic_row ++; 497 } else { 498 $ic_row = 1; 499 } 500 } 501 502 return $row_class; 503 503 } 504 504 … … 506 506 507 507 function reset_row_class() { 508 global $ic_row;509 $ic_row = 1;510 ic_delete_global( 'shortcode_per_row' );508 global $ic_row; 509 $ic_row = 1; 510 ic_delete_global( 'shortcode_per_row' ); 511 511 } 512 512 … … 521 521 */ 522 522 function product_post_class( $classes ) { 523 if ( is_ic_catalog_page() ) {524 if ( $key = array_search( 'has-post-thumbnail', $classes ) !== false ) {525 unset( $classes[ $key ] );526 }527 $classes[] = 'al_product';528 $classes[] = 'responsive';529 if ( is_ic_product_page() ) {530 $single_options = get_product_page_settings();531 $classes[] = $single_options['template'];532 $classes[] = 'ic-template-' . $single_options['template'];533 $product_id = ic_get_product_id();534 if ( ! empty( $product_id ) ) {535 $classes[] = 'product-' . $product_id;536 }537 $classes = apply_filters( 'product-page-class', $classes, $product_id );538 }539 }540 541 return $classes;523 if ( is_ic_catalog_page() ) { 524 if ( $key = array_search( 'has-post-thumbnail', $classes ) !== false ) { 525 unset( $classes[ $key ] ); 526 } 527 $classes[] = 'al_product'; 528 $classes[] = 'responsive'; 529 if ( is_ic_product_page() ) { 530 $single_options = get_product_page_settings(); 531 $classes[] = $single_options['template']; 532 $classes[] = 'ic-template-' . $single_options['template']; 533 $product_id = ic_get_product_id(); 534 if ( ! empty( $product_id ) ) { 535 $classes[] = 'product-' . $product_id; 536 } 537 $classes = apply_filters( 'product-page-class', $classes, $product_id ); 538 } 539 } 540 541 return $classes; 542 542 } 543 543 … … 550 550 */ 551 551 function product_listing_additional_styles( $archive_template ) { 552 if ( current_filter() === 'product_listing_entry_inside' ) {553 remove_action( 'before_product_list', 'product_listing_additional_styles' );554 } else if ( current_filter() === 'before_product_list' ) {555 remove_action( 'product_listing_entry_inside', 'product_listing_additional_styles' );556 }557 $styles = '<style>';558 $styles = apply_filters( 'product_listing_additional_styles', $styles, $archive_template );559 $styles .= '</style>';560 if ( $styles != '<style></style>' && ! is_ic_admin() ) {561 echo $styles;562 }552 if ( current_filter() === 'product_listing_entry_inside' ) { 553 remove_action( 'before_product_list', 'product_listing_additional_styles' ); 554 } else if ( current_filter() === 'before_product_list' ) { 555 remove_action( 'product_listing_entry_inside', 'product_listing_additional_styles' ); 556 } 557 $styles = '<style>'; 558 $styles = apply_filters( 'product_listing_additional_styles', $styles, $archive_template ); 559 $styles .= '</style>'; 560 if ( $styles != '<style></style>' && ! is_ic_admin() ) { 561 echo $styles; 562 } 563 563 } 564 564 … … 570 570 */ 571 571 function product_page_additional_styles() { 572 $styles = '<style>';573 $styles = apply_filters( 'product_page_additional_styles', $styles );574 $styles .= '</style>';575 if ( $styles != '<style></style>' && ! is_ic_admin() ) {576 echo $styles;577 }572 $styles = '<style>'; 573 $styles = apply_filters( 'product_page_additional_styles', $styles ); 574 $styles .= '</style>'; 575 if ( $styles != '<style></style>' && ! is_ic_admin() ) { 576 echo $styles; 577 } 578 578 } 579 579 … … 584 584 */ 585 585 function get_product_listing_template() { 586 global $shortcode_query;587 $default = 'default';588 if ( ! empty( $shortcode_query ) ) {589 global $archive_template;590 $archive_template = isset( $archive_template ) ? $archive_template : get_option( 'archive_template', $default );591 } else {592 $archive_template = get_option( 'archive_template', $default );593 }594 $archive_template = ! empty( $archive_template ) ? $archive_template : $default;595 596 return apply_filters( 'product_listing_template', $archive_template );586 global $shortcode_query; 587 $default = 'default'; 588 if ( ! empty( $shortcode_query ) ) { 589 global $archive_template; 590 $archive_template = isset( $archive_template ) ? $archive_template : get_option( 'archive_template', $default ); 591 } else { 592 $archive_template = get_option( 'archive_template', $default ); 593 } 594 $archive_template = ! empty( $archive_template ) ? $archive_template : $default; 595 596 return apply_filters( 'product_listing_template', $archive_template ); 597 597 } 598 598 … … 636 636 */ 637 637 function override_product_page_title( $page_title, $id = null ) { 638 $listing_id = get_product_listing_id();639 if ( ! is_admin() && is_ic_catalog_page() && ! is_ic_product_page() && ! in_the_ic_loop() && ! is_filter_bar() && ( empty( $id ) || ( get_quasi_post_type( get_post_type( $id ) ) == 'al_product' ) ) || $listing_id == $id ) {640 $query = null;641 if ( $listing_id === 'noid' ) {642 return $page_title;643 }644 if ( is_ic_shortcode_integration() ) {645 global $wp_query;646 $this_query = ic_get_global( 'pre_shortcode_query' );647 if ( $this_query ) {648 $wp_query = $this_query;649 }650 } else {651 return $page_title;652 }653 if ( is_ic_taxonomy_page( $query ) && ( empty( $id ) || ! is_ic_product( $id ) ) && $listing_id != $id ) {654 $page_title = get_product_tax_title( $page_title );655 } else if ( is_ic_product_search( $query ) ) {656 $page_title = ic_get_search_page_title();657 } else if ( is_ic_product_listing( $query ) && ( empty( $id ) || $id == $listing_id ) ) {658 $page_title = get_product_listing_title();659 }660 }661 662 return $page_title;638 $listing_id = get_product_listing_id(); 639 if ( ! is_admin() && is_ic_catalog_page() && ! is_ic_product_page() && ! in_the_ic_loop() && ! is_filter_bar() && ( empty( $id ) || ( get_quasi_post_type( get_post_type( $id ) ) == 'al_product' ) ) || $listing_id == $id ) { 640 $query = null; 641 if ( $listing_id === 'noid' ) { 642 return $page_title; 643 } 644 if ( is_ic_shortcode_integration() ) { 645 global $wp_query; 646 $this_query = ic_get_global( 'pre_shortcode_query' ); 647 if ( $this_query ) { 648 $wp_query = $this_query; 649 } 650 } else { 651 return $page_title; 652 } 653 if ( is_ic_taxonomy_page( $query ) && ( empty( $id ) || ! is_ic_product( $id ) ) && $listing_id != $id ) { 654 $page_title = get_product_tax_title( $page_title ); 655 } else if ( is_ic_product_search( $query ) ) { 656 $page_title = ic_get_search_page_title(); 657 } else if ( is_ic_product_listing( $query ) && ( empty( $id ) || $id == $listing_id ) ) { 658 $page_title = get_product_listing_title(); 659 } 660 } 661 662 return $page_title; 663 663 } 664 664 … … 666 666 667 667 function ic_catalog_set_post_title() { 668 if ( is_ic_simple_mode() || is_ic_theme_mode() ) {669 return;670 }671 if ( is_ic_product_listing() ) {672 $page_title = get_product_listing_title();673 } else if ( is_ic_taxonomy_page() ) {674 $page_title = get_product_tax_title();675 }676 if ( ! empty( $page_title ) ) {677 global $post;678 if ( ! empty( $post->ID ) ) {679 ic_save_global( 'pre_title_post_' . $post->ID, $post->post_title );680 $post->post_title = $page_title;681 add_action( 'before_product_list', 'ic_catalog_reset_post_title' );682 }683 }668 if ( is_ic_simple_mode() || is_ic_theme_mode() ) { 669 return; 670 } 671 if ( is_ic_product_listing() ) { 672 $page_title = get_product_listing_title(); 673 } else if ( is_ic_taxonomy_page() ) { 674 $page_title = get_product_tax_title(); 675 } 676 if ( ! empty( $page_title ) ) { 677 global $post; 678 if ( ! empty( $post->ID ) ) { 679 ic_save_global( 'pre_title_post_' . $post->ID, $post->post_title ); 680 $post->post_title = $page_title; 681 add_action( 'before_product_list', 'ic_catalog_reset_post_title' ); 682 } 683 } 684 684 } 685 685 686 686 function ic_catalog_reset_post_title() { 687 if ( is_ic_in_shortcode() ) {688 return;689 }690 global $post;691 the_post();692 if ( ! empty( $post->ID ) ) {693 $pre_title = ic_get_global( 'pre_title_post_' . $post->ID );694 if ( ! empty( $pre_title ) ) {695 $post->post_title = $pre_title;696 ic_delete_global( 'pre_title_post_' . $post->ID );697 remove_action( 'before_product_list', 'ic_catalog_reset_post_title' );698 }699 }700 rewind_posts();687 if ( is_ic_in_shortcode() ) { 688 return; 689 } 690 global $post; 691 the_post(); 692 if ( ! empty( $post->ID ) ) { 693 $pre_title = ic_get_global( 'pre_title_post_' . $post->ID ); 694 if ( ! empty( $pre_title ) ) { 695 $post->post_title = $pre_title; 696 ic_delete_global( 'pre_title_post_' . $post->ID ); 697 remove_action( 'before_product_list', 'ic_catalog_reset_post_title' ); 698 } 699 } 700 rewind_posts(); 701 701 } 702 702 703 703 function ic_get_search_page_title() { 704 if ( ! empty( $_GET['s'] ) ) {705 $search = $_GET['s'];706 } else {707 $search = get_search_query( false );708 if ( empty( $search ) ) {709 $query = ic_get_catalog_query();710 if ( ! empty( $query->query['s'] ) ) {711 $search = $query->query['s'];712 }713 }714 715 }716 717 return __( 'Search Results for:', 'ecommerce-product-catalog' ) . ' <span class="ic-search-keyword">' . wp_unslash( esc_html( strval( $search ) ) ) . '</span>';704 if ( ! empty( $_GET['s'] ) ) { 705 $search = $_GET['s']; 706 } else { 707 $search = get_search_query( false ); 708 if ( empty( $search ) ) { 709 $query = ic_get_catalog_query(); 710 if ( ! empty( $query->query['s'] ) ) { 711 $search = $query->query['s']; 712 } 713 } 714 715 } 716 717 return __( 'Search Results for:', 'ecommerce-product-catalog' ) . ' <span class="ic-search-keyword">' . wp_unslash( esc_html( strval( $search ) ) ) . '</span>'; 718 718 } 719 719 720 720 function get_product_listing_title() { 721 $archive_names = get_archive_names();722 $def_page_id = get_product_listing_id();723 $page_id = apply_filters( 'before_archive_post_id', $def_page_id );724 725 $page = empty( $page_id ) ? '' : get_post( $page_id );726 if ( $page == '' ) {727 $archive_multiple_settings = get_multiple_settings();728 if ( $archive_multiple_settings['product_listing_cats'] == 'off' ) {729 $page_title = $archive_names['all_products'];730 } else {731 $page_title = $archive_names['all_main_categories'];732 }733 } else {734 //remove_filter( 'the_title', 'override_product_page_title', 11, 2 );735 $page_title = apply_filters( 'the_title', $page->post_title, $page_id );736 //add_filter( 'the_title', 'override_product_page_title', 11, 2 );737 }738 739 return apply_filters( 'ic_product_listing_title', $page_title, $page );721 $archive_names = get_archive_names(); 722 $def_page_id = get_product_listing_id(); 723 $page_id = apply_filters( 'before_archive_post_id', $def_page_id ); 724 725 $page = empty( $page_id ) ? '' : get_post( $page_id ); 726 if ( $page == '' ) { 727 $archive_multiple_settings = get_multiple_settings(); 728 if ( $archive_multiple_settings['product_listing_cats'] == 'off' ) { 729 $page_title = $archive_names['all_products']; 730 } else { 731 $page_title = $archive_names['all_main_categories']; 732 } 733 } else { 734 //remove_filter( 'the_title', 'override_product_page_title', 11, 2 ); 735 $page_title = apply_filters( 'the_title', $page->post_title, $page_id ); 736 //add_filter( 'the_title', 'override_product_page_title', 11, 2 ); 737 } 738 739 return apply_filters( 'ic_product_listing_title', $page_title, $page ); 740 740 } 741 741 742 742 function get_product_tax_title( $page_title = null ) { 743 $archive_names = get_archive_names();744 $the_tax = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );745 if ( isset( $the_tax->name ) ) {746 $name = $the_tax->name;747 } else {748 $name = $page_title;749 }750 if ( ! empty( $archive_names['all_prefix'] ) && has_shortcode( $archive_names['all_prefix'], 'product_category_name' ) ) {751 $page_title = do_shortcode( $archive_names['all_prefix'] );752 } else if ( ! empty( $archive_names['all_prefix'] ) && ! empty( $name ) ) {753 $page_title = do_shortcode( $archive_names['all_prefix'] ) . ' ' . $name;754 } else {755 $page_title = $name;756 }757 758 return $page_title;743 $archive_names = get_archive_names(); 744 $the_tax = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 745 if ( isset( $the_tax->name ) ) { 746 $name = $the_tax->name; 747 } else { 748 $name = $page_title; 749 } 750 if ( ! empty( $archive_names['all_prefix'] ) && has_shortcode( $archive_names['all_prefix'], 'product_category_name' ) ) { 751 $page_title = do_shortcode( $archive_names['all_prefix'] ); 752 } else if ( ! empty( $archive_names['all_prefix'] ) && ! empty( $name ) ) { 753 $page_title = do_shortcode( $archive_names['all_prefix'] ) . ' ' . $name; 754 } else { 755 $page_title = $name; 756 } 757 758 return $page_title; 759 759 } 760 760 … … 771 771 */ 772 772 function product_listing_current_nav_class( $classes, $item ) { 773 global $post;774 if ( isset( $post->ID ) && is_ic_product_listing() ) {775 if ( isset( $item->object_id ) && $item->object_id == get_product_listing_id() ) {776 777 //$current_post_type = get_post_type_object( get_post_type( $post->ID ) );778 //$current_post_type_slug = $current_post_type->rewrite[ 'slug' ];779 //$current_post_type_slug = !empty( $current_post_type_slug ) ? '/' . $current_post_type_slug . '/' : $current_post_type_slug;780 //$menu_slug = ic_strtolower( trim( $item->url ) );781 //if ( strpos( $menu_slug, $current_post_type_slug ) !== false ) {782 $classes[] = 'current-menu-item';783 $classes[] = 'current_page_item';784 //}785 } else {786 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) {787 unset( $classes[ $key ] );788 }789 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) {790 unset( $classes[ $key ] );791 }792 }793 } else if ( isset( $post->ID ) && ( is_ic_product_page() || is_ic_taxonomy_page() ) ) {794 if ( isset( $item->object ) && strpos( $item->object, 'al_product-cat' ) === false && $item->object != 'custom' ) {795 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) {796 unset( $classes[ $key ] );797 }798 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) {799 unset( $classes[ $key ] );800 }801 }802 }803 804 return $classes;773 global $post; 774 if ( isset( $post->ID ) && is_ic_product_listing() ) { 775 if ( isset( $item->object_id ) && $item->object_id == get_product_listing_id() ) { 776 777 //$current_post_type = get_post_type_object( get_post_type( $post->ID ) ); 778 //$current_post_type_slug = $current_post_type->rewrite[ 'slug' ]; 779 //$current_post_type_slug = !empty( $current_post_type_slug ) ? '/' . $current_post_type_slug . '/' : $current_post_type_slug; 780 //$menu_slug = ic_strtolower( trim( $item->url ) ); 781 //if ( strpos( $menu_slug, $current_post_type_slug ) !== false ) { 782 $classes[] = 'current-menu-item'; 783 $classes[] = 'current_page_item'; 784 //} 785 } else { 786 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) { 787 unset( $classes[ $key ] ); 788 } 789 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) { 790 unset( $classes[ $key ] ); 791 } 792 } 793 } else if ( isset( $post->ID ) && ( is_ic_product_page() || is_ic_taxonomy_page() ) ) { 794 if ( isset( $item->object ) && strpos( $item->object, 'al_product-cat' ) === false && $item->object != 'custom' ) { 795 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) { 796 unset( $classes[ $key ] ); 797 } 798 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) { 799 unset( $classes[ $key ] ); 800 } 801 } 802 } 803 804 return $classes; 805 805 } 806 806 … … 817 817 */ 818 818 function product_listing_page_nav_class( $classes, $page ) { 819 global $post;820 if ( isset( $post->ID ) && is_ic_product_listing() ) {821 if ( $page->ID == get_product_listing_id() ) {822 //$current_post_type = get_post_type_object( get_post_type( $post->ID ) );823 //$current_post_type_slug = $current_post_type->rewrite[ 'slug' ];824 //$menu_slug = $page->post_name;825 //if ( $menu_slug == $current_post_type_slug ) {826 $classes[] = 'current-menu-item';827 $classes[] = 'current_page_item';828 //}829 } else {830 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) {831 unset( $classes[ $key ] );832 }833 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) {834 unset( $classes[ $key ] );835 }836 }837 } else if ( isset( $post->ID ) && ( is_ic_product_page() || is_ic_taxonomy_page() ) ) {838 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) {839 unset( $classes[ $key ] );840 }841 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) {842 unset( $classes[ $key ] );843 }844 }845 846 return $classes;819 global $post; 820 if ( isset( $post->ID ) && is_ic_product_listing() ) { 821 if ( $page->ID == get_product_listing_id() ) { 822 //$current_post_type = get_post_type_object( get_post_type( $post->ID ) ); 823 //$current_post_type_slug = $current_post_type->rewrite[ 'slug' ]; 824 //$menu_slug = $page->post_name; 825 //if ( $menu_slug == $current_post_type_slug ) { 826 $classes[] = 'current-menu-item'; 827 $classes[] = 'current_page_item'; 828 //} 829 } else { 830 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) { 831 unset( $classes[ $key ] ); 832 } 833 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) { 834 unset( $classes[ $key ] ); 835 } 836 } 837 } else if ( isset( $post->ID ) && ( is_ic_product_page() || is_ic_taxonomy_page() ) ) { 838 if ( ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) { 839 unset( $classes[ $key ] ); 840 } 841 if ( ( $key = array_search( 'current_page_parent', $classes ) ) !== false ) { 842 unset( $classes[ $key ] ); 843 } 844 } 845 846 return $classes; 847 847 } 848 848 … … 852 852 */ 853 853 function product_list_class( $archive_template, $where = 'product-list' ) { 854 return apply_filters( 'product-list-class', '', $where, $archive_template );854 return apply_filters( 'product-list-class', '', $where, $archive_template ); 855 855 } 856 856 857 857 function product_list_attr( $query = null ) { 858 return apply_filters( 'product-list-attr', '', $query );858 return apply_filters( 'product-list-attr', '', $query ); 859 859 } 860 860 … … 864 864 */ 865 865 function product_class( $product_id ) { 866 $class = get_post_status( $product_id );867 868 return apply_filters( 'product-class', $class, $product_id );866 $class = get_post_status( $product_id ); 867 868 return apply_filters( 'product-class', $class, $product_id ); 869 869 } 870 870 … … 874 874 */ 875 875 function product_category_class( $category_id ) { 876 return apply_filters( 'product-category-class', '', $category_id );876 return apply_filters( 'product-category-class', '', $category_id ); 877 877 } 878 878 … … 884 884 */ 885 885 function product_list_categories_header() { 886 $archive_names = get_archive_names();887 if ( ! empty( $archive_names['all_main_categories'] ) && ! isset( $shortcode_query ) ) {888 $title = do_shortcode( $archive_names['all_main_categories'] );889 if ( get_product_listing_title() != $title ) {890 echo '<h2 class="catalog-header">' . do_shortcode( $archive_names['all_main_categories'] ) . '</h2>';891 }892 }886 $archive_names = get_archive_names(); 887 if ( ! empty( $archive_names['all_main_categories'] ) && ! isset( $shortcode_query ) ) { 888 $title = do_shortcode( $archive_names['all_main_categories'] ); 889 if ( get_product_listing_title() != $title ) { 890 echo '<h2 class="catalog-header">' . do_shortcode( $archive_names['all_main_categories'] ) . '</h2>'; 891 } 892 } 893 893 } 894 894 … … 900 900 */ 901 901 function category_list_subcategories_header() { 902 if ( is_ic_taxonomy_page() ) {903 $archive_names = get_archive_names();904 if ( ! empty( $archive_names['all_subcategories'] ) && ! is_ic_shortcode_query() ) {905 echo '<h2 class="catalog-header">' . do_shortcode( $archive_names['all_subcategories'] ) . '</h2>';906 }907 }902 if ( is_ic_taxonomy_page() ) { 903 $archive_names = get_archive_names(); 904 if ( ! empty( $archive_names['all_subcategories'] ) && ! is_ic_shortcode_query() ) { 905 echo '<h2 class="catalog-header">' . do_shortcode( $archive_names['all_subcategories'] ) . '</h2>'; 906 } 907 } 908 908 } 909 909 … … 915 915 */ 916 916 function product_list_header() { 917 $archive_names = get_archive_names();918 if ( ( ! empty( $archive_names['all_products'] ) || ! empty( $archive_names['category_products'] ) ) && ! is_ic_shortcode_query() ) {919 if ( is_ic_product_listing() && ! empty( $archive_names['all_products'] ) ) {920 $title = do_shortcode( $archive_names['all_products'] );921 if ( get_product_listing_title() != $title ) {922 echo '<h2 class="catalog-header">' . $title . '</h2>';923 }924 } else if ( is_ic_taxonomy_page() && ! empty( $archive_names['category_products'] ) && is_ic_product_listing_showing_cats() ) {925 //$the_tax = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );926 echo '<h2 class="catalog-header">' . do_shortcode( $archive_names['category_products'] ) . '</h2>';927 }928 }917 $archive_names = get_archive_names(); 918 if ( ( ! empty( $archive_names['all_products'] ) || ! empty( $archive_names['category_products'] ) ) && ! is_ic_shortcode_query() ) { 919 if ( is_ic_product_listing() && ! empty( $archive_names['all_products'] ) ) { 920 $title = do_shortcode( $archive_names['all_products'] ); 921 if ( get_product_listing_title() != $title ) { 922 echo '<h2 class="catalog-header">' . $title . '</h2>'; 923 } 924 } else if ( is_ic_taxonomy_page() && ! empty( $archive_names['category_products'] ) && is_ic_product_listing_showing_cats() ) { 925 //$the_tax = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 926 echo '<h2 class="catalog-header">' . do_shortcode( $archive_names['category_products'] ) . '</h2>'; 927 } 928 } 929 929 } 930 930 … … 935 935 */ 936 936 function design_settings_examples_image() { 937 return AL_PLUGIN_BASE_PATH . 'templates/themes/img/example-product.jpg';937 return AL_PLUGIN_BASE_PATH . 'templates/themes/img/example-product.jpg'; 938 938 } 939 939 … … 941 941 942 942 function exclude_products_from_child_cat( $query ) { 943 if ( empty( $_GET['product_category'] ) && ( ! is_admin() || is_ic_ajax() ) && ( is_ic_ajax() || $query->is_main_query() ) && is_ic_taxonomy_page( $query ) && is_ic_only_main_cats( $query ) && ! is_product_filter_active( 'product_category' ) ) {944 foreach ( $query->tax_query->queries as $i => $xquery ) {945 if ( ! empty( $query->tax_query->queries[ $i ] ) && is_array( $query->tax_query->queries[ $i ] ) && ! empty( $query->tax_query->queries[ $i ]['taxonomy'] ) ) {946 $query->tax_query->queries[ $i ]['include_children'] = 0;947 }948 }949 }943 if ( empty( $_GET['product_category'] ) && ( ! is_admin() || is_ic_ajax() ) && ( is_ic_ajax() || $query->is_main_query() ) && is_ic_taxonomy_page( $query ) && is_ic_only_main_cats( $query ) && ! is_product_filter_active( 'product_category' ) ) { 944 foreach ( $query->tax_query->queries as $i => $xquery ) { 945 if ( ! empty( $query->tax_query->queries[ $i ] ) && is_array( $query->tax_query->queries[ $i ] ) && ! empty( $query->tax_query->queries[ $i ]['taxonomy'] ) ) { 946 $query->tax_query->queries[ $i ]['include_children'] = 0; 947 } 948 } 949 } 950 950 } 951 951 … … 960 960 */ 961 961 function add_classes_on_categories( $classes ) { 962 if ( is_tax() /* && is_ic_only_main_cats() */ ) {963 $classes .= ' hentry status-publish';964 }965 966 return $classes;962 if ( is_tax() /* && is_ic_only_main_cats() */ ) { 963 $classes .= ' hentry status-publish'; 964 } 965 966 return $classes; 967 967 } 968 968 … … 974 974 */ 975 975 function advanced_mode_styling() { 976 $settings = ic_catalog_theme_integration::settings();977 $styling = '<style>';978 if ( $settings['container_width'] != 100 ) {979 $styling .= '#container.content-area.product-catalog {width: ' . $settings['container_width'] . '%; margin: 0 auto; overflow: hidden; box-sizing: border-box; float: none;}';980 }981 if ( $settings['container_bg'] !== '' && ic_string_contains( $settings['container_bg'], '#' ) ) {982 $styling .= '#container.content-area.product-catalog {background: ' . $settings['container_bg'] . ';}';983 }984 if ( $settings['container_padding'] != 0 ) {985 $styling .= '.content-area.product-catalog #content {padding: ' . $settings['container_padding'] . 'px; box-sizing: border-box; float: none; }';986 if ( is_ic_default_theme_sided_sidebar_active() ) {987 $styling .= '.content-area.product-catalog #catalog_sidebar {padding: ' . $settings['container_padding'] . 'px; box-sizing: border-box;}';988 }989 }990 if ( $settings['container_text'] !== '' && ic_string_contains( $settings['container_text'], '#' ) ) {991 $styling .= '#container.content-area.product-catalog * {color: ' . $settings['container_text'] . ';}';992 }993 if ( $settings['default_sidebar'] == 'left' ) {994 $styling .= '.content-area.product-catalog #catalog_sidebar {float: left;}';995 }996 if ( is_ic_default_theme_sided_sidebar_active() ) {997 $styling .= '.content-area.product-catalog #content {width: 70%;';998 if ( $settings['default_sidebar'] == 'left' ) {999 $styling .= 'float:right;';1000 } else if ( $settings['default_sidebar'] == 'right' ) {1001 $styling .= 'float:left;';1002 }1003 $styling .= '}';1004 }1005 $styling .= apply_filters( 'advanced_mode_styling_rules', '' );1006 $styling .= '</style>';1007 if ( $styling != '<style></style>' ) {1008 echo $styling;1009 }976 $settings = ic_catalog_theme_integration::settings(); 977 $styling = '<style>'; 978 if ( $settings['container_width'] != 100 ) { 979 $styling .= '#container.content-area.product-catalog {width: ' . $settings['container_width'] . '%; margin: 0 auto; overflow: hidden; box-sizing: border-box; float: none;}'; 980 } 981 if ( $settings['container_bg'] !== '' && ic_string_contains( $settings['container_bg'], '#' ) ) { 982 $styling .= '#container.content-area.product-catalog {background: ' . $settings['container_bg'] . ';}'; 983 } 984 if ( $settings['container_padding'] != 0 ) { 985 $styling .= '.content-area.product-catalog #content {padding: ' . $settings['container_padding'] . 'px; box-sizing: border-box; float: none; }'; 986 if ( is_ic_default_theme_sided_sidebar_active() ) { 987 $styling .= '.content-area.product-catalog #catalog_sidebar {padding: ' . $settings['container_padding'] . 'px; box-sizing: border-box;}'; 988 } 989 } 990 if ( $settings['container_text'] !== '' && ic_string_contains( $settings['container_text'], '#' ) ) { 991 $styling .= '#container.content-area.product-catalog * {color: ' . $settings['container_text'] . ';}'; 992 } 993 if ( $settings['default_sidebar'] == 'left' ) { 994 $styling .= '.content-area.product-catalog #catalog_sidebar {float: left;}'; 995 } 996 if ( is_ic_default_theme_sided_sidebar_active() ) { 997 $styling .= '.content-area.product-catalog #content {width: 70%;'; 998 if ( $settings['default_sidebar'] == 'left' ) { 999 $styling .= 'float:right;'; 1000 } else if ( $settings['default_sidebar'] == 'right' ) { 1001 $styling .= 'float:left;'; 1002 } 1003 $styling .= '}'; 1004 } 1005 $styling .= apply_filters( 'advanced_mode_styling_rules', '' ); 1006 $styling .= '</style>'; 1007 if ( $styling != '<style></style>' ) { 1008 echo $styling; 1009 } 1010 1010 } 1011 1011 … … 1016 1016 */ 1017 1017 function show_advanced_mode_default_sidebar() { 1018 if ( is_ic_default_theme_sided_sidebar_active() || ( is_ic_integration_wizard_page() && isset( $_GET['test_advanced'] ) && $_GET['test_advanced'] == 1 ) ) {1019 add_action( 'advanced_mode_layout_after_content', 'advanced_mode_default_sided_sidebar' );1020 } else if ( is_ic_default_theme_sidebar_active() ) {1021 add_action( 'advanced_mode_layout_end', 'advanced_mode_default_sidebar' );1022 }1018 if ( is_ic_default_theme_sided_sidebar_active() || ( is_ic_integration_wizard_page() && isset( $_GET['test_advanced'] ) && $_GET['test_advanced'] == 1 ) ) { 1019 add_action( 'advanced_mode_layout_after_content', 'advanced_mode_default_sided_sidebar' ); 1020 } else if ( is_ic_default_theme_sidebar_active() ) { 1021 add_action( 'advanced_mode_layout_end', 'advanced_mode_default_sidebar' ); 1022 } 1023 1023 } 1024 1024 … … 1027 1027 */ 1028 1028 function advanced_mode_default_sidebar() { 1029 get_sidebar();1029 get_sidebar(); 1030 1030 } 1031 1031 … … 1034 1034 */ 1035 1035 function advanced_mode_default_sided_sidebar() { 1036 $sidebar_id = apply_filters( 'catalog_default_sidebar_id', 'catalog_sidebar' );1037 $class = apply_filters( 'catalog_default_sidebar_class', 'catalog_sidebar' );1038 echo '<div id="' . $sidebar_id . '" class="' . $class . '" role="complementary">';1039 $first_sidebar = ic_get_theme_primary_sidebar();1040 dynamic_sidebar( $first_sidebar );1041 echo '</div>';1036 $sidebar_id = apply_filters( 'catalog_default_sidebar_id', 'catalog_sidebar' ); 1037 $class = apply_filters( 'catalog_default_sidebar_class', 'catalog_sidebar' ); 1038 echo '<div id="' . $sidebar_id . '" class="' . $class . '" role="complementary">'; 1039 $first_sidebar = ic_get_theme_primary_sidebar(); 1040 dynamic_sidebar( $first_sidebar ); 1041 echo '</div>'; 1042 1042 } 1043 1043 1044 1044 function ic_get_theme_primary_sidebar() { 1045 $registered_sidebars = $GLOBALS['wp_registered_sidebars'];1046 unset( $registered_sidebars['product_sort_bar'] );1047 foreach ( $registered_sidebars as $sidebar_name => $sidebar ) {1048 if ( ic_string_contains( $sidebar['name'], 'primary' ) || ic_string_contains( $sidebar['name'], 'Primary' ) ) {1049 $first_sidebar = $sidebar_name;1050 break;1051 }1052 }1053 if ( ! isset( $first_sidebar ) ) {1054 reset( $registered_sidebars );1055 $first_sidebar = key( $registered_sidebars );1056 }1057 1058 return apply_filters( 'advanced_mode_sidebar_name', $first_sidebar, $registered_sidebars );1045 $registered_sidebars = $GLOBALS['wp_registered_sidebars']; 1046 unset( $registered_sidebars['product_sort_bar'] ); 1047 foreach ( $registered_sidebars as $sidebar_name => $sidebar ) { 1048 if ( ic_string_contains( $sidebar['name'], 'primary' ) || ic_string_contains( $sidebar['name'], 'Primary' ) ) { 1049 $first_sidebar = $sidebar_name; 1050 break; 1051 } 1052 } 1053 if ( ! isset( $first_sidebar ) ) { 1054 reset( $registered_sidebars ); 1055 $first_sidebar = key( $registered_sidebars ); 1056 } 1057 1058 return apply_filters( 'advanced_mode_sidebar_name', $first_sidebar, $registered_sidebars ); 1059 1059 } 1060 1060 … … 1069 1069 */ 1070 1070 function get_related_products( $products_limit = null, $markup = false, $product_id = null ) { 1071 if ( ! isset( $products_limit ) ) {1072 $products_limit = apply_filters( 'related_products_count', get_current_per_row() );1073 }1074 if ( ! empty( $product_id ) ) {1075 $current_product_id = intval( $product_id );1076 }1077 if ( empty( $current_product_id ) ) {1078 $current_product_id = ic_get_product_id();1079 }1080 $taxonomy = apply_filters( 'ic_cat_related_products_tax', get_current_screen_tax() );1081 $post_type = get_current_screen_post_type();1082 $terms = ic_get_product_categories( $current_product_id );1083 if ( is_array( $terms ) && ! empty( $taxonomy ) && ! empty( $post_type ) ) {1084 $terms = apply_filters( 'ic_catalog_related_product_terms', array_reverse( $terms ), $current_product_id );1085 //$archive_template = get_product_listing_template();1086 $i = 0;1087 //$inside = '';1088 $products = array();1089 foreach ( $terms as $term ) {1090 $query_param = array(1091 'post_type' => $post_type,1092 'orderby' => 'rand',1093 'tax_query' => array(1094 array(1095 'taxonomy' => $taxonomy,1096 'field' => 'slug',1097 'terms' => $term->slug,1098 ),1099 ),1100 'posts_per_page' => $products_limit * 2,1101 );1102 $query = new WP_Query( $query_param );1103 while ( $query->have_posts() ) : $query->the_post();1104 global $post;1105 if ( $current_product_id != $post->ID ) {1106 $i ++;1107 $products[] = $post->ID;1108 }1109 if ( $i >= $products_limit ) {1110 break;1111 }1112 //ic_delete_global( 'product_id' );1113 endwhile;1114 wp_reset_postdata();1115 reset_row_class();1116 if ( $i >= $products_limit ) {1117 break;1118 }1119 }1120 $div = '';1121 if ( ! empty( $products ) ) {1122 $products = apply_filters( 'ic_cat_related_products', implode( ',', $products ), $products_limit );1123 ic_save_global( 'current_related_products', $products );1124 remove_filter( 'shortcode_query', 'set_shortcode_product_order', 10, 2 );1125 if ( $markup ) {1126 ob_start();1127 ic_show_template_file( 'product-page/related-products.php' );1128 $div = ob_get_clean();1129 } else {1130 $div = do_shortcode( '[show_products post_type="' . $post_type . '" product="' . $products . '"]' );1131 }1132 add_filter( 'shortcode_query', 'set_shortcode_product_order', 10, 2 );1133 }1134 1135 return $div;1136 }1137 1138 return;1071 if ( ! isset( $products_limit ) ) { 1072 $products_limit = apply_filters( 'related_products_count', get_current_per_row() ); 1073 } 1074 if ( ! empty( $product_id ) ) { 1075 $current_product_id = intval( $product_id ); 1076 } 1077 if ( empty( $current_product_id ) ) { 1078 $current_product_id = ic_get_product_id(); 1079 } 1080 $taxonomy = apply_filters( 'ic_cat_related_products_tax', get_current_screen_tax() ); 1081 $post_type = get_current_screen_post_type(); 1082 $terms = ic_get_product_categories( $current_product_id ); 1083 if ( is_array( $terms ) && ! empty( $taxonomy ) && ! empty( $post_type ) ) { 1084 $terms = apply_filters( 'ic_catalog_related_product_terms', array_reverse( $terms ), $current_product_id ); 1085 //$archive_template = get_product_listing_template(); 1086 $i = 0; 1087 //$inside = ''; 1088 $products = array(); 1089 foreach ( $terms as $term ) { 1090 $query_param = array( 1091 'post_type' => $post_type, 1092 'orderby' => 'rand', 1093 'tax_query' => array( 1094 array( 1095 'taxonomy' => $taxonomy, 1096 'field' => 'slug', 1097 'terms' => $term->slug, 1098 ), 1099 ), 1100 'posts_per_page' => $products_limit * 2, 1101 ); 1102 $query = new WP_Query( $query_param ); 1103 while ( $query->have_posts() ) : $query->the_post(); 1104 global $post; 1105 if ( $current_product_id != $post->ID ) { 1106 $i ++; 1107 $products[] = $post->ID; 1108 } 1109 if ( $i >= $products_limit ) { 1110 break; 1111 } 1112 //ic_delete_global( 'product_id' ); 1113 endwhile; 1114 wp_reset_postdata(); 1115 reset_row_class(); 1116 if ( $i >= $products_limit ) { 1117 break; 1118 } 1119 } 1120 $div = ''; 1121 if ( ! empty( $products ) ) { 1122 $products = apply_filters( 'ic_cat_related_products', implode( ',', $products ), $products_limit ); 1123 ic_save_global( 'current_related_products', $products ); 1124 remove_filter( 'shortcode_query', 'set_shortcode_product_order', 10, 2 ); 1125 if ( $markup ) { 1126 ob_start(); 1127 ic_show_template_file( 'product-page/related-products.php' ); 1128 $div = ob_get_clean(); 1129 } else { 1130 $div = do_shortcode( '[show_products post_type="' . $post_type . '" product="' . $products . '"]' ); 1131 } 1132 add_filter( 'shortcode_query', 'set_shortcode_product_order', 10, 2 ); 1133 } 1134 1135 return $div; 1136 } 1137 1138 return; 1139 1139 } 1140 1140 1141 1141 function ic_get_product_categories( $product_id, $taxonomy = null, $args = null ) { 1142 if ( empty( $taxonomy ) ) {1143 $taxonomy = apply_filters( 'ic_cat_related_products_tax', get_current_screen_tax() );1144 }1145 $terms = get_the_terms( $product_id, $taxonomy );1146 1147 return $terms;1142 if ( empty( $taxonomy ) ) { 1143 $taxonomy = apply_filters( 'ic_cat_related_products_tax', get_current_screen_tax() ); 1144 } 1145 $terms = get_the_terms( $product_id, $taxonomy ); 1146 1147 return $terms; 1148 1148 } 1149 1149 … … 1156 1156 */ 1157 1157 function ic_add_product_category_image( $term_id ) { 1158 if ( is_ic_category_image_enabled() ) {1159 ic_save_global( 'current_product_category_id', $term_id );1160 ic_show_template_file( 'product-listing/category-image.php' );1161 }1158 if ( is_ic_category_image_enabled() ) { 1159 ic_save_global( 'current_product_category_id', $term_id ); 1160 ic_show_template_file( 'product-listing/category-image.php' ); 1161 } 1162 1162 } 1163 1163 … … 1169 1169 */ 1170 1170 function ic_add_product_category_description() { 1171 add_filter( 'ic_product_cat_desc', 'wptexturize' );1172 add_filter( 'ic_product_cat_desc', 'convert_smilies' );1173 add_filter( 'ic_product_cat_desc', 'convert_chars' );1174 add_filter( 'ic_product_cat_desc', 'wpautop' );1175 add_filter( 'ic_product_cat_desc', 'shortcode_unautop' );1176 add_filter( 'ic_product_cat_desc', 'do_shortcode', 11 );1177 ic_show_template_file( 'product-listing/category-description.php' );1171 add_filter( 'ic_product_cat_desc', 'wptexturize' ); 1172 add_filter( 'ic_product_cat_desc', 'convert_smilies' ); 1173 add_filter( 'ic_product_cat_desc', 'convert_chars' ); 1174 add_filter( 'ic_product_cat_desc', 'wpautop' ); 1175 add_filter( 'ic_product_cat_desc', 'shortcode_unautop' ); 1176 add_filter( 'ic_product_cat_desc', 'do_shortcode', 11 ); 1177 ic_show_template_file( 'product-listing/category-description.php' ); 1178 1178 } 1179 1179 … … 1187 1187 */ 1188 1188 function ic_product_listing_categories( $archive_template, $multiple_settings ) { 1189 $taxonomy_name = apply_filters( 'current_product_catalog_taxonomy', 'al_product-cat' );1190 if ( ! is_tax() && ! is_search() ) {1191 $before_archive = content_product_adder_archive_before();1192 if ( $before_archive != '<div class="entry-summary"></div>' ) {1193 echo $before_archive;1194 }1195 if ( $multiple_settings['product_listing_cats'] == 'on' || $multiple_settings['product_listing_cats'] == 'cats_only' || $multiple_settings['product_listing_cats'] == 'forced_cats_only' ) {1196 1197 if ( $multiple_settings['cat_template'] != 'template' ) {1198 $product_subcategories = wp_list_categories( 'show_option_none=No_cat&echo=0&title_li=&taxonomy=' . $taxonomy_name . '&parent=0' );1199 if ( ! strpos( $product_subcategories, 'No_cat' ) ) {1200 do_action( 'before_product_listing_category_list' );1201 ic_save_global( 'current_product_categories', $product_subcategories );1202 ic_save_global( 'current_product_archive_template', get_product_listing_template() );1203 ic_show_template_file( 'product-listing/categories-listing.php' );1204 }1205 } else {1206 $show_categories = do_shortcode( '[show_categories parent="0" shortcode_query="no"]' );1207 if ( ! empty( $show_categories ) ) {1208 do_action( 'before_product_listing_category_list' );1209 echo $show_categories;1210 if ( $archive_template != 'list' && more_products() && $multiple_settings['product_listing_cats'] !== 'forced_cats_only'/* && !is_ic_only_main_cats() */ ) {1211 echo '<hr>';1212 }1213 }1214 }1215 }1216 } else if ( is_tax() ) {1217 $term = ic_get_queried_object();1218 if ( empty( $term->term_id ) ) {1219 return;1220 }1221 if ( current_filter() === 'product_listing_entry_inside' ) {1222 if ( has_shortcode( $term->description, 'product_listing_products' ) ) {1223 remove_action( 'product_listing_entry_inside', 'ic_product_listing_products', 20, 2 );1224 add_action( 'after_product_list', 'product_archive_pagination', 99, 0 );1225 remove_action( 'product_listing_end', 'product_archive_pagination' );1226 }1227 do_action( 'product_category_page_start', $term->term_id );1228 1229 if ( has_shortcode( $term->description, 'product_listing_categories' ) ) {1230 return;1231 }1232 }1233 if ( $multiple_settings['category_top_cats'] == 'on' || $multiple_settings['category_top_cats'] == 'only_subcategories' ) {1234 if ( $multiple_settings['cat_template'] != 'template' ) {1235 $product_subcategories = wp_list_categories( 'show_option_none=No_cat&echo=0&title_li=&taxonomy=' . $taxonomy_name . '&child_of=' . $term->term_id );1236 if ( ! strpos( $product_subcategories, 'No_cat' ) ) {1237 do_action( 'before_category_subcategories' );1238 ic_save_global( 'current_product_categories', $product_subcategories );1239 ic_save_global( 'current_product_archive_template', get_product_listing_template() );1240 ic_show_template_file( 'product-listing/categories-listing.php' );1241 }1242 } else {1243 $show_categories = do_shortcode( '[show_categories parent=' . get_queried_object_id() . ' shortcode_query=no]' );1244 if ( ! empty( $show_categories ) ) {1245 do_action( 'before_category_subcategories' );1246 echo $show_categories;1247 if ( $archive_template != 'list' && more_products() /* && !is_ic_only_main_cats() */ ) {1248 echo '<hr>';1249 }1250 }1251 }1252 }1253 }1189 $taxonomy_name = apply_filters( 'current_product_catalog_taxonomy', 'al_product-cat' ); 1190 if ( ! is_tax() && ! is_search() ) { 1191 $before_archive = content_product_adder_archive_before(); 1192 if ( $before_archive != '<div class="entry-summary"></div>' ) { 1193 echo $before_archive; 1194 } 1195 if ( $multiple_settings['product_listing_cats'] == 'on' || $multiple_settings['product_listing_cats'] == 'cats_only' || $multiple_settings['product_listing_cats'] == 'forced_cats_only' ) { 1196 1197 if ( $multiple_settings['cat_template'] != 'template' ) { 1198 $product_subcategories = wp_list_categories( 'show_option_none=No_cat&echo=0&title_li=&taxonomy=' . $taxonomy_name . '&parent=0' ); 1199 if ( ! strpos( $product_subcategories, 'No_cat' ) ) { 1200 do_action( 'before_product_listing_category_list' ); 1201 ic_save_global( 'current_product_categories', $product_subcategories ); 1202 ic_save_global( 'current_product_archive_template', get_product_listing_template() ); 1203 ic_show_template_file( 'product-listing/categories-listing.php' ); 1204 } 1205 } else { 1206 $show_categories = do_shortcode( '[show_categories parent="0" shortcode_query="no"]' ); 1207 if ( ! empty( $show_categories ) ) { 1208 do_action( 'before_product_listing_category_list' ); 1209 echo $show_categories; 1210 if ( $archive_template != 'list' && more_products() && $multiple_settings['product_listing_cats'] !== 'forced_cats_only'/* && !is_ic_only_main_cats() */ ) { 1211 echo '<hr>'; 1212 } 1213 } 1214 } 1215 } 1216 } else if ( is_tax() ) { 1217 $term = ic_get_queried_object(); 1218 if ( empty( $term->term_id ) ) { 1219 return; 1220 } 1221 if ( current_filter() === 'product_listing_entry_inside' ) { 1222 if ( has_shortcode( $term->description, 'product_listing_products' ) ) { 1223 remove_action( 'product_listing_entry_inside', 'ic_product_listing_products', 20, 2 ); 1224 add_action( 'after_product_list', 'product_archive_pagination', 99, 0 ); 1225 remove_action( 'product_listing_end', 'product_archive_pagination' ); 1226 } 1227 do_action( 'product_category_page_start', $term->term_id ); 1228 1229 if ( has_shortcode( $term->description, 'product_listing_categories' ) ) { 1230 return; 1231 } 1232 } 1233 if ( $multiple_settings['category_top_cats'] == 'on' || $multiple_settings['category_top_cats'] == 'only_subcategories' ) { 1234 if ( $multiple_settings['cat_template'] != 'template' ) { 1235 $product_subcategories = wp_list_categories( 'show_option_none=No_cat&echo=0&title_li=&taxonomy=' . $taxonomy_name . '&child_of=' . $term->term_id ); 1236 if ( ! strpos( $product_subcategories, 'No_cat' ) ) { 1237 do_action( 'before_category_subcategories' ); 1238 ic_save_global( 'current_product_categories', $product_subcategories ); 1239 ic_save_global( 'current_product_archive_template', get_product_listing_template() ); 1240 ic_show_template_file( 'product-listing/categories-listing.php' ); 1241 } 1242 } else { 1243 $show_categories = do_shortcode( '[show_categories parent=' . get_queried_object_id() . ' shortcode_query=no]' ); 1244 if ( ! empty( $show_categories ) ) { 1245 do_action( 'before_category_subcategories' ); 1246 echo $show_categories; 1247 if ( $archive_template != 'list' && more_products() /* && !is_ic_only_main_cats() */ ) { 1248 echo '<hr>'; 1249 } 1250 } 1251 } 1252 } 1253 } 1254 1254 } 1255 1255 … … 1263 1263 */ 1264 1264 function ic_product_listing_products( $archive_template, $multiple_settings ) { 1265 global $ic_is_home;1266 if ( ! is_ic_ajax() && ( is_ic_product_listing() || ! is_ic_catalog_page() ) && $multiple_settings['product_listing_cats'] == 'forced_cats_only' ) {1267 return;1268 }1269 1270 if ( is_home_archive() || ( ! more_products() && ( is_custom_product_listing_page() || ( ! is_ic_catalog_page() && ic_get_global( 'inside_show_catalog_shortcode' ) && ! is_ic_only_main_cats() ) ) ) ) {1271 $catalog_query = ic_set_home_listing_query();1272 if ( ! empty( $catalog_query ) ) {1273 global $wp_query;1274 $wp_query = $catalog_query;1275 1276 }1277 $ic_is_home = 1;1278 }1279 global $wp_query;1280 if ( /* (!is_ic_only_main_cats() || is_search() || is_product_filters_active() || is_ic_ajax() ) && */ more_products() ) {1281 do_action( 'before_product_list', $archive_template, $multiple_settings );1282 $product_list = '';1283 while ( have_posts() ) : the_post();1284 $post = get_post();1285 if ( empty( $post->ID ) ) {1286 1287 continue;1288 }1289 ic_set_product_id( $post->ID );1290 $product_list .= get_catalog_template( $archive_template, $post );1291 ic_reset_product_id();1292 endwhile;1293 $product_list = apply_filters( 'product_list_ready', $product_list, $archive_template, 'auto_listing' );1294 echo '<div class="product-list ' . $archive_template . ' ' . product_list_class( $archive_template ) . '" ' . product_list_attr() . '>' . $product_list . '</div>';1295 do_action( 'after_product_list', $archive_template, $multiple_settings );1296 add_action( 'product_listing_end', 'ic_product_clear_span', 99 );1297 } else if ( ( ! is_product_filters_active() && is_search() ) && ! more_products() ) {1298 do_action( 'ic_before_empty_search', $archive_template, $multiple_settings );1299 ob_start();1300 $notfound_text = __( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'ecommerce-product-catalog' );1301 echo '<div class="product-list ' . product_list_class( $archive_template ) . '"><p>' . apply_filters( 'ic_catalog_not_found_message', $notfound_text ) . '</p></div>';1302 product_search_form();1303 echo apply_filters( 'ic_catalog_not_found_content', ob_get_clean() );1304 } else if ( is_product_filters_active() && ! more_products() ) {1305 show_product_sort_bar();1306 $notfound_filters_text = sprintf( __( 'Sorry, but nothing matched your search terms. Please try again with some different options or %sreset filters%s.', 'ecommerce-product-catalog' ), '<a href="' . esc_url( get_filters_bar_reset_url() ) . '">', '</a>' );1307 echo '<div class="product-list ' . product_list_class( $archive_template ) . '"><p>' . apply_filters( 'ic_catalog_not_found_filters_message', $notfound_filters_text ) . '</p></div>';1308 } else if ( ! more_products() && ! ic_is_rendering_catalog_block() && ! is_ic_admin() && ( ! is_ic_only_main_cats() || ( is_ic_taxonomy_page() && ! has_category_children() ) ) ) {1309 echo ic_empty_list_text();1310 }1265 global $ic_is_home; 1266 if ( ! is_ic_ajax() && ( is_ic_product_listing() || ! is_ic_catalog_page() ) && $multiple_settings['product_listing_cats'] == 'forced_cats_only' ) { 1267 return; 1268 } 1269 1270 if ( is_home_archive() || ( ! more_products() && ( is_custom_product_listing_page() || ( ! is_ic_catalog_page() && ic_get_global( 'inside_show_catalog_shortcode' ) && ! is_ic_only_main_cats() ) ) ) ) { 1271 $catalog_query = ic_set_home_listing_query(); 1272 if ( ! empty( $catalog_query ) ) { 1273 global $wp_query; 1274 $wp_query = $catalog_query; 1275 1276 } 1277 $ic_is_home = 1; 1278 } 1279 global $wp_query; 1280 if ( /* (!is_ic_only_main_cats() || is_search() || is_product_filters_active() || is_ic_ajax() ) && */ more_products() ) { 1281 do_action( 'before_product_list', $archive_template, $multiple_settings ); 1282 $product_list = ''; 1283 while ( have_posts() ) : the_post(); 1284 $post = get_post(); 1285 if ( empty( $post->ID ) ) { 1286 1287 continue; 1288 } 1289 ic_set_product_id( $post->ID ); 1290 $product_list .= get_catalog_template( $archive_template, $post ); 1291 ic_reset_product_id(); 1292 endwhile; 1293 $product_list = apply_filters( 'product_list_ready', $product_list, $archive_template, 'auto_listing' ); 1294 echo '<div class="product-list ' . $archive_template . ' ' . product_list_class( $archive_template ) . '" ' . product_list_attr() . '>' . $product_list . '</div>'; 1295 do_action( 'after_product_list', $archive_template, $multiple_settings ); 1296 add_action( 'product_listing_end', 'ic_product_clear_span', 99 ); 1297 } else if ( ( ! is_product_filters_active() && is_search() ) && ! more_products() ) { 1298 do_action( 'ic_before_empty_search', $archive_template, $multiple_settings ); 1299 ob_start(); 1300 $notfound_text = __( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'ecommerce-product-catalog' ); 1301 echo '<div class="product-list ' . product_list_class( $archive_template ) . '"><p>' . apply_filters( 'ic_catalog_not_found_message', $notfound_text ) . '</p></div>'; 1302 product_search_form(); 1303 echo apply_filters( 'ic_catalog_not_found_content', ob_get_clean() ); 1304 } else if ( is_product_filters_active() && ! more_products() ) { 1305 show_product_sort_bar(); 1306 $notfound_filters_text = sprintf( __( 'Sorry, but nothing matched your search terms. Please try again with some different options or %sreset filters%s.', 'ecommerce-product-catalog' ), '<a href="' . esc_url( get_filters_bar_reset_url() ) . '">', '</a>' ); 1307 echo '<div class="product-list ' . product_list_class( $archive_template ) . '"><p>' . apply_filters( 'ic_catalog_not_found_filters_message', $notfound_filters_text ) . '</p></div>'; 1308 } else if ( ! more_products() && ! ic_is_rendering_catalog_block() && ! is_ic_admin() && ( ! is_ic_only_main_cats() || ( is_ic_taxonomy_page() && ! has_category_children() ) ) ) { 1309 echo ic_empty_list_text(); 1310 } 1311 1311 1312 1312 } 1313 1313 1314 1314 function ic_home_listing_query_args() { 1315 $args = ic_get_global( 'home_listing_query_args' );1316 if ( $args !== false ) {1317 return $args;1318 }1319 $multiple_settings = get_multiple_settings();1320 if ( get_query_var( 'paged' ) ) {1321 $paged = get_query_var( 'paged' );1322 } elseif ( get_query_var( 'page' ) ) {1323 $paged = get_query_var( 'page' );1324 } else {1325 $paged = 1;1326 }1327 $args = apply_filters( 'home_product_listing_query', array(1328 'post_status' => ic_visible_product_status(),1329 'post_type' => 'al_product',1330 'posts_per_page' => isset( $multiple_settings['archive_products_limit'] ) ? $multiple_settings['archive_products_limit'] : 12,1331 'paged' => $paged1332 ) );1333 ic_save_global( 'home_listing_query_args', $args );1334 1335 return $args;1315 $args = ic_get_global( 'home_listing_query_args' ); 1316 if ( $args !== false ) { 1317 return $args; 1318 } 1319 $multiple_settings = get_multiple_settings(); 1320 if ( get_query_var( 'paged' ) ) { 1321 $paged = get_query_var( 'paged' ); 1322 } elseif ( get_query_var( 'page' ) ) { 1323 $paged = get_query_var( 'page' ); 1324 } else { 1325 $paged = 1; 1326 } 1327 $args = apply_filters( 'home_product_listing_query', array( 1328 'post_status' => ic_visible_product_status(), 1329 'post_type' => 'al_product', 1330 'posts_per_page' => isset( $multiple_settings['archive_products_limit'] ) ? $multiple_settings['archive_products_limit'] : 12, 1331 'paged' => $paged 1332 ) ); 1333 ic_save_global( 'home_listing_query_args', $args ); 1334 1335 return $args; 1336 1336 } 1337 1337 1338 1338 function ic_set_home_listing_query() { 1339 $args = ic_home_listing_query_args();1340 if ( ! empty( $args ) ) {1341 $catalog_query = apply_filters( 'ic_home_query', '', $args );1342 if ( empty( $catalog_query ) ) {1343 $cache_meta = 'ic_home_listing_query_' . serialize( array_values( $args ) );1344 $catalog_query = ic_get_global( $cache_meta );1345 if ( $catalog_query !== false ) {1346 return $catalog_query;1347 }1348 do_action( 'ic_before_home_listing_query' );1349 $catalog_query = new WP_Query( $args );1350 do_action( 'ic_after_home_listing_query' );1351 1352 if ( ! empty( $args['is_archive'] ) ) {1353 $catalog_query->is_post_type_archive = true;1354 }1355 ic_save_global( $cache_meta, $catalog_query );1356 }1357 1358 return $catalog_query;1359 }1360 1361 return false;1339 $args = ic_home_listing_query_args(); 1340 if ( ! empty( $args ) ) { 1341 $catalog_query = apply_filters( 'ic_home_query', '', $args ); 1342 if ( empty( $catalog_query ) ) { 1343 $cache_meta = 'ic_home_listing_query_' . serialize( array_values( $args ) ); 1344 $catalog_query = ic_get_global( $cache_meta ); 1345 if ( $catalog_query !== false ) { 1346 return $catalog_query; 1347 } 1348 do_action( 'ic_before_home_listing_query' ); 1349 $catalog_query = new WP_Query( $args ); 1350 do_action( 'ic_after_home_listing_query' ); 1351 1352 if ( ! empty( $args['is_archive'] ) ) { 1353 $catalog_query->is_post_type_archive = true; 1354 } 1355 ic_save_global( $cache_meta, $catalog_query ); 1356 } 1357 1358 return $catalog_query; 1359 } 1360 1361 return false; 1362 1362 } 1363 1363 1364 1364 function ic_product_clear_span() { 1365 ?>1365 ?> 1366 1366 <span class="clear"></span> 1367 <?php1367 <?php 1368 1368 1369 1369 } … … 1377 1377 */ 1378 1378 function ic_reset_home_listing_query() { 1379 global $ic_is_home;1380 if ( isset( $ic_is_home ) && $ic_is_home == 1 ) {1381 wp_reset_query();1382 }1379 global $ic_is_home; 1380 if ( isset( $ic_is_home ) && $ic_is_home == 1 ) { 1381 wp_reset_query(); 1382 } 1383 1383 } 1384 1384 … … 1386 1386 1387 1387 function ic_catalog_page_body_class( $classes ) { 1388 if ( is_ic_catalog_page() ) { 1389 $classes[] = 'ecommerce-product-catalog'; 1390 if ( ! is_ic_theme_mode() ) { 1391 $classes[] = 'type-page'; 1392 $classes[] = 'page'; 1393 $listing_id = intval( get_product_listing_id() ); 1394 $template_slug = apply_filters( 'ic_catalog_page_template', get_page_template_slug( $listing_id ) ); 1395 if ( ! empty( $template_slug ) ) { 1396 $classes[] = "page-template"; 1397 $template_parts = explode( '/', $template_slug ); 1398 foreach ( $template_parts as $part ) { 1399 $classes[] = "page-template-" . sanitize_html_class( str_replace( array( 1400 '.', 1401 '/' 1402 ), '-', basename( $part, '.php' ) ) ); 1403 } 1404 $classes[] = "page-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); 1405 } else { 1406 $classes[] = "page-template-default"; 1407 } 1408 } 1409 } 1410 1411 return $classes; 1388 if ( is_ic_catalog_page() ) { 1389 $classes[] = 'ecommerce-product-catalog'; 1390 if ( is_ic_product_listing() ) { 1391 $classes[] = 'main-catalog-page'; 1392 } 1393 if ( ! is_ic_theme_mode() ) { 1394 $classes[] = 'type-page'; 1395 $classes[] = 'page'; 1396 $listing_id = intval( get_product_listing_id() ); 1397 $template_slug = apply_filters( 'ic_catalog_page_template', get_page_template_slug( $listing_id ) ); 1398 if ( ! empty( $template_slug ) ) { 1399 $classes[] = "page-template"; 1400 $template_parts = explode( '/', $template_slug ); 1401 foreach ( $template_parts as $part ) { 1402 $classes[] = "page-template-" . sanitize_html_class( str_replace( array( 1403 '.', 1404 '/' 1405 ), '-', basename( $part, '.php' ) ) ); 1406 } 1407 $classes[] = "page-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); 1408 } else { 1409 $classes[] = "page-template-default"; 1410 } 1411 } 1412 } 1413 1414 return $classes; 1412 1415 } 1413 1416 … … 1415 1418 1416 1419 function ic_catalog_product_page_body_class( $body_class ) { 1417 $product_id = ic_get_product_id();1418 $body_class[] = 'single-product-page';1419 $terms = wp_get_post_terms( $product_id, 'al_product-cat', array( "fields" => "ids", "orderby" => "none" ) );1420 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {1421 foreach ( $terms as $term_id ) {1422 $body_class[] = 'product-category-' . $term_id;1423 $parent_terms = ic_get_parent_terms( $term_id );1424 if ( ! empty( $parent_terms ) ) {1425 foreach ( $parent_terms as $parent_term_id ) {1426 $body_class[] = 'parent-product-category-' . $parent_term_id;1427 }1428 }1429 }1430 }1431 1432 return $body_class;1420 $product_id = ic_get_product_id(); 1421 $body_class[] = 'single-product-page'; 1422 $terms = wp_get_post_terms( $product_id, 'al_product-cat', array( "fields" => "ids", "orderby" => "none" ) ); 1423 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { 1424 foreach ( $terms as $term_id ) { 1425 $body_class[] = 'product-category-' . $term_id; 1426 $parent_terms = ic_get_parent_terms( $term_id ); 1427 if ( ! empty( $parent_terms ) ) { 1428 foreach ( $parent_terms as $parent_term_id ) { 1429 $body_class[] = 'parent-product-category-' . $parent_term_id; 1430 } 1431 } 1432 } 1433 } 1434 1435 return $body_class; 1433 1436 } 1434 1437 … … 1436 1439 1437 1440 function ic_catalog_product_category_body_class( $body_class ) { 1438 $term_id = ic_get_current_category_id();1439 if ( empty( $term_id ) ) {1440 return $body_class;1441 }1442 $term = get_term( $term_id );1443 if ( ! is_wp_error( $term ) ) {1444 $body_class[] = 'product-category-page';1445 $body_class[] = 'product-category-page-' . $term_id;1446 }1447 if ( ! empty( $term->parent ) ) {1448 $terms = array( $term->parent );1449 foreach ( $terms as $term_id ) {1450 $body_class[] = 'product-category-page-parent-' . $term_id;1451 $parent_terms = ic_get_parent_terms( $term_id );1452 if ( ! empty( $parent_terms ) ) {1453 foreach ( $parent_terms as $parent_term_id ) {1454 $body_class[] = 'product-category-page-parent-' . $parent_term_id;1455 }1456 }1457 }1458 }1459 1460 return $body_class;1441 $term_id = ic_get_current_category_id(); 1442 if ( empty( $term_id ) ) { 1443 return $body_class; 1444 } 1445 $term = get_term( $term_id ); 1446 if ( ! is_wp_error( $term ) ) { 1447 $body_class[] = 'product-category-page'; 1448 $body_class[] = 'product-category-page-' . $term_id; 1449 } 1450 if ( ! empty( $term->parent ) ) { 1451 $terms = array( $term->parent ); 1452 foreach ( $terms as $term_id ) { 1453 $body_class[] = 'product-category-page-parent-' . $term_id; 1454 $parent_terms = ic_get_parent_terms( $term_id ); 1455 if ( ! empty( $parent_terms ) ) { 1456 foreach ( $parent_terms as $parent_term_id ) { 1457 $body_class[] = 'product-category-page-parent-' . $parent_term_id; 1458 } 1459 } 1460 } 1461 } 1462 1463 return $body_class; 1461 1464 } 1462 1465 1463 1466 function ic_get_parent_terms( $term_id ) { 1464 $term = get_term( $term_id );1465 if ( ! empty( $term->parent ) ) {1466 $term_ids = array( $term->parent );1467 $parent_term = ic_get_parent_terms( $term->parent );1468 if ( ! empty( $parent_term ) ) {1469 $term_ids = array_merge( $term_ids, $parent_term );1470 }1471 1472 return array_unique( $term_ids );1473 }1474 1475 return array();1467 $term = get_term( $term_id ); 1468 if ( ! empty( $term->parent ) ) { 1469 $term_ids = array( $term->parent ); 1470 $parent_term = ic_get_parent_terms( $term->parent ); 1471 if ( ! empty( $parent_term ) ) { 1472 $term_ids = array_merge( $term_ids, $parent_term ); 1473 } 1474 1475 return array_unique( $term_ids ); 1476 } 1477 1478 return array(); 1476 1479 } 1477 1480 1478 1481 if ( ! function_exists( 'ic_get_template_file' ) ) { 1479 1482 1480 /**1481 * Manages template files paths1482 *1483 * @param type $file_path1484 *1485 * @return type1486 */1487 function ic_get_template_file( $file_path, $base_path = AL_BASE_TEMPLATES_PATH, $product_id = false ) {1488 if ( empty( $base_path ) ) {1489 $base_path = AL_BASE_TEMPLATES_PATH;1490 }1491 $folder = get_custom_templates_folder();1492 $file_path = apply_filters( 'ic_template_file_path', $file_path, $product_id );1493 $base_path = apply_filters( 'ic_template_file_base_path', $base_path, $file_path );1494 $file_name = basename( $file_path );1495 if ( file_exists( $folder . $file_name ) ) {1496 return $folder . $file_name;1497 } else if ( file_exists( $base_path . '/templates/template-parts/' . $file_path ) ) {1498 return $base_path . '/templates/template-parts/' . $file_path;1499 } else {1500 return false;1501 }1502 }1483 /** 1484 * Manages template files paths 1485 * 1486 * @param type $file_path 1487 * 1488 * @return type 1489 */ 1490 function ic_get_template_file( $file_path, $base_path = AL_BASE_TEMPLATES_PATH, $product_id = false ) { 1491 if ( empty( $base_path ) ) { 1492 $base_path = AL_BASE_TEMPLATES_PATH; 1493 } 1494 $folder = get_custom_templates_folder(); 1495 $file_path = apply_filters( 'ic_template_file_path', $file_path, $product_id ); 1496 $base_path = apply_filters( 'ic_template_file_base_path', $base_path, $file_path ); 1497 $file_name = basename( $file_path ); 1498 if ( file_exists( $folder . $file_name ) ) { 1499 return $folder . $file_name; 1500 } else if ( file_exists( $base_path . '/templates/template-parts/' . $file_path ) ) { 1501 return $base_path . '/templates/template-parts/' . $file_path; 1502 } else { 1503 return false; 1504 } 1505 } 1503 1506 1504 1507 } … … 1506 1509 if ( ! function_exists( 'ic_show_template_file' ) ) { 1507 1510 1508 /**1509 * Includes template file1510 *1511 * @param type $file_path1512 *1513 * @return type1514 */1515 function ic_show_template_file( $file_path, $base_path = AL_BASE_TEMPLATES_PATH, $product_id = false ) {1516 $path = ic_get_template_file( $file_path, $base_path, $product_id );1517 if ( $path ) {1518 ic_enqueue_main_catalog_js_css();1519 if ( $product_id ) {1520 $prev_id = ic_get_global( 'product_id' );1521 if ( $prev_id !== $product_id && is_ic_product( $product_id ) ) {1522 ic_save_global( 'product_id', $product_id, false, false, true );1523 }1524 }1525 include $path;1526 if ( $product_id && isset( $prev_id ) ) {1527 //$prev_id = isset( $prev_id ) ? $prev_id : null;1528 if ( $prev_id && $prev_id !== $product_id && is_ic_product( $prev_id ) ) {1529 ic_save_global( 'product_id', $prev_id, false, false, true );1530 } else if ( $prev_id === false ) {1531 ic_delete_global( 'product_id' );1532 }1533 }1534 }1535 1536 return;1537 }1511 /** 1512 * Includes template file 1513 * 1514 * @param type $file_path 1515 * 1516 * @return type 1517 */ 1518 function ic_show_template_file( $file_path, $base_path = AL_BASE_TEMPLATES_PATH, $product_id = false ) { 1519 $path = ic_get_template_file( $file_path, $base_path, $product_id ); 1520 if ( $path ) { 1521 ic_enqueue_main_catalog_js_css(); 1522 if ( $product_id ) { 1523 $prev_id = ic_get_global( 'product_id' ); 1524 if ( $prev_id !== $product_id && is_ic_product( $product_id ) ) { 1525 ic_save_global( 'product_id', $product_id, false, false, true ); 1526 } 1527 } 1528 include $path; 1529 if ( $product_id && isset( $prev_id ) ) { 1530 //$prev_id = isset( $prev_id ) ? $prev_id : null; 1531 if ( $prev_id && $prev_id !== $product_id && is_ic_product( $prev_id ) ) { 1532 ic_save_global( 'product_id', $prev_id, false, false, true ); 1533 } else if ( $prev_id === false ) { 1534 ic_delete_global( 'product_id' ); 1535 } 1536 } 1537 } 1538 1539 return; 1540 } 1538 1541 1539 1542 } … … 1542 1545 1543 1546 function ic_catalog_archive_title( $title ) { 1544 if ( is_ic_taxonomy_page() ) {1545 $title = single_term_title( '', false );1546 } else if ( is_ic_product_listing() ) {1547 $title = post_type_archive_title( '', false );1548 }1549 1550 return $title;1551 } 1547 if ( is_ic_taxonomy_page() ) { 1548 $title = single_term_title( '', false ); 1549 } else if ( is_ic_product_listing() ) { 1550 $title = post_type_archive_title( '', false ); 1551 } 1552 1553 return $title; 1554 }
Note: See TracChangeset
for help on using the changeset viewer.