config.php
202 lines
| 1 | <?php |
| 2 | namespace ShopPress\Elementor\Widgets; |
| 3 | |
| 4 | use ShopPress\Elementor\ShopPressWidgets; |
| 5 | use Elementor\Controls_Manager; |
| 6 | |
| 7 | defined( 'ABSPATH' ) || exit; |
| 8 | |
| 9 | class Rating extends ShopPressWidgets { |
| 10 | |
| 11 | public function get_name() { |
| 12 | return 'sp-rating'; |
| 13 | } |
| 14 | |
| 15 | public function get_title() { |
| 16 | return __( 'Product Rating', 'shop-press' ); |
| 17 | } |
| 18 | |
| 19 | public function get_icon() { |
| 20 | return 'sp-widget sp-eicon-product-rating'; |
| 21 | } |
| 22 | |
| 23 | public function get_categories() { |
| 24 | return array( 'sp_woo_single' ); |
| 25 | } |
| 26 | |
| 27 | public function setup_styling_options() { |
| 28 | |
| 29 | $this->register_group_styler( |
| 30 | 'wrapper', |
| 31 | __( 'Wrapper', 'shop-press' ), |
| 32 | array( |
| 33 | 'wrapper' => array( |
| 34 | 'label' => esc_html__( 'Wrapper', 'shop-press' ), |
| 35 | 'type' => 'styler', |
| 36 | 'selector' => '.sp-single-rating', |
| 37 | 'wrapper' => '{{WRAPPER}}', |
| 38 | ), |
| 39 | ) |
| 40 | ); |
| 41 | |
| 42 | $this->register_group_styler( |
| 43 | 'modern_rating', |
| 44 | __( 'Rating', 'shop-press' ), |
| 45 | array( |
| 46 | 'modern_container' => array( |
| 47 | 'label' => esc_html__( 'Container', 'shop-press' ), |
| 48 | 'type' => 'styler', |
| 49 | 'selector' => '.sp-rating', |
| 50 | 'wrapper' => '{{WRAPPER}} .woocommerce-product-rating.sp-single-rating.sp-modern-rating', |
| 51 | ), |
| 52 | 'star' => array( |
| 53 | 'label' => esc_html__( 'Star', 'shop-press' ), |
| 54 | 'type' => 'styler', |
| 55 | 'selector' => '.sp-rating-star', |
| 56 | 'wrapper' => '{{WRAPPER}} .woocommerce-product-rating.sp-single-rating.sp-modern-rating .sp-rating', |
| 57 | ), |
| 58 | ), |
| 59 | array( |
| 60 | 'rating_type' => 'modern' ?? array(), |
| 61 | ) |
| 62 | ); |
| 63 | |
| 64 | $this->register_group_styler( |
| 65 | 'classic_rating', |
| 66 | __( 'Rating', 'shop-press' ), |
| 67 | array( |
| 68 | 'classic_container' => array( |
| 69 | 'label' => esc_html__( 'Container', 'shop-press' ), |
| 70 | 'type' => 'styler', |
| 71 | 'selector' => '.star-rating', |
| 72 | 'wrapper' => '{{WRAPPER}} .woocommerce-product-rating.sp-single-rating.sp-classic-rating', |
| 73 | ), |
| 74 | 'empty_stars' => array( |
| 75 | 'label' => esc_html__( 'Empty Star', 'shop-press' ), |
| 76 | 'type' => 'styler', |
| 77 | 'selector' => '.star-rating::before', |
| 78 | 'wrapper' => '{{WRAPPER}} .woocommerce-product-rating.sp-single-rating.sp-classic-rating', |
| 79 | ), |
| 80 | 'full_stars' => array( |
| 81 | 'label' => esc_html__( 'Full Star', 'shop-press' ), |
| 82 | 'type' => 'styler', |
| 83 | 'selector' => 'span', |
| 84 | 'wrapper' => '{{WRAPPER}} .woocommerce-product-rating.sp-single-rating.sp-classic-rating .star-rating', |
| 85 | ), |
| 86 | ), |
| 87 | array( |
| 88 | 'rating_type' => 'classic' ?? array(), |
| 89 | ) |
| 90 | ); |
| 91 | |
| 92 | $this->register_group_styler( |
| 93 | 'review_counter', |
| 94 | __( 'Review Counter', 'shop-press' ), |
| 95 | array( |
| 96 | 'count_star' => array( |
| 97 | 'label' => esc_html__( 'Reviews Count', 'shop-press' ), |
| 98 | 'type' => 'styler', |
| 99 | 'selector' => 'span.count', |
| 100 | 'wrapper' => '{{WRAPPER}} a.woocommerce-review-link', |
| 101 | ), |
| 102 | 'review_link' => array( |
| 103 | 'label' => esc_html__( 'Review Link', 'shop-press' ), |
| 104 | 'type' => 'styler', |
| 105 | 'selector' => 'a.woocommerce-review-link', |
| 106 | 'wrapper' => '{{WRAPPER}} .woocommerce-product-rating.sp-single-rating', |
| 107 | ), |
| 108 | ) |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | protected function register_controls() { |
| 113 | $this->start_controls_section( |
| 114 | 'section_content', |
| 115 | array( |
| 116 | 'label' => __( 'General', 'shop-press' ), |
| 117 | ) |
| 118 | ); |
| 119 | |
| 120 | $this->add_control( |
| 121 | 'rating_type', |
| 122 | array( |
| 123 | 'label' => __( 'Type', 'shop-press' ), |
| 124 | 'type' => Controls_Manager::SELECT, |
| 125 | 'default' => 'modern', |
| 126 | 'options' => array( |
| 127 | 'modern' => __( 'Modern', 'shop-press' ), |
| 128 | 'classic' => __( 'Classic', 'shop-press' ), |
| 129 | ), |
| 130 | ) |
| 131 | ); |
| 132 | |
| 133 | $this->add_control( |
| 134 | 'show_review_counter', |
| 135 | array( |
| 136 | 'label' => esc_html__( 'Show review counter', 'shop-press' ), |
| 137 | 'type' => Controls_Manager::SWITCHER, |
| 138 | 'label_off' => esc_html__( 'Off', 'shop-press' ), |
| 139 | 'label_on' => esc_html__( 'On', 'shop-press' ), |
| 140 | 'default' => 'yes', |
| 141 | ) |
| 142 | ); |
| 143 | |
| 144 | $this->end_controls_section(); |
| 145 | |
| 146 | $this->setup_styling_options(); |
| 147 | |
| 148 | do_action( 'shoppress/elementor/widget/register_controls_init', $this ); |
| 149 | } |
| 150 | |
| 151 | protected function render() { |
| 152 | $settings = $this->get_settings_for_display(); |
| 153 | |
| 154 | do_action( 'shoppress/widget/before_render', $settings ); |
| 155 | |
| 156 | $args = array( |
| 157 | 'rating_type' => $settings['rating_type'], |
| 158 | 'show_review_counter' => $settings['show_review_counter'], |
| 159 | ); |
| 160 | |
| 161 | if ( $this->editor_preview() ) { |
| 162 | sp_load_builder_template( 'single-product/product-rating', $args ); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | protected function content_template() { |
| 167 | ?> |
| 168 | |
| 169 | <# if ( 'modern' === settings.rating_type ) { #> |
| 170 | <div class="woocommerce-product-rating sp-single-rating sp-modern-rating"> |
| 171 | <div class="sp-rating"> |
| 172 | <span class="sp-rating-star">S</span> |
| 173 | 4.0 |
| 174 | </div> |
| 175 | <# if ( 'yes' === settings.show_review_counter ) { #> |
| 176 | <a href="#reviews" class="woocommerce-review-link" rel="nofollow"> |
| 177 | <span class="count">1</span> |
| 178 | review |
| 179 | </a> |
| 180 | <# } #> |
| 181 | </div> |
| 182 | <# } #> |
| 183 | |
| 184 | <# if ( 'classic' === settings.rating_type ) { #> |
| 185 | <div class="woocommerce-product-rating sp-single-rating sp-classic-rating"> |
| 186 | <div class="star-rating" role="img" aria-label="Rated 4 out of 5"> |
| 187 | <span style="width:80%"></span> |
| 188 | </div> |
| 189 | <# if ( 'yes' === settings.show_review_counter ) { #> |
| 190 | <a href="#reviews" class="woocommerce-review-link" rel="nofollow"> |
| 191 | <span class="count">1</span> |
| 192 | review |
| 193 | </a> |
| 194 | <# } #> |
| 195 | </div> |
| 196 | <# } #> |
| 197 | <?php |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 202 |