-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyplugin.php
54 lines (49 loc) · 1.87 KB
/
myplugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Plugin Name: Myplugin
* Description: A block to demonstrate extending the Product Editor
* Version: 0.1.0
* Requires at least: 6.2
* WC requires at least: 7.8
* Requires PHP: 7.4
* Author: The WordPress Contributors
* License: GPL-3.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: myplugin
*
* @package extension
*/
use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\BlockRegistry;
/**
* 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 myplugin_myplugin_block_init() {
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wc-admin' ) {
BlockRegistry::get_instance()->register_block_type_from_metadata( __DIR__ . '/build' );
}
}
add_action( 'init', 'myplugin_myplugin_block_init' );
function myplugin_myplugin_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' );
if ( $basic_details ) {
$basic_details->add_block(
[
'id' => 'extension-myplugin',
'order' => 40,
'blockName' => 'extension/myplugin',
'attributes' => [
'message' => 'Myplugin',
]
]
);
}
}
}
add_filter( 'woocommerce_block_template_register', 'myplugin_myplugin_add_block_to_product_editor', 100 );