tier-pricing-table
/
src
/
Addons
/
ReactProductEditorAddon
/
Sections
/
RoleBasedPricingSection.php
RoleBasedPricingSection.php in Tiered Pricing Table for WooCommerce 7.1.1, at src/Addons/ReactProductEditorAddon/Sections/RoleBasedPricingSection.php
| 1 | <?php namespace TierPricingTable\Addons\ReactProductEditorAddon\Sections; |
| 2 | |
| 3 | use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface; |
| 4 | use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface; |
| 5 | use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\SectionInterface; |
| 6 | use TierPricingTable\Addons\ReactProductEditorAddon\TieredPricingGroup; |
| 7 | |
| 8 | class RoleBasedPricingSection { |
| 9 | |
| 10 | const ID = 'tiered-pricing-table/product-editor-role-based-pricing-section'; |
| 11 | |
| 12 | /** |
| 13 | * Section instance |
| 14 | * |
| 15 | * @var ?SectionInterface |
| 16 | */ |
| 17 | public $sectionInstance = null; |
| 18 | |
| 19 | public function __construct() { |
| 20 | add_action( 'woocommerce_block_template_register', array( $this, 'register' ) ); |
| 21 | } |
| 22 | |
| 23 | public function register( BlockTemplateInterface $template ) { |
| 24 | |
| 25 | if ( $template instanceof ProductFormTemplateInterface && in_array( $template->get_id(), |
| 26 | $this->getSupportedProductTypes() ) ) { |
| 27 | |
| 28 | $group = $template->get_group_by_id( TieredPricingGroup::ID ); |
| 29 | |
| 30 | if ( ! $group ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | $this->sectionInstance = $group->add_section( array( |
| 35 | 'id' => self::ID, |
| 36 | 'order' => 20, |
| 37 | 'attributes' => array( |
| 38 | 'title' => __( 'Role-Based Pricing', 'tier-pricing-table' ), |
| 39 | 'description' => __( 'Set up custom pricing for specific user roles.', 'tier-pricing-table' ), |
| 40 | 'blockGap' => 'unit-40', |
| 41 | ), |
| 42 | ) ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public function getSupportedProductTypes(): array { |
| 47 | return apply_filters( 'tiered_pricing_table/product_editor/role-based-section/supported_types', |
| 48 | array( 'product-variation', 'simple-product' ) ); |
| 49 | } |
| 50 | } |
| 51 |