Guest User

product_snippet_review.php

a guest
Apr 30th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.26 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Product Reviews
  4.  *
  5.  * Display the reviews and review form for the current product
  6.  */
  7. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if( !class_exists( 'woocommerce' ) )
  11. {
  12.     add_shortcode('av_product_review', 'avia_please_install_woo');
  13.     return;
  14. }
  15.  
  16. if ( !class_exists( 'avia_sc_product_review' ) )
  17. {
  18.     class avia_sc_product_review extends aviaShortcodeTemplate
  19.     {
  20.         /**
  21.          * Create the config array for the shortcode button
  22.          */
  23.         function shortcode_insert_button()
  24.         {
  25.             $this->config['self_closing']   =   'yes';
  26.            
  27.             $this->config['name']       = __('Product Reviews', 'avia_framework' );
  28.             $this->config['tab']        = __('Plugin Additions', 'avia_framework' );
  29.             $this->config['icon']       = AviaBuilder::$path['imagesURL']."sc-comments.png";
  30.             $this->config['order']      = 9;
  31.             $this->config['target']     = 'avia-target-insert';
  32.             $this->config['shortcode']  = 'av_product_review';
  33.             $this->config['tooltip']    = __('Display the reviews and review form for the current product', 'avia_framework' );
  34.             $this->config['drag-level'] = 3;
  35.             $this->config['tinyMCE']    = array('disable' => "true");
  36.             $this->config['posttype']   = array('product',__('This element can only be used on single product pages','avia_framework'));
  37.         }
  38.  
  39.  
  40.         /**
  41.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  42.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  43.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  44.          *
  45.          *
  46.          * @param array $params this array holds the default values for $content and $args.
  47.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  48.          */
  49.         function editor_element($params)
  50.         {
  51.             $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  52.             $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  53.            
  54.             $params['innerHtml'].= "<div class='avia-flex-element'>";
  55.             $params['innerHtml'].=      __( 'Display and allow reviews for this product. Needs to enable reviews in advanced tab.', 'avia_framework' );
  56.             $params['innerHtml'].= "</div>";
  57.            
  58.             return $params;
  59.         }
  60.  
  61.  
  62.  
  63.         /**
  64.          * Frontend Shortcode Handler
  65.          *
  66.          * @param array $atts array of attributes
  67.          * @param string $content text within enclosing form of shortcode element
  68.          * @param string $shortcodename the shortcode found, when == callback name
  69.          * @return string $output returns the modified html string
  70.          */
  71.         function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  72.         {
  73.             $output = "";
  74.             $meta['el_class'];
  75.            
  76.             global $woocommerce, $product;
  77.             if(!is_object($woocommerce) || !is_object($woocommerce->query) || empty($product)) return;
  78.  
  79.             if($product->get_review_count('view') != 0) {
  80.                 add_filter('comments_open', __return_true);
  81.             }
  82.            
  83.             // $product = wc_get_product();
  84.             $output .= "<div class='av-woo-product-review ".$meta['el_class']."'>";
  85.             ob_start();
  86.             comments_template('reviews');
  87.             $output .= ob_get_clean();
  88.             $output .= "</div>";
  89.            
  90.            
  91.             return $output;
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment