Created
December 7, 2023 00:45
-
-
Save J2112O/9df871cb605a9202657c16d40f11a501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface; | |
if ( ! function_exists( 'woo_prod_editor_custom_add_block' ) ) { | |
/** | |
* Add a new block to the template after the product name field. | |
* | |
* @param BlockInterface $product_name_field The product name block. | |
*/ | |
function woo_prod_editor_custom_add_block( BlockInterface $product_name_field ) { | |
$parent = $product_name_field->get_parent(); | |
if ( ! method_exists( $parent, 'add_block' ) ) { | |
return; | |
} | |
$parent->add_block( | |
[ | |
'id' => 'custom-editor-text-block', | |
'order' => $product_name_field->get_order() + 5, | |
'blockName' => 'woocommerce/product-text-field', | |
'attributes' => array( | |
'property' => 'meta_data.example_block_property', | |
'label' => __( 'Custom Example Block', 'astra-child' ), | |
), | |
] | |
); | |
} | |
add_action( | |
'woocommerce_block_template_area_product-form_after_add_block_product-name', | |
'woo_prod_editor_custom_add_block' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment