Advertisement
raselahmed7

ElementorWoo | Class 8 | products.php

Feb 27th, 2019
1,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.20 KB | None | 0 0
  1. <?php
  2.  
  3. function rrfcommerce_product_cat_list( ) {
  4.  
  5.     $term_id = 'product_cat';
  6.     $categories = get_terms( $term_id );
  7.  
  8.     $cat_array['all'] = "All Categories";
  9.     if ( !empty($categories) ) {
  10.         foreach ( $categories as $cat ) {
  11.             $cat_info = get_term($cat, $term_id);
  12.             $cat_array[ $cat_info->slug ] = $cat_info->name;
  13.         }
  14.     }
  15.  
  16.     return $cat_array;
  17. }
  18.  
  19. class RRFCommerce_Products_Widget extends \Elementor\Widget_Base {
  20.  
  21.  
  22.     public function get_name() {
  23.         return 'rrfcommerce-products';
  24.     }
  25.  
  26.     public function get_title() {
  27.         return __( 'RRFCommerce Products', 'plugin-name' );
  28.     }
  29.  
  30.     public function get_icon() {
  31.         return 'fa fa-code';
  32.     }
  33.  
  34.     public function get_categories() {
  35.         return [ 'general' ];
  36.     }
  37.  
  38.     protected function _register_controls() {
  39.  
  40.         $this->start_controls_section(
  41.             'content_section',
  42.             [
  43.                 'label' => __( 'Content', 'plugin-name' ),
  44.                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  45.             ]
  46.         );
  47.  
  48.         $this->add_control(
  49.             'limit',
  50.             [
  51.                 'label' => __( 'Count', 'plugin-domain' ),
  52.                 'type' => \Elementor\Controls_Manager::TEXT,
  53.                 'default' => '4',
  54.             ]
  55.         );
  56.        
  57.         $this->add_control(
  58.             'columns',
  59.             [
  60.                 'label' => __( 'Columns', 'plugin-domain' ),
  61.                 'type' => \Elementor\Controls_Manager::SELECT,
  62.                 'default' => '4',
  63.                 'options' => [
  64.                     '1'  => __( '1 Column', 'plugin-domain' ),
  65.                     '2' => __( '2 Columns', 'plugin-domain' ),
  66.                     '3' => __( '3 Columns', 'plugin-domain' ),
  67.                     '4' => __( '4 Columns', 'plugin-domain' ),
  68.                 ],
  69.             ]
  70.         );
  71.        
  72.         $this->add_control(
  73.             'category',
  74.             [
  75.                 'label' => __( 'Select Category', 'plugin-domain' ),
  76.                 'type' => \Elementor\Controls_Manager::SELECT2,
  77.                 'multiple' => true,
  78.                 'options' => rrfcommerce_product_cat_list(),
  79.                 'default' => [ 'all' ],
  80.             ]
  81.         );
  82.        
  83.  
  84.         $this->add_control(
  85.             'carousel',
  86.             [
  87.                 'label' => __( 'Enable Carousel?', 'plugin-domain' ),
  88.                 'type' => \Elementor\Controls_Manager::SWITCHER,
  89.                 'label_on' => __( 'Yes', 'your-plugin' ),
  90.                 'label_off' => __( 'No', 'your-plugin' ),
  91.                 'return_value' => 'yes',
  92.                 'default' => 'no',
  93.             ]
  94.         );
  95.  
  96.         $this->end_controls_section();
  97.  
  98.     }
  99.  
  100.     protected function render() {
  101.  
  102.         $settings = $this->get_settings_for_display();
  103.  
  104.         if(empty($settings['category']) OR $settings['category'] == 'all') {
  105.             $cats = '';
  106.         } else {
  107.             $cats = implode(',', $settings['category']);
  108.         }
  109.  
  110.         if($settings['carousel'] == 'yes') {
  111.            
  112.             $dynamic_id = rand(89896,896698);
  113.             echo '<script>
  114.                jQuery(window).load(function(){
  115.                    jQuery("#product-carousel-'.$dynamic_id.' .products").slick({
  116.                        slidesToShow: '.$settings['columns'].'
  117.                    });
  118.                });
  119.            </script><div id="product-carousel-'.$dynamic_id.'">';
  120.         }
  121.  
  122.         echo do_shortcode('[products category="'.$cats.'" limit="'.$settings['limit'].'" columns="'.$settings['columns'].'"]');
  123.        
  124.        
  125.         if($settings['carousel'] == 'yes') { echo '</div>'; }
  126.  
  127.     }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement