Skip to content

Instantly share code, notes, and snippets.

@J2112O
Created December 7, 2023 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J2112O/9df871cb605a9202657c16d40f11a501 to your computer and use it in GitHub Desktop.
Save J2112O/9df871cb605a9202657c16d40f11a501 to your computer and use it in GitHub Desktop.
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