BlockAnchorSupportService.php
1 year ago
BlockCurrencyConversionSupportService.php
1 year ago
BlockPatternsService.php
1 year ago
BlockService.php
4 months ago
BlockServiceProvider.php
4 months ago
BlockStylesService.php
3 months ago
BlockValidationService.php
2 years ago
CartMenuIconMigrationService.php
1 year ago
CartMigrationService.php
1 year ago
FormModeSwitcherService.php
7 hours ago
ProductCollectionBadgesMigrationService.php
1 year ago
ProductListFilterTagsMigrationService.php
1 year ago
ProductListMigrationService.php
1 year ago
ProductListService.php
1 year ago
ProductPageBlocksMigrationService.php
1 year ago
ProductPriceChoicesMigrationService.php
1 year ago
ProductQuickViewService.php
9 months ago
ProductReviewFormService.php
4 months ago
ProductSelectedPriceMigrationService.php
1 year ago
ProductVariantsMigrationService.php
1 year ago
URLParamService.php
3 months ago
BlockCurrencyConversionSupportService.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\BlockLibrary; |
| 4 | |
| 5 | /** |
| 6 | * Provide anchor support for blocks. |
| 7 | */ |
| 8 | class BlockCurrencyConversionSupportService { |
| 9 | /** |
| 10 | * Register block support. |
| 11 | * |
| 12 | * @return void |
| 13 | */ |
| 14 | public function bootstrap() { |
| 15 | add_filter( 'pre_render_block', [ $this, 'applySupport' ], 10, 2 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Apply the currency conversion support. |
| 20 | * |
| 21 | * @param string $pre_render Pre-render content. |
| 22 | * @param array $parsed_block Parsed block. |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function applySupport( $pre_render, $parsed_block ) { |
| 27 | // Get the block type object. |
| 28 | $block_type = \WP_Block_Type_Registry::get_instance()->get_registered( $parsed_block['blockName'] ); |
| 29 | |
| 30 | // Should the block convert currency? (either true or false). |
| 31 | $support = $block_type->supports['currencyConversion'] ?? null; |
| 32 | |
| 33 | if ( ! empty( $block_type ) && null !== $support ) { |
| 34 | \SureCart::currency()->convert( wp_validate_boolean( $support ) ); |
| 35 | } |
| 36 | |
| 37 | // Returning '' means "go ahead and render normally". |
| 38 | return $pre_render; |
| 39 | } |
| 40 | } |
| 41 |