Skip to content

Instantly share code, notes, and snippets.

@jan-koch
Created November 15, 2018 13:09
Show Gist options
  • Save jan-koch/5dd8897b974969ed66204e92f6a05ef4 to your computer and use it in GitHub Desktop.
Save jan-koch/5dd8897b974969ed66204e92f6a05ef4 to your computer and use it in GitHub Desktop.
Example of adding a select box to the "General" product data tab.
<?php
function prefix_add_selectbox() {
$args = array(
'id' => 'my_new_select', // required. The meta_key ID for the stored value
'wrapper_class' => '', // a custom wrapper class if needed
'desc_tip' => true, // makes your description show up with a "?" symbol and as a tooltip
'description' => __('My awesome select box', 'your_text_domain'),
'label' => __( 'My New Select', 'your_text_domain' ),
'options' => array(
'value1' => __( 'Text 1', 'your_text_domain' ),
'value2' => __( 'Text 2', 'your_text_domain' )
)
);
woocommerce_wp_select( $args );
}
add_action( 'woocommerce_product_options_tax', 'prefix_add_selectbox' );
@jan-koch
Copy link
Author

jan-koch commented Mar 4, 2020

Nice code, but how can I let it appear on the product page?

You would extend your child theme and query the field using get_post_meta(). Field ID is set in line 4 in my code, that's what you'd reference in get_post_meta().

@elmatador1170
Copy link

I don't know how to do that because I don't have any PHP experience. Can you maybe suggest any code which could help me?

thanks in advance

@jan-koch
Copy link
Author

jan-koch commented Mar 5, 2020 via email

@elmatador1170
Copy link

That's what I thought.

Still thanks Jan!

@jimvadams
Copy link

Hi Jan, thanks for this amazing code snippet, is there an option to make the new Field appears in the quick edit page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment