Skip to content

Instantly share code, notes, and snippets.

@jan-koch
Last active January 23, 2021 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jan-koch/c0efab4f2ec7222eab50e4646be01971 to your computer and use it in GitHub Desktop.
Save jan-koch/c0efab4f2ec7222eab50e4646be01971 to your computer and use it in GitHub Desktop.
Example implementation of radio buttons as product meta fields, in the "General" tab.
<?php
function prefix_add_radio_buttons() {
$args = array(
'label' => '', // Text in the label in the editor
'class' => 'prefix_radio', // custom class
'style' => '',
'wrapper_class' => '', // custom wrapper class
'value' => '', // if empty, retrieved from meta_value where id is the meta_key
'id' => '', // required, will be used as meta_key for this field
'name' => 'my_radio_buttons', // required if you want only one option to be selected at a time
'options' => array( // options for radio inputs, array
'value1' => __( 'Option 1', 'your_text_domain' ),
'value2' => __( 'Option 2', 'your_text_domain' )
),
'desc_tip' => '', // true or false. Controls whether your description is shown directly or as tooltip
'description' => '' // provide a useful description
);
woocommerce_wp_radio( $args );
}
add_action( 'woocommerce_product_options_tax', 'prefix_add_radio_buttons' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment