1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
4
|
|
|
exit; |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Recent Reviews Widget. |
9
|
|
|
* |
10
|
|
|
* @author WooThemes |
11
|
|
|
* @category Widgets |
12
|
|
|
* @package WooCommerce/Widgets |
13
|
|
|
* @version 2.3.0 |
14
|
|
|
* @extends WC_Widget |
15
|
|
|
*/ |
16
|
|
|
class LSX_WC_Widget_Recent_Reviews extends WC_Widget { |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct() { |
22
|
|
|
$this->widget_cssclass = 'woocommerce widget_recent_reviews'; |
|
|
|
|
23
|
|
|
$this->widget_description = __( 'Display a list of your most recent reviews on your site.', 'lsx' ); |
|
|
|
|
24
|
|
|
$this->widget_id = 'woocommerce_recent_reviews'; |
|
|
|
|
25
|
|
|
$this->widget_name = __( 'WooCommerce recent reviews', 'lsx' ); |
|
|
|
|
26
|
|
|
$this->settings = array( |
|
|
|
|
27
|
|
|
'title' => array( |
28
|
|
|
'type' => 'text', |
29
|
|
|
'std' => __( 'Recent reviews', 'lsx' ), |
30
|
|
|
'label' => __( 'Title', 'lsx' ), |
31
|
|
|
), |
32
|
|
|
'number' => array( |
33
|
|
|
'type' => 'number', |
34
|
|
|
'step' => 1, |
35
|
|
|
'min' => 1, |
36
|
|
|
'max' => '', |
37
|
|
|
'std' => 10, |
38
|
|
|
'label' => __( 'Number of reviews to show', 'lsx' ), |
39
|
|
|
), |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
parent::__construct(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Output widget. |
47
|
|
|
* |
48
|
|
|
* @see WP_Widget |
49
|
|
|
* |
50
|
|
|
* @param array $args |
|
|
|
|
51
|
|
|
* @param array $instance |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
public function widget( $args, $instance ) { |
54
|
|
|
if ( $this->get_cached_widget( $args ) ) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
ob_start(); |
58
|
|
|
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; |
59
|
|
|
$comments = get_comments( |
60
|
|
|
array( |
61
|
|
|
'number' => $number, |
62
|
|
|
'status' => 'approve', |
63
|
|
|
'post_status' => 'publish', |
64
|
|
|
'post_type' => 'product', |
65
|
|
|
'parent' => 0, |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
if ( $comments ) { |
70
|
|
|
$this->widget_start( $args, $instance ); |
71
|
|
|
|
72
|
|
|
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) ); |
73
|
|
|
|
74
|
|
|
global $stored_comment, $_product, $rating; |
75
|
|
|
|
76
|
|
|
the_comment(); |
77
|
|
|
foreach ( (array) $comments as $comment ) { |
78
|
|
|
$_product = wc_get_product( $comment->comment_post_ID ); |
|
|
|
|
79
|
|
|
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); |
80
|
|
|
$stored_comment = $comment; |
81
|
|
|
|
82
|
|
|
wc_get_template( 'content-widget-review.php' ); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_list', '</ul>' ) ); |
86
|
|
|
|
87
|
|
|
$this->widget_end( $args ); |
88
|
|
|
} |
89
|
|
|
$content = ob_get_clean(); |
90
|
|
|
echo wp_kses_post( $content ); |
91
|
|
|
$this->cache_widget( $args, $content ); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|