Skip to content

Instantly share code, notes, and snippets.

@joshuatf
Last active July 14, 2023 02:18
Show Gist options
  • Save joshuatf/8eb3fbd4885e68cee9f3166260a55153 to your computer and use it in GitHub Desktop.
Save joshuatf/8eb3fbd4885e68cee9f3166260a55153 to your computer and use it in GitHub Desktop.
Product template extensibility
<?php
/**
* Plugin Name: Test Plugin
* Author: Joshua Flowers
* Version: 0.1.0
*/
function test_plugin_modify_product_template() {
$template_registry = Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductTemplateRegistry::get_instance();
$simple_template = $template_registry->get_registered( 'simple' );
if ( ! $simple_template ) {
return;
}
$simple_template->add_field(
array(
'parent' => $simple_template::BASIC_DETAILS_SECTION,
'block' => array(
'woocommerce/product-radio-field',
array(
'title' => __( 'Custom radio', 'text-domain' ),
'description' => __( 'Custom radio field description.', 'text-domain' ),
'property' => 'product_property',
'options' => array(
array(
'label' => __( 'Option A', 'text-domain' ),
'value' => 'a',
),
array(
'label' => __( 'Option B', 'text-domain' ),
'value' => 'b',
),
array(
'label' => __( 'Option C', 'text-domain' ),
'value' => 'c',
),
),
),
),
)
);
}
add_action( 'init', 'test_plugin_modify_product_template' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment