MOON
Server: Apache
System: Linux server.netcommlabs.in 3.10.0-1160.83.1.el7.x86_64 #1 SMP Wed Jan 25 16:41:43 UTC 2023 x86_64
User: dermova (1051)
PHP: 5.4.45
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/dermova/www/india/wp-content/plugins/rit-core/inc/helpers/wc.php
<?php
/**
 * RIT Core Plugin
 * @package     RIT Core
 * @version     0.1
 * @author      CleverSoft
 * @link        http://cleversoft.co
 * @copyright   Copyright (c) 2015 CleverSoft
 * @license     GPL v2
 */
function rit_product_label($product = null, $post = null){

    if($product == null){
        global $product;
    }

    if($post == null){
        global $post;
    }
    $stock_status = get_post_meta($post->ID, '_stock_status',true);
    if ($stock_status == 'outofstock') {

        echo '<span class="out-of-stock-badge">' . esc_html__( 'Out of Stock', RIT_TEXT_DOMAIN ) . '</span>';

    } else if ($product->is_on_sale()) {

        echo apply_filters('woocommerce_sale_flash', '<span class="onsale">'.esc_html__( 'Sale!', 'woocommerce' ).'</span>', $post, $product);
    } else if (!$product->get_price()) {

        echo '<span class="free-badge">' . esc_html__( 'Free', RIT_TEXT_DOMAIN ) . '</span>';

    } else {

        $postdate 		= get_the_time( 'Y-m-d' );			// Post date
        $postdatestamp 	= strtotime( $postdate );			// Timestamped post date
        $newness 		= 7; 	// Newness in days

        if ( ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdatestamp ) {
            echo '<span class="wc-new-badge">' . esc_html__( 'New', RIT_TEXT_DOMAIN ) . '</span>';
        }

    }
}



if(!function_exists('rit_ajax_product_filter')){

    function rit_ajax_product_filter(){

        global $wpdb;

        $atts = array(
            //'title' => '',
            'post_type' => $_POST['post_type'],
            'pagination' => $_POST['pagination'],
            'column' => $_POST['column'],
            'posts_per_page' => $_POST['posts_per_page'],
            'category'=> $_POST['category'],
            'products_type' => $_POST['products_type'],
            'products_img_size' => $_POST['products_img_size'],
            'paged' => $_POST['paged'],
            'ignore_sticky_posts' => $_POST['ignore_sticky_posts'],
            'show' => $_POST['show'],
            'orderby' => $_POST['orderby'],
            'element_custom_class' => $_POST['element_custom_class'],
            'padding_bottom_module' => $_POST['padding_bottom_module'],
            'filter_attributes' => $_POST['filter_attributes'],
            'filter_tags' => $_POST['filter_tags'],
            'filter_categories' => $_POST['filter_categories'],
            'show_filter' => $_POST['show_filter'],
            'show_loadmore' => $_POST['show_loadmore']

        );



        $wc_attr = array(
            'post_type' => 'product',
            'posts_per_page' => $atts['posts_per_page'],
            'paged' => $atts['paged'],
            'orderby' => $atts['orderby'],
            'ignore_sticky_posts' => $atts['ignore_sticky_posts'],
        );

        $meta_query = WC()->query->get_meta_query();
        $tax_query = array();

        if(isset($_POST['show'])){


            if ($atts['show'] == 'featured') {

                $meta_query[] = array(
                    'key' => '_featured',
                    'value' => 'yes'
                );

                $wc_attr['meta_query'] = $meta_query;

            } elseif ($atts['show'] == 'onsale') {

                $product_ids_on_sale = wc_get_product_ids_on_sale();

                $wc_attr['post__in'] = $product_ids_on_sale;

                $wc_attr['meta_query'] = $meta_query;

            } elseif ($atts['show'] == 'best-selling') {

                $wc_attr['meta_key'] = 'total_sales';

                $wc_attr['meta_query'] = $meta_query;

            } elseif ($atts['show'] == 'latest'){

                $wc_attr['orderby'] = 'date';

                $wc_attr['order'] = 'DESC';

            } elseif ($atts['show'] == 'toprate'){

                add_filter('posts_clauses', array( 'WC_Shortcodes', 'order_by_rating_post_clauses'));

            } elseif ($atts['show'] == 'price'){

                $wc_attr['orderby']  = "meta_value_num {$wpdb->posts}.ID";
                $wc_attr['order']    = 'ASC';
                $wc_attr['meta_key'] = '_price';

            } elseif ($atts['show'] == 'price-desc'){

                $wc_attr['orderby']  = "meta_value_num {$wpdb->posts}.ID";
                $wc_attr['order']    = 'DESC';
                $wc_attr['meta_key'] = '_price';

            }

        }

        if(isset($_POST['product_attribute']) && isset($_POST['attribute_value'])){
            if(is_array($_POST['product_attribute'])){
                foreach ($_POST['product_attribute'] as $key => $value) {
                    $tax_query[] = array(
                        'taxonomy' => $value,
                        'terms' => $_POST['attribute_value'][$key],
                        'field'         => 'slug',
                        'operator'      => 'IN'
                    );
                }
            }else {
                $tax_query[] = array(
                    'taxonomy' => $_POST['product_attribute'],
                    'terms' => $_POST['attribute_value'],
                    'field'         => 'slug',
                    'operator'      => 'IN'
                );

            }

            $wc_attr['tax_query'] = $tax_query;
            $wc_attr['meta_query'] = $meta_query;
        }

        if(isset($_POST['product_cat'])){
            $wc_attr['product_cat'] = $_POST['product_cat'];
        }

        if(isset($_POST['product_tag'])){
            $wc_attr['product_tag'] = $_POST['product_tag'];
        }

        $atts['wc_attr'] = $wc_attr;

        echo rit_get_template_part('shortcode', 'product', array('atts' => $atts));

    }

    add_action('wp_ajax_rit_ajax_product_filter', 'rit_ajax_product_filter');
    add_action( 'wp_ajax_nopriv_rit_ajax_product_filter', 'rit_ajax_product_filter' );
}