| 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 MainSection { |
| 9 |
|
| 10 |
const ID = 'tiered-pricing-table/product-editor-main-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' => 10, |
| 37 |
'attributes' => array( |
| 38 |
'title' => __( 'Tiered Pricing', 'tier-pricing-table' ), |
| 39 |
'description' => __( 'Specify tiered pricing and quantity limits.', '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/main-section/supported_types', |
| 48 |
array( 'product-variation', 'simple-product' ) ); |
| 49 |
} |
| 50 |
} |
| 51 |
|