| 1 |
<?php namespace TierPricingTable\Addons\AdvancedQuantityOptions\ProductEditor; |
| 2 |
|
| 3 |
use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface; |
| 4 |
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface; |
| 5 |
use TierPricingTable\Addons\ReactProductEditorAddon\ProductEditor as MainProductEditor; |
| 6 |
use TierPricingTable\Addons\ReactProductEditorAddon\Sections\MainSection; |
| 7 |
|
| 8 |
class ProductEditor { |
| 9 |
|
| 10 |
public function __construct() { |
| 11 |
|
| 12 |
add_filter( 'woocommerce_block_template_register', function ( BlockTemplateInterface $template ) { |
| 13 |
|
| 14 |
if ( $template instanceof ProductFormTemplateInterface ) { |
| 15 |
|
| 16 |
$group = $template->get_group_by_id( MainProductEditor::GROUP_ID ); |
| 17 |
|
| 18 |
if ( ! $group ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
$blockWrapper = $template->get_section_by_id( MainSection::ID )->add_block( [ |
| 23 |
'id' => 'tiered-pricing-table/advanced-quantity-options', |
| 24 |
'blockName' => 'woocommerce/product-collapsible', |
| 25 |
'attributes' => [ |
| 26 |
'toggleText' => __( 'Advanced Quantity Options', 'tier-pricing-table' ), |
| 27 |
'initialCollapsed' => true, |
| 28 |
'persistRender' => true, |
| 29 |
], |
| 30 |
] ); |
| 31 |
|
| 32 |
if ( ! tpt_fs()->can_use_premium_code() ) { |
| 33 |
$blockWrapper = $blockWrapper->add_block( array( |
| 34 |
'id' => 'tiered-pricing-table/premium-wrapper__advanced-quantity-options', |
| 35 |
'blockName' => 'tiered-pricing-table/premium-wrapper', |
| 36 |
'attributes' => array( |
| 37 |
'isPremium' => tpt_fs()->can_use_premium_code(), |
| 38 |
), |
| 39 |
) ); |
| 40 |
} |
| 41 |
|
| 42 |
$blocks = [ |
| 43 |
new MaximumOrderQuantityBlock(), |
| 44 |
new QuantityStepBlock(), |
| 45 |
]; |
| 46 |
|
| 47 |
foreach ( $blocks as $block ) { |
| 48 |
|
| 49 |
$section = $template->get_section_by_id( $block->getSectionId() ); |
| 50 |
|
| 51 |
if ( ! $section ) { |
| 52 |
continue; |
| 53 |
} |
| 54 |
$blockWrapper->add_block( [ |
| 55 |
'id' => $block->getId(), |
| 56 |
'order' => $block->getOrder(), |
| 57 |
'blockName' => $block->getBlockName(), |
| 58 |
'attributes' => $block->getAttributes(), |
| 59 |
] ); |
| 60 |
} |
| 61 |
} |
| 62 |
}, 10000 ); |
| 63 |
} |
| 64 |
} |
| 65 |
|