File: /home/dermova/www/india/wp-content/plugins/rit-core/inc/shortcode/rit_product.php
<?php
/* ================================================================================== */
/* Products Shortcode
/* ================================================================================== */
if (!function_exists('rit_shortcode_products')) {
function rit_shortcode_products($atts, $content) {
$outputs='';
$atts = shortcode_atts(array(
'title' => '',
'heading_color' =>'#353535',
'post_type' => 'product',
'pagination' => 'simple',
'column' => 'col-md-3 col-sm-6',
'posts_per_page' => 4,
'products_types' => 'products_carousel',
'carousel_style' => 'false',
'title_align' => 'center',
'paged' => -1,
'ignore_sticky_posts' => 1,
'show' => '',
'style' =>'default',
'bg_box_css' =>'',
'element_custom_class' => '',
'meta_query' =>'',
'show_category' =>'',
'padding_bottom_module' => '0px'
), $atts);
//category
if(isset($atts['show_category']) && empty($atts['show_category'])){
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'product_cat'
)
)
);
$query_shop = new WP_Query($args);
$atts['tax_query'] = $query_shop;
}
else{
$terms=explode(',', $atts['show_category']);
$args = array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $terms,
'posts_per_page' => -1,
'post_status' => 'publish'
)
);
$atts['tax_query'] = $args;
}
if( $atts['show'] == 'featured' ){
$meta_query = WC()->query->get_meta_query();
$meta_query[] = array(
'key' => '_featured',
'value' => 'yes'
);
$atts['meta_query'] = $meta_query;
}
elseif( $atts['show'] == 'onsale' ){
$product_ids_on_sale = wc_get_product_ids_on_sale();
$atts['post__in'] = $product_ids_on_sale;
$meta_query = WC()->query->get_meta_query();
$atts['meta_query'] = $meta_query;
}
elseif( $atts['show'] == 'best-selling' ){
$atts['meta_key']='total_sales';
$atts['orderby']='meta_value_num';
$atts['ignore_sticky_posts'] = 1;
$atts['meta_query']= WC()->query->stock_status_meta_query();
$atts['meta_query']= WC()->query->visibility_meta_query();
}
elseif( $atts['show'] == 'latest' ){
$meta_query = WC()->query->stock_status_meta_query();
$atts['meta_query'] = $meta_query;
}
elseif( $atts['show'] == 'toprate' ){
add_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
$atts['meta_query'] = WC()->query->get_meta_query();
}
$bg_box_css = $heading_color_css = array();
if($atts['bg_box_css']){
$bg_box_css[] = vc_get_css_color( 'background-color', $atts['bg_box_css'] );
}
if($atts['heading_color']){
$heading_color[] = vc_get_css_color( 'color', $atts['heading_color'] );
}
$heading_color_css = ' style="' . implode( '', $heading_color ) . '"';
$bg_box_css = ' style="' . implode( '', $bg_box_css ) . '"';
ob_start();?>
<div class="widget style-<?php echo $atts['style']; ?>">
<?php if ( $atts['title'] ) {?>
<h3 class="widget-title" <?php if($atts['style'] != 'default'){ echo $bg_box_css;} ?> >
<span <?php echo $heading_color_css;?> class="<?php echo $atts['title_align']; ?>"><?php echo htmlspecialchars_decode( $atts['title'] ); ?></span>
</h3>
<?php }?>
<div class="widget-content">
<?php
switch ($atts['products_types']) {
case 'products_carousel':
$output = ri_get_template_part('product-layout/shortcode', 'product-carousel', array('atts' => $atts));
break;
case 'products_grid':
$output = ri_get_template_part('product-layout/shortcode', 'product-grid', array('atts' => $atts));
break;
case 'products_list':
$output = ri_get_template_part('product-layout/shortcode', 'product-list', array('atts' => $atts));
break;
default:
$output = ri_get_template_part('product-layout/shortcode', 'product-list', array('atts' => $atts));
break;
}
?>
</div>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
add_shortcode('rit_products', 'rit_shortcode_products');
add_action('vc_before_init', 'rit_product_integrate_vc');
if (!function_exists('rit_product_integrate_vc')) {
function rit_product_integrate_vc()
{
vc_map(
array(
'name' => __('RIT Products', RIT_TEXT_DOMAIN),
'base' => 'rit_products',
'icon' => 'icon-rit',
'category' => __('RIT', RIT_TEXT_DOMAIN),
'description' => __('Show multiple products by ID or SKU.', RIT_TEXT_DOMAIN),
'params' => array(
array(
'type' => 'textfield',
'heading' => __('Title', RIT_TEXT_DOMAIN),
'value' => '',
'param_name' => 'title',
),
array(
'type' => 'colorpicker',
'heading' => __( 'Heading Color',RIT_TEXT_DOMAIN),
'param_name' => 'heading_color',
'std' => '#353535',
),
array(
'type' => 'dropdown',
'heading' => __('Title align', RIT_TEXT_DOMAIN),
'value' => array(
__('Center', RIT_TEXT_DOMAIN) => 'center',
__('Left', RIT_TEXT_DOMAIN) => 'left',
__('Right', RIT_TEXT_DOMAIN) => 'right',
__('Hidden', RIT_TEXT_DOMAIN) => 'hidden'
),
'param_name' => 'title_align',
),
array(
'type' => 'dropdown',
'heading' => __('Show', RIT_TEXT_DOMAIN),
'value' => array(
__('Featured', RIT_TEXT_DOMAIN) => 'featured',
__('Onsale', RIT_TEXT_DOMAIN) => 'onsale',
__('Best Selling', RIT_TEXT_DOMAIN) => 'best-selling',
__('Latest product', RIT_TEXT_DOMAIN) => 'latest',
__('Top rate product', RIT_TEXT_DOMAIN) => 'toprate'
),
'std' => '',
'param_name' => 'show',
),
array(
'type' => 'rit_product_categories',
'heading' => __( 'Category',RIT_TEXT_DOMAIN ),
'param_name' => 'show_category',
'description' => __( 'Product category list',RIT_TEXT_DOMAIN),
),
array(
'type' => 'dropdown',
'heading' => __('Select type', RIT_TEXT_DOMAIN),
'value' => array(
__('Carousel', RIT_TEXT_DOMAIN) => 'products_carousel',
__('Grid', RIT_TEXT_DOMAIN) => 'products_grid',
__('List', RIT_TEXT_DOMAIN) => 'products_list'
),
'param_name' => 'products_types',
),
array(
'type' => 'checkbox',
'heading' => __("Pagination Carousel:", RIT_TEXT_DOMAIN),
'param_name' => 'carousel_style',
'value' => array(
__('Yes', RIT_TEXT_DOMAIN) => 'true')
),
array(
'type' => 'dropdown',
'heading' => __('Column count', RIT_TEXT_DOMAIN),
'value' => array(
__('1 Columns', RIT_TEXT_DOMAIN) => 'col-md-12 col-sm-12',
__('2 Columns', RIT_TEXT_DOMAIN) => 'col-md-6 col-sm-6',
__('3 Columns', RIT_TEXT_DOMAIN) => 'col-md-4 col-sm-6',
__('4 Columns', RIT_TEXT_DOMAIN) => 'col-md-3 col-sm-6',
__('6 Columns', RIT_TEXT_DOMAIN) => 'col-md-2 col-sm-4'
),
'std' => 'col-md-3 col-sm-6',
'param_name' => 'column',
),
array(
'type' => 'textfield',
'heading' => __('Number of Post', RIT_TEXT_DOMAIN),
'value' => 6,
'param_name' => 'posts_per_page',
),
array(
'type' => 'dropdown',
'heading' => __('Style :', RIT_TEXT_DOMAIN),
'value' => array(
__('Default', RIT_TEXT_DOMAIN) => 'default',
__('Box - Style', RIT_TEXT_DOMAIN) => 'box',
__('Border - Style', RIT_TEXT_DOMAIN) => 'border',
),
'std' => 'default',
'param_name' => 'style',
),
array(
'type' => 'colorpicker',
'heading' => __( 'Background Color',RIT_TEXT_DOMAIN),
'param_name' => 'bg_box_css',
'description' => __( 'Select custom background color.', RIT_TEXT_DOMAIN )
),
array(
'type' => 'textfield',
'heading' => __('Custom Class', RIT_TEXT_DOMAIN),
'value' => '',
'param_name' => 'element_custom_class',
'description' => __('You can use the custom CSS class for this module', RIT_TEXT_DOMAIN),
),
array(
'type' => 'textfield',
'heading' => __('Bottom padding for the module', RIT_TEXT_DOMAIN),
'value' => '35px',
'param_name' => 'padding_bottom_module',
)
)
)
);
}
}