PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.1
Tiered Pricing Table for WooCommerce v7.1.1
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / ReactProductEditorAddon / ProductEditor.php

ProductEditor.php in Tiered Pricing Table for WooCommerce 7.1.1, at src/Addons/ReactProductEditorAddon/ProductEditor.php

119 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\ReactProductEditorAddon;
2
3 use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;
4 use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface;
5 use TierPricingTable\Addons\ReactProductEditorAddon\Blocks\PremiumWrapper;
6 use TierPricingTable\Addons\ReactProductEditorAddon\Blocks\RoleBasedPricing;
7 use TierPricingTable\Addons\ReactProductEditorAddon\Blocks\UpgradeNotice;
8 use TierPricingTable\Addons\ReactProductEditorAddon\Sections\AdvanceProductOptionSection;
9 use TierPricingTable\Addons\ReactProductEditorAddon\Sections\MainSection;
10 use TierPricingTable\Addons\ReactProductEditorAddon\Sections\RoleBasedPricingSection;
11
12 class ProductEditor {
13
14 /**
15 * Blocks
16 *
17 * @var Block[]
18 */
19 protected $blocks;
20
21 const GROUP_ID = 'tiered-pricing/group';
22
23 /**
24 * Sections
25 *
26 * @var object
27 */
28 protected $sections;
29
30 public function __construct() {
31
32 $blocks = array(
33 new Blocks\TieredPricing(),
34 );
35
36 if ( ! tpt_fs()->can_use_premium_code() ) {
37 $blocks[] = new UpgradeNotice();
38 }
39
40 $blocks[] = new Blocks\AdvanceProductOptions();
41 $blocks[] = new Blocks\MinQuantity();
42 $blocks[] = new RoleBasedPricing();
43 $blocks[] = new PremiumWrapper();
44
45 $this->blocks = apply_filters( 'tiered_pricing_table/product_editor/blocks', $blocks );
46
47 $this->sections = apply_filters( 'tiered_pricing_table/product_editor/sections', array(
48 new MainSection(),
49 new AdvanceProductOptionSection(),
50 new RoleBasedPricingSection(),
51 ) );
52
53 new TieredPricingGroup();
54
55 add_action( 'init', array( $this, 'registerBlocks' ) );
56 add_filter( 'woocommerce_block_template_register', array( $this, 'addBlocks' ), 100 );
57 }
58
59 public function addBlocks( BlockTemplateInterface $template ) {
60
61 if ( $template instanceof ProductFormTemplateInterface ) {
62
63 $group = $template->get_group_by_id( self::GROUP_ID );
64
65 if ( ! $group ) {
66 return;
67 }
68
69 foreach ( $this->blocks as $block ) {
70
71 $section = $template->get_section_by_id( $block->getSectionId() );
72
73 if ( ! $section ) {
74 continue;
75 }
76
77 $blockWrapper = $section;
78
79 if ( $block->wrapToPremium() ) {
80 $premiumWrapper = $section->add_block( array(
81 'id' => 'tiered-pricing-table/premium-wrapper',
82 'blockName' => 'tiered-pricing-table/premium-wrapper',
83 'attributes' => array(
84 'isPremium' => tpt_fs()->can_use_premium_code(),
85 ),
86 ) );
87
88 $blockWrapper = $premiumWrapper;
89 }
90
91 $blockWrapper->add_block( [
92 'id' => $block->getId(),
93 'order' => $block->getOrder(),
94 'blockName' => $block->getBlockName(),
95 'attributes' => $block->getAttributes(),
96 ] );
97 }
98 }
99 }
100
101 public function registerBlocks() {
102
103 if ( version_compare( wc()->version, '10.8.0', '>' ) ) {
104 return;
105 }
106
107 if ( ! class_exists( 'Automattic\WooCommerce\Admin\Features\ProductBlockEditor\BlockRegistry' ) ) {
108 return;
109 }
110
111 if ( isset( $_GET['page'] ) && 'wc-admin' === $_GET['page'] ) {
112 foreach ( $this->blocks as $block ) {
113 $block->register();
114 }
115 }
116 }
117
118 }
119