BuyButton.php
3 months ago
CartMenuIcon.php
5 months ago
CollectionTag.php
1 year ago
CollectionTags.php
1 year ago
Media.php
1 year ago
PriceChoiceTemplate.php
1 year ago
PriceChooser.php
4 months ago
PriceData.php
1 year ago
Product.php
4 months ago
ProductCard.php
10 months ago
ProductContent.php
10 months ago
ProductData.php
1 year ago
ProductLineItemNote.php
10 months ago
ProductQuickAddButton.php
10 months ago
ProductReviewAverageRatingStars.php
4 months ago
ProductReviewAverageRatingValue.php
4 months ago
ProductReviewBreakdown.php
4 months ago
ProductReviewContent.php
4 months ago
ProductReviewList.php
2 months ago
ProductReviewRating.php
4 months ago
ProductReviewTotalRating.php
4 months ago
ProductReviews.php
4 months ago
Quantity.php
10 months ago
SaleBadge.php
1 year ago
SelectedPriceAdHocAmount.php
1 year ago
VariantPill.php
6 months ago
VariantPills.php
1 year ago
ProductReviewAverageRatingValue.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\Bricks\Elements; |
| 4 | |
| 5 | use SureCart\Integrations\Bricks\Concerns\ConvertsBlocks; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; // Exit if accessed directly. |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Product Average Rating Value element. |
| 13 | */ |
| 14 | class ProductReviewAverageRatingValue extends \Bricks\Element { |
| 15 | use ConvertsBlocks; |
| 16 | |
| 17 | /** |
| 18 | * Element category. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | public $category = 'SureCart Elements'; |
| 23 | |
| 24 | /** |
| 25 | * Element name. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | public $name = 'surecart-product-review-average-rating-value'; |
| 30 | |
| 31 | /** |
| 32 | * Element block name. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public $block_name = 'surecart/product-review-average-rating-value'; |
| 37 | |
| 38 | /** |
| 39 | * Element icon. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $icon = 'ti-bookmark-alt'; |
| 44 | |
| 45 | /** |
| 46 | * Get element label. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function get_label() { |
| 51 | return esc_html__( 'Product Average Rating Value', 'surecart' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Set controls. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public function set_controls() { |
| 60 | $this->controls['format_style'] = [ |
| 61 | 'tab' => 'content', |
| 62 | 'label' => esc_html__( 'Format Style', 'surecart' ), |
| 63 | 'type' => 'select', |
| 64 | 'options' => [ |
| 65 | 'none' => esc_html__( 'None', 'surecart' ), |
| 66 | 'parentheses' => esc_html__( 'Parentheses', 'surecart' ), |
| 67 | 'slash' => '/ 5.0', |
| 68 | ], |
| 69 | 'default' => 'none', |
| 70 | 'inline' => true, |
| 71 | ]; |
| 72 | |
| 73 | $this->controls['link_to_reviews'] = [ |
| 74 | 'tab' => 'content', |
| 75 | 'label' => esc_html__( 'Link to Reviews', 'surecart' ), |
| 76 | 'type' => 'checkbox', |
| 77 | 'default' => false, |
| 78 | ]; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Render element. |
| 83 | * |
| 84 | * @return void |
| 85 | */ |
| 86 | public function render() { |
| 87 | $format_style = ! empty( $this->settings['format_style'] ) ? $this->settings['format_style'] : 'none'; |
| 88 | $class_name = 'none' === $format_style ? '' : 'is-style-' . $format_style; |
| 89 | $link_to_reviews = ! empty( $this->settings['link_to_reviews'] ); |
| 90 | |
| 91 | if ( $this->is_admin_editor() ) { |
| 92 | $this->render_preview( $format_style ); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | echo $this->html( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 97 | [ |
| 98 | 'className' => esc_attr( $class_name ), |
| 99 | 'link_to_reviews' => $link_to_reviews, //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 100 | ] |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Render admin preview. |
| 106 | * |
| 107 | * @param string $format_style Format style. |
| 108 | * |
| 109 | * @return void |
| 110 | */ |
| 111 | public function render_preview( $format_style ) { |
| 112 | $content = '4.5'; |
| 113 | |
| 114 | if ( 'parentheses' === $format_style ) { |
| 115 | $content = '(' . $content . ')'; |
| 116 | } elseif ( 'slash' === $format_style ) { |
| 117 | $content = $content . ' / 5.0'; |
| 118 | } |
| 119 | |
| 120 | echo $this->preview( $content ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 121 | } |
| 122 | } |
| 123 |