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
ProductLineItemNote.php
282 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 Line Item Note element. |
| 13 | */ |
| 14 | class ProductLineItemNote extends \Bricks\Element { |
| 15 | use ConvertsBlocks; // we have to use a trait since we can't extend the surecart class. |
| 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-line-item-note'; |
| 30 | |
| 31 | /** |
| 32 | * Element block name. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public $block_name = 'surecart/product-line-item-note'; |
| 37 | |
| 38 | /** |
| 39 | * Element icon. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $icon = 'ion-md-create'; |
| 44 | |
| 45 | /** |
| 46 | * Get element label. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function get_label() { |
| 51 | return esc_html__( 'Product Note', 'surecart' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Set controls. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public function set_controls() { |
| 60 | $this->controls['label'] = array( |
| 61 | 'label' => esc_html__( 'Label', 'surecart' ), |
| 62 | 'type' => 'text', |
| 63 | 'default' => esc_html__( 'Note', 'surecart' ), |
| 64 | ); |
| 65 | |
| 66 | $this->controls['placeholder'] = array( |
| 67 | 'label' => esc_html__( 'Placeholder', 'surecart' ), |
| 68 | 'type' => 'text', |
| 69 | ); |
| 70 | |
| 71 | $this->controls['help_text'] = array( |
| 72 | 'label' => esc_html__( 'Help text', 'surecart' ), |
| 73 | 'type' => 'text', |
| 74 | 'description' => esc_html__( 'Optional text that appears below the note field to provide additional guidance.', 'surecart' ), |
| 75 | ); |
| 76 | |
| 77 | // Label Style Controls. |
| 78 | $this->controls['labelStyleSeparator'] = [ |
| 79 | 'label' => esc_html__( 'Label style', 'surecart' ), |
| 80 | 'type' => 'separator', |
| 81 | ]; |
| 82 | |
| 83 | $this->controls['labelTypography'] = [ |
| 84 | 'label' => esc_html__( 'Typography', 'surecart' ), |
| 85 | 'type' => 'typography', |
| 86 | 'css' => [ |
| 87 | [ |
| 88 | 'property' => 'font', |
| 89 | 'selector' => '.sc-form-label', |
| 90 | ], |
| 91 | ], |
| 92 | ]; |
| 93 | |
| 94 | $this->controls['labelColor'] = [ |
| 95 | 'label' => esc_html__( 'Text color', 'surecart' ), |
| 96 | 'type' => 'color', |
| 97 | 'css' => [ |
| 98 | [ |
| 99 | 'property' => 'color', |
| 100 | 'selector' => '.sc-form-label', |
| 101 | ], |
| 102 | ], |
| 103 | ]; |
| 104 | |
| 105 | $this->controls['labelMargin'] = [ |
| 106 | 'label' => esc_html__( 'Margin', 'surecart' ), |
| 107 | 'type' => 'spacing', |
| 108 | 'css' => [ |
| 109 | [ |
| 110 | 'property' => 'margin', |
| 111 | 'selector' => '.sc-form-label', |
| 112 | ], |
| 113 | ], |
| 114 | ]; |
| 115 | |
| 116 | // Input Field Style Controls. |
| 117 | $this->controls['inputFieldStyleSeparator'] = [ |
| 118 | 'label' => esc_html__( 'Input field style', 'surecart' ), |
| 119 | 'type' => 'separator', |
| 120 | ]; |
| 121 | |
| 122 | $this->controls['inputFieldTypography'] = [ |
| 123 | 'label' => esc_html__( 'Typography', 'surecart' ), |
| 124 | 'type' => 'typography', |
| 125 | 'css' => [ |
| 126 | [ |
| 127 | 'property' => 'font', |
| 128 | 'selector' => '.sc-form-control', |
| 129 | ], |
| 130 | ], |
| 131 | ]; |
| 132 | |
| 133 | $this->controls['inputFieldColor'] = [ |
| 134 | 'label' => esc_html__( 'Text color', 'surecart' ), |
| 135 | 'type' => 'color', |
| 136 | 'css' => [ |
| 137 | [ |
| 138 | 'property' => 'color', |
| 139 | 'selector' => '.sc-form-control', |
| 140 | ], |
| 141 | ], |
| 142 | ]; |
| 143 | |
| 144 | $this->controls['inputFieldBackgroundColor'] = [ |
| 145 | 'label' => esc_html__( 'Background color', 'surecart' ), |
| 146 | 'type' => 'color', |
| 147 | 'css' => [ |
| 148 | [ |
| 149 | 'property' => 'background-color', |
| 150 | 'selector' => '.sc-form-control', |
| 151 | ], |
| 152 | ], |
| 153 | ]; |
| 154 | |
| 155 | $this->controls['inputFieldBorder'] = [ |
| 156 | 'label' => esc_html__( 'Border', 'surecart' ), |
| 157 | 'type' => 'border', |
| 158 | 'css' => [ |
| 159 | [ |
| 160 | 'property' => 'border', |
| 161 | 'selector' => '.sc-form-control', |
| 162 | ], |
| 163 | ], |
| 164 | ]; |
| 165 | |
| 166 | $this->controls['inputFieldPadding'] = [ |
| 167 | 'label' => esc_html__( 'Padding', 'surecart' ), |
| 168 | 'type' => 'spacing', |
| 169 | 'css' => [ |
| 170 | [ |
| 171 | 'property' => 'padding', |
| 172 | 'selector' => '.sc-form-control', |
| 173 | ], |
| 174 | ], |
| 175 | ]; |
| 176 | |
| 177 | $this->controls['inputFieldMargin'] = [ |
| 178 | 'label' => esc_html__( 'Margin', 'surecart' ), |
| 179 | 'type' => 'spacing', |
| 180 | 'css' => [ |
| 181 | [ |
| 182 | 'property' => 'margin', |
| 183 | 'selector' => '.sc-form-control', |
| 184 | ], |
| 185 | ], |
| 186 | ]; |
| 187 | |
| 188 | // Help Text Style Controls. |
| 189 | $this->controls['helpTextStyleSeparator'] = [ |
| 190 | 'label' => esc_html__( 'Help text style', 'surecart' ), |
| 191 | 'type' => 'separator', |
| 192 | ]; |
| 193 | |
| 194 | $this->controls['helpTextTypography'] = [ |
| 195 | 'label' => esc_html__( 'Typography', 'surecart' ), |
| 196 | 'type' => 'typography', |
| 197 | 'css' => [ |
| 198 | [ |
| 199 | 'property' => 'font', |
| 200 | 'selector' => '.sc-help-text', |
| 201 | ], |
| 202 | ], |
| 203 | ]; |
| 204 | |
| 205 | $this->controls['helpTextColor'] = [ |
| 206 | 'label' => esc_html__( 'Text color', 'surecart' ), |
| 207 | 'type' => 'color', |
| 208 | 'css' => [ |
| 209 | [ |
| 210 | 'property' => 'color', |
| 211 | 'selector' => '.sc-help-text', |
| 212 | ], |
| 213 | ], |
| 214 | ]; |
| 215 | |
| 216 | $this->controls['helpTextMargin'] = [ |
| 217 | 'label' => esc_html__( 'Margin', 'surecart' ), |
| 218 | 'type' => 'spacing', |
| 219 | 'css' => [ |
| 220 | [ |
| 221 | 'property' => 'margin', |
| 222 | 'selector' => '.sc-help-text', |
| 223 | ], |
| 224 | ], |
| 225 | ]; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Render element. |
| 230 | * |
| 231 | * @return void |
| 232 | */ |
| 233 | public function render() { |
| 234 | $label = ! empty( $this->settings['label'] ) ? $this->settings['label'] : ''; |
| 235 | $placeholder = ! empty( $this->settings['placeholder'] ) ? $this->settings['placeholder'] : esc_html__( 'Add a note (optional)', 'surecart' ); |
| 236 | $help_text = ! empty( $this->settings['help_text'] ) ? $this->settings['help_text'] : ''; |
| 237 | |
| 238 | if ( $this->is_admin_editor() ) { |
| 239 | ob_start(); |
| 240 | ?> |
| 241 | <div> |
| 242 | <?php if ( ! empty( $label ) ) : ?> |
| 243 | <label class="sc-form-label" for="sc_product_note"> |
| 244 | <?php echo wp_kses_post( $label ); ?> |
| 245 | </label> |
| 246 | <?php endif; ?> |
| 247 | |
| 248 | <textarea |
| 249 | class="sc-form-control" |
| 250 | name="sc_product_note" |
| 251 | id="sc_product_note" |
| 252 | placeholder="<?php echo esc_attr( $placeholder ); ?>" |
| 253 | rows="1" |
| 254 | onfocus="this.rows=3" |
| 255 | maxlength="485" |
| 256 | ></textarea> |
| 257 | |
| 258 | <?php if ( ! empty( $help_text ) ) : ?> |
| 259 | <div class="sc-help-text"> |
| 260 | <?php echo wp_kses_post( $help_text ); ?> |
| 261 | </div> |
| 262 | <?php endif; ?> |
| 263 | </div> |
| 264 | <?php |
| 265 | $output = ob_get_clean(); |
| 266 | echo $this->preview( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 267 | $output, |
| 268 | 'wp-block-surecart-product-line-item-note' |
| 269 | ); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | echo $this->raw( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 274 | [ |
| 275 | 'label' => wp_kses_post( $label ), |
| 276 | 'placeholder' => esc_attr( $placeholder ), |
| 277 | 'help_text' => wp_kses_post( $help_text ), |
| 278 | ] |
| 279 | ); |
| 280 | } |
| 281 | } |
| 282 |