PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.19.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.19.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / packages / blocks / Blocks / Product / Price / Block.php
Block.php
54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCartBlocks\Blocks\Product\Price;
4
5 use SureCart\Support\Currency;
6 use SureCartBlocks\Blocks\Product\ProductBlock;
7
8 /**
9 * Product Title Block
10 */
11 class Block extends ProductBlock {
12 /**
13 * Keep track of the instance number of this block.
14 *
15 * @var integer
16 */
17 public static $instance;
18
19 /**
20 * Render the block
21 *
22 * @param array $attributes Block attributes.
23 * @param string $content Post content.
24 *
25 * @return string
26 */
27 public function render( $attributes, $content ) {
28 $product = $this->getProductAndSetInitialState( $attributes['id'] ?? '' );
29 if ( empty( $product ) || empty( $product->activePrices() ) ) {
30 return '';
31 }
32
33 $attributes = get_block_wrapper_attributes(
34 [
35 'sale-text' => esc_attr( $attributes['sale_text'] ?? '' ),
36 'class' => esc_attr( $this->getClasses( $attributes ) . ' product-price surecart-block' ),
37 'style' => esc_attr( $this->getStyles( $attributes ) . ' --sc-product-price-alignment:' . esc_attr( $attributes['alignment'] ?? 'left' ) . '; text-align:' . esc_attr( $attributes['alignment'] ?? 'left' ) . ';' ),
38 'product-id' => esc_attr( $product->id ),
39 ]
40 );
41
42 // first price.
43 $first_price = $product->activePrices()[0];
44
45 return wp_sprintf(
46 '<sc-product-price %1$s>
47 %2$s
48 </sc-product-price>',
49 $attributes,
50 esc_html( Currency::format( $first_price->amount, $first_price->currency ) )
51 );
52 }
53 }
54