BuyButton.php
1 year ago
CollectionTag.php
1 year ago
CollectionTags.php
1 year ago
Media.php
1 year ago
PriceChoiceTemplate.php
1 year ago
PriceChooser.php
1 year ago
PriceData.php
1 year ago
Product.php
1 year ago
ProductCard.php
1 year ago
ProductData.php
1 year ago
Quantity.php
1 year ago
SaleBadge.php
1 year ago
SelectedPriceAdHocAmount.php
1 year ago
VariantPill.php
1 year ago
VariantPills.php
1 year ago
PriceData.php
197 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 | /** |
| 13 | * Selected Price element. |
| 14 | */ |
| 15 | class PriceData extends \Bricks\Element { |
| 16 | use ConvertsBlocks; // we have to use a trait since we can't extend the surecart class. |
| 17 | |
| 18 | /** |
| 19 | * Element category. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | public $category = 'SureCart Elements'; |
| 24 | |
| 25 | /** |
| 26 | * Element icon. |
| 27 | * |
| 28 | * @var string |
| 29 | */ |
| 30 | public $icon = 'ti-receipt'; |
| 31 | |
| 32 | /** |
| 33 | * Element name. |
| 34 | * |
| 35 | * @var string |
| 36 | */ |
| 37 | public $name = 'surecart-price-data'; |
| 38 | |
| 39 | /** |
| 40 | * Element block name. |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | public function get_label() { |
| 45 | return esc_html__( 'Price Data', 'surecart' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Set controls. |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | public function set_controls() { |
| 54 | $this->controls['meta'] = [ |
| 55 | 'tab' => 'content', |
| 56 | 'type' => 'repeater', |
| 57 | 'titleProperty' => 'dynamicData', |
| 58 | 'placeholder' => esc_html__( 'Product data', 'surecart' ), |
| 59 | 'fields' => [ |
| 60 | 'dynamicData' => [ |
| 61 | 'label' => esc_html__( 'Dynamic data', 'surecart' ), |
| 62 | 'type' => 'text', |
| 63 | ], |
| 64 | ], |
| 65 | 'default' => [ |
| 66 | [ |
| 67 | 'dynamicData' => '{sc_price_name}', |
| 68 | 'id' => \Bricks\Helpers::generate_random_id( false ), |
| 69 | ], |
| 70 | [ |
| 71 | 'dynamicData' => '{sc_price_amount}', |
| 72 | 'id' => \Bricks\Helpers::generate_random_id( false ), |
| 73 | ], |
| 74 | [ |
| 75 | 'dynamicData' => '{sc_price_trial}', |
| 76 | 'id' => \Bricks\Helpers::generate_random_id( false ), |
| 77 | ], |
| 78 | [ |
| 79 | 'dynamicData' => '{sc_price_setup_fee}', |
| 80 | 'id' => \Bricks\Helpers::generate_random_id( false ), |
| 81 | ], |
| 82 | ], |
| 83 | ]; |
| 84 | |
| 85 | $this->controls['direction'] = [ |
| 86 | 'tab' => 'content', |
| 87 | 'label' => esc_html__( 'Direction', 'surecart' ), |
| 88 | 'type' => 'direction', |
| 89 | 'css' => [ |
| 90 | [ |
| 91 | 'property' => 'flex-direction', |
| 92 | 'selector' => '', |
| 93 | ], |
| 94 | ], |
| 95 | 'inline' => true, |
| 96 | ]; |
| 97 | |
| 98 | $this->controls['direction'] = [ |
| 99 | 'tab' => 'content', |
| 100 | 'label' => esc_html__( 'Direction', 'surecart' ), |
| 101 | 'type' => 'direction', |
| 102 | 'css' => [ |
| 103 | [ |
| 104 | 'property' => 'flex-direction', |
| 105 | 'selector' => '', |
| 106 | ], |
| 107 | ], |
| 108 | 'inline' => true, |
| 109 | ]; |
| 110 | |
| 111 | $this->controls['justifyContent'] = [ |
| 112 | 'label' => esc_html__( 'Align main axis', 'surecart' ), |
| 113 | 'tooltip' => [ |
| 114 | 'content' => 'justify-content', |
| 115 | 'position' => 'top-left', |
| 116 | ], |
| 117 | 'type' => 'justify-content', |
| 118 | 'css' => [ |
| 119 | [ |
| 120 | 'property' => 'justify-content', |
| 121 | ], |
| 122 | ], |
| 123 | ]; |
| 124 | |
| 125 | $this->controls['alignItems'] = [ |
| 126 | 'label' => esc_html__( 'Align cross axis', 'surecart' ), |
| 127 | 'tooltip' => [ |
| 128 | 'content' => 'align-items', |
| 129 | 'position' => 'top-left', |
| 130 | ], |
| 131 | 'type' => 'align-items', |
| 132 | 'css' => [ |
| 133 | [ |
| 134 | 'property' => 'align-items', |
| 135 | ], |
| 136 | ], |
| 137 | ]; |
| 138 | |
| 139 | $this->controls['gutter'] = [ |
| 140 | 'tab' => 'content', |
| 141 | 'label' => esc_html__( 'Gap', 'surecart' ), |
| 142 | 'type' => 'number', |
| 143 | 'units' => true, |
| 144 | 'css' => [ |
| 145 | [ |
| 146 | 'property' => 'gap', |
| 147 | 'selector' => '', |
| 148 | ], |
| 149 | ], |
| 150 | 'placeholder' => 5, |
| 151 | 'default' => 5, |
| 152 | ]; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | /** |
| 157 | * Render element. |
| 158 | * |
| 159 | * @return void |
| 160 | */ |
| 161 | public function render() { |
| 162 | $settings = $this->settings; |
| 163 | |
| 164 | if ( empty( $settings['meta'] ) ) { |
| 165 | return $this->render_element_placeholder( |
| 166 | [ |
| 167 | 'title' => esc_html__( 'No price data selected.', 'surecart' ), |
| 168 | ] |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | global $post; |
| 173 | |
| 174 | $post_id = $this->post_id; |
| 175 | $post = get_post( $post_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 176 | $meta_data = []; |
| 177 | |
| 178 | foreach ( $settings['meta'] as $index => $meta ) { |
| 179 | $meta_html = ''; |
| 180 | |
| 181 | if ( ! empty( $meta['dynamicData'] ) ) { |
| 182 | $meta_html .= bricks_render_dynamic_data( $meta['dynamicData'], $post_id ); |
| 183 | } |
| 184 | |
| 185 | $meta_data[] = $meta_html; |
| 186 | } |
| 187 | |
| 188 | $this->set_attribute( '_root', 'class', 'post-meta' ); |
| 189 | |
| 190 | echo "<div {$this->render_attributes( '_root' )}>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 191 | |
| 192 | echo join( '', $meta_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 193 | |
| 194 | echo '</div>'; |
| 195 | } |
| 196 | } |
| 197 |