2023-05-26 12:16:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Plugin Name: {{title}}
|
|
|
|
{{#pluginURI}}
|
|
|
|
* Plugin URI: {{{pluginURI}}}
|
|
|
|
{{/pluginURI}}
|
|
|
|
{{#description}}
|
|
|
|
* Description: {{description}}
|
|
|
|
{{/description}}
|
|
|
|
* Version: {{version}}
|
|
|
|
* Requires at least: 6.2
|
|
|
|
* WC requires at least: 7.8
|
2023-08-22 07:21:09 +00:00
|
|
|
* Requires PHP: 7.4
|
2023-05-26 12:16:57 +00:00
|
|
|
{{#author}}
|
|
|
|
* Author: {{author}}
|
|
|
|
{{/author}}
|
|
|
|
{{#license}}
|
|
|
|
* License: {{license}}
|
|
|
|
{{/license}}
|
|
|
|
{{#licenseURI}}
|
|
|
|
* License URI: {{{licenseURI}}}
|
|
|
|
{{/licenseURI}}
|
|
|
|
* Text Domain: {{textdomain}}
|
|
|
|
{{#domainPath}}
|
|
|
|
* Domain Path: {{{domainPath}}}
|
|
|
|
{{/domainPath}}
|
|
|
|
{{#updateURI}}
|
|
|
|
* Update URI: {{{updateURI}}}
|
|
|
|
{{/updateURI}}
|
|
|
|
*
|
|
|
|
* @package {{namespace}}
|
|
|
|
*/
|
|
|
|
|
2023-08-31 20:05:43 +00:00
|
|
|
use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;
|
|
|
|
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface;
|
2023-12-13 13:38:33 +00:00
|
|
|
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\BlockRegistry;
|
|
|
|
|
2023-08-31 20:05:43 +00:00
|
|
|
|
2023-05-26 12:16:57 +00:00
|
|
|
/**
|
|
|
|
* Registers the block using the metadata loaded from the `block.json` file.
|
|
|
|
* Behind the scenes, it registers also all assets so they can be enqueued
|
|
|
|
* through the block editor in the corresponding context.
|
|
|
|
*
|
|
|
|
* @see https://developer.wordpress.org/reference/functions/register_block_type/
|
|
|
|
*/
|
|
|
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
|
|
|
|
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wc-admin' ) {
|
2023-12-13 13:38:33 +00:00
|
|
|
BlockRegistry::get_instance()->register_block_type_from_metadata( __DIR__ . '/build' );
|
2023-05-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
|
|
|
|
|
2023-08-31 20:05:43 +00:00
|
|
|
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_add_block_to_product_editor( BlockTemplateInterface $template ) {
|
|
|
|
if ( $template instanceof ProductFormTemplateInterface && 'simple-product' === $template->get_id() ) {
|
|
|
|
$basic_details = $template->get_section_by_id( 'basic-details' );
|
2023-05-26 12:16:57 +00:00
|
|
|
|
2023-08-31 20:05:43 +00:00
|
|
|
if ( $basic_details ) {
|
|
|
|
$basic_details->add_block(
|
|
|
|
[
|
2023-08-31 21:07:14 +00:00
|
|
|
'id' => '{{namespace}}-{{slug}}',
|
2023-08-31 20:05:43 +00:00
|
|
|
'order' => 40,
|
2023-08-31 21:07:14 +00:00
|
|
|
'blockName' => '{{namespace}}/{{slug}}',
|
2023-08-31 20:05:43 +00:00
|
|
|
'attributes' => [
|
|
|
|
'message' => '{{title}}',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
2023-05-26 12:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-31 20:05:43 +00:00
|
|
|
add_filter( 'woocommerce_block_template_register', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_add_block_to_product_editor', 100 );
|