*/ class IS_Ajax { /** * Core singleton class * @var self */ private static $_instance; /** * Initializes this class */ public function __construct() { } /** * Gets the instance of this class. * * @return self */ public static function getInstance() { if ( ! ( self::$_instance instanceof self ) ) { self::$_instance = new self(); } return self::$_instance; } /** * Load AJAX posts. * * @since 4.3 * * @return void */ function ajax_load_posts() { check_ajax_referer( 'is_ajax_nonce', 'security' ); $search_post_id = isset( $_POST['id'] ) ? sanitize_text_field( absint( $_POST['id'] ) ) : ''; $page = isset( $_POST['page'] ) ? sanitize_text_field( absint( $_POST['page'] ) ) : 1; $search_term = isset( $_POST['s'] ) ? sanitize_text_field( $_POST['s'] ) : ''; $search_form = IS_Search_Form::get_instance( $search_post_id ); $stored_field = $search_form->prop( '_is_ajax' ); $is_settings = $search_form->prop( '_is_settings' ); $is_includes = $search_form->prop( '_is_includes' ); $posts_per_page = isset( $is_settings['posts_per_page'] ) ? $is_settings['posts_per_page'] : 10; $defaults = array( 'show_description' => 0, 'description_source' => 'content', 'description_length' => 20, 'show_image' => 0, 'show_categories' => 0, 'show_tags' => 0, 'show_author' => 0, 'show_date' => 0, 'nothing_found_text' => __( 'Nothing found', 'add-search-to-menu' ), 'show_more_result' => 0, 'show_more_func' => 0, 'more_result_text' => __( 'More results', 'add-search-to-menu' ), 'show_price' => 0, 'hide_price_out_of_stock' => 0, 'show_sale_badge' => 0, 'show_sku' => 0, 'show_stock_status' => 0, 'show_featured_icon' => 0, 'show_matching_categories' => 0, 'show_matching_tags' => 0, 'show_details_box' => 0, ); $field = wp_parse_args( $stored_field, $defaults ); $field = apply_filters( 'is_ajax_fields', $field ); $posts_class = 'is-show-details-disabled'; if ( isset( $field['show_details_box'] ) && $field['show_details_box'] ) { $posts_class = 'is-show-details-enabled'; } $posts_class = apply_filters( 'is_ajax_items_classes', $posts_class ); $template = locate_template( 'is-ajax-results.php' ); if ( ! $template ) { $template = 'partials/is-ajax-results.php'; } include_once( $template ); wp_die(); } /** * Get Taxonomies by Search Term * * @since 4.3 * * @param string $taxonomy Taxonomy Slug. * @param string $search_term Search Term. * @return array */ function get_taxonomies( $taxonomy, $search_term, $strict = false ) { $result = array(); $all_terms = get_terms( $taxonomy, array( 'taxonomy' => $taxonomy, ) ); foreach ( $all_terms as $term ) { // Used strtolower() because, If search term is 'product' and actual taxonomy title is 'Product', // Then, it does not match due to its case sensitive test. if ( ( $strict && strtolower($term->name) == strtolower($search_term) ) || ( ! $strict && strpos( strtolower($term->name), strtolower($search_term) ) !== false ) ) { $result[] = array( 'term_id' => $term->term_id, 'name' => $term->name, 'slug' => $term->slug, 'taxonomy' => $term->taxonomy, 'count' => $term->count, 'url' => get_term_link( $term, $taxonomy ), ); } } return $result; } /** * Term Title * * @since 4.3 * * @param array $args Term Arguments. * @return void */ function term_title_markup( $args = array() ) { $taxonomy = $args['taxonomy']; $search_term = $args['search_term']; $term_title = $args['title']; $wrapper_class = $args['wrapper_class']; $tags = $this->get_taxonomies( $taxonomy, $search_term, $args['strict'] ); $is_markup = apply_filters( 'is_customize_term_title_markup', false ); if ( $is_markup ) { do_action( 'is_term_title_markup', $taxonomy, $search_term, $term_title, $wrapper_class, $tags ); } else if( $tags ) { ?>
$tag) { ?>
get_taxonomies( $taxonomy, $search_term ); $is_markup = apply_filters( 'is_customize_product_details_markup', false ); if ( $is_markup ) { do_action( 'is_product_details_markup', $taxonomy, $search_term, $field, $wrapper_class, $terms ); } else if ( $terms ) { ob_start(); foreach ($terms as $key => $term) { $this->get_product_by_tax_id( $field, $term['term_id'], $taxonomy ); } $details = ob_get_clean(); if ( $details ) {?>
4, 'post_status' => 'publish', 'post_type' => 'product', 'no_found_rows' => 1, 'order' => $order, 'meta_query' => array(), 'tax_query' => array( 'relation' => 'AND', ) ); if ( function_exists( 'pll_current_language' ) ) { $lang = pll_current_language(); $query_args['lang'] = $lang; } $query_args = apply_filters( 'is_get_product_by_tax_id', $query_args ); switch ( $product_list ) { case 'featured' : $query_args[ 'tax_query' ][] = array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured', ); break; case 'onsale' : $query_args[ 'post__in' ] = wc_get_product_ids_on_sale(); break; } switch ( $order_by ) { case 'price' : $query_args[ 'meta_key' ] = '_price'; $query_args[ 'orderby' ] = 'meta_value_num'; break; case 'rand' : $query_args[ 'orderby' ] = 'rand'; break; case 'sales' : $query_args[ 'meta_key' ] = 'total_sales'; $query_args[ 'orderby' ] = 'meta_value_num'; break; default : $query_args[ 'orderby' ] = 'date'; } $query_args[ 'tax_query' ][] = array( 'taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $cat_id, 'include_children' => true, ); $products = new WP_Query( $query_args ); if ( $products->have_posts() ) { $product_count = 0; while ( $products->have_posts() ) { $products->the_post(); $product_count++; ?>
'.__('Category', 'add-search-to-menu').': '; } else { echo ''.__('Tag', 'add-search-to-menu').': '; } $term = get_term( $cat_id, $taxonomy ); echo ''.esc_html( $term->name ).''; ?>
image_markup( $field, $product ); ?>
title_markup( $field, $post, $product ); ?>
product_price_markup( $field, $product ); ?> product_stock_status_markup( $field, $product ); ?> product_sku_markup( $field, $product ); ?>
date_markup( $field, $post ); ?> author_markup( $field ); ?> tags_markup( $field, $post ); ?> categories_markup( $field, $post ); ?>
description_markup( $field, $post ); ?>
product_sale_badge_markup( $field, $product ); if( $product ) { ?>
'is-ajax-search-product-quantity', ), $product, true ); echo WC_Shortcodes::product_add_to_cart( array( 'id' => get_the_ID(), 'show_price' => false, 'style' => '', ) ); } ?>
post_type ) { $image = wp_get_attachment_image( $post->ID, $image_size ); } else if( has_post_thumbnail( $post->ID ) ) { $image = get_the_post_thumbnail( $post->ID, $image_size ); } $is_markup = apply_filters( 'is_customize_image_markup', false ); if ( $is_markup ) { do_action( 'is_image_markup', $image, $field ); } else if ( isset( $field['show_image'] ) && $field['show_image'] ) { ?>
ID ) ) { ?>
is_featured() ) { ?> " version="1.1" viewBox="0 0 20 21" xmlns="http://www.w3.org/2000/svg" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" xmlns:xlink="http://www.w3.org/1999/xlink"> ID ); ?>
%s', _ex( 'By', 'Article written by', 'add-search-to-menu' ) ); ?> %2$s'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = ''; } $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c', $post->ID ) ), esc_html( get_the_date( '', $post->ID ) ), esc_attr( get_the_modified_date( 'c', $post->ID ) ), esc_html( get_the_modified_date( '', $post->ID ) ) ); echo $time_string; ?> ID, $post->post_type.'_tag' ); if ( $terms && ! is_wp_error( $terms ) ) { ?> %s', __( 'Tagged with:', 'add-search-to-menu' ) ); ?> $term ) { if ( $key ) { echo ', '; }?> post_type ) ? 'category' : $post->post_type.'_cat'; $terms = get_the_terms( $post->ID, $tax_name ); if ( $terms && ! is_wp_error( $terms ) ) { ?> %s', __( 'Categories:', 'add-search-to-menu' ) ); ?> $term ) { if ( $key ) { echo ', '; } ?> post_content; if ( 'product_variation' === $post->post_type ) { $_product = wc_get_product( $post->ID, array( 'parent_id' => $post->post_parent ) ); $is_post_content = $_product->description; } $content = strip_tags( strip_shortcodes( $is_post_content ) ); if ( $single ) { $excerpt_length = 100; } else if ( isset( $field['description_source'] ) && 'excerpt' === $field['description_source'] ) { $content = get_the_excerpt( $post->ID ); } // Removes all shortcodes $patterns = "/\[[\/]?[\s\S][^\]]*\]/"; $replacements = ""; $content = preg_replace( $patterns, $replacements, $content, -1 ); $content = wp_trim_words( $content, $excerpt_length, '...' ); ?>
is_in_stock() ) ? 'in-stock' : 'out-of-stock'; $stock_status_text = ( 'in-stock' == $stock_status ) ? __( 'In stock', 'add-search-to-menu' ) : __( 'Out of stock', 'add-search-to-menu' ); echo ''.$stock_status_text.''; } } } /** * Product SKU Markup * * @since 4.3 * * @param array $field Current stored values. * @param mixed $product Product or Empty. * @return void */ function product_sku_markup( $field, $product ) { $is_markup = apply_filters( 'is_customize_product_sku_markup', false ); if ( $is_markup ) { do_action( 'is_product_sku_markup', $field, $product ); } else if ( $product ) { // Show SKU. if( isset( $field['show_sku'] ) && $field['show_sku'] ) { $sku = $product->get_sku(); echo ''.__( 'SKU:', 'add-search-to-menu' ).' '.esc_html( $sku ).''; } } } /** * Product Price Markup * * @since 4.3 * * @param array $field Current stored values. * @param mixed $product Product or Empty. * @return void */ function product_price_markup( $field, $product ) { $is_markup = apply_filters( 'is_customize_product_price_markup', false ); if ( $is_markup ) { do_action( 'is_product_price_markup', $field, $product ); } else if ( $product ) { if ( isset( $field['show_price'] ) && $field['show_price'] ) { $hide_price_out_of_stock = isset( $field['hide_price_out_of_stock'] ) && $field['hide_price_out_of_stock'] ? $field['hide_price_out_of_stock'] : false; if ( $product->is_in_stock() || false === $hide_price_out_of_stock ) {?> get_price_html(); ?> is_in_stock() ) ? $product->is_on_sale() : ''; if( $on_sale ) { echo '
'.__( 'Sale!', 'add-search-to-menu' ) .'
'; } } } } }