Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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' );
@elmatador1170

This comment has been minimized.

Copy link

@elmatador1170 elmatador1170 commented Mar 3, 2020

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

@jan-koch

This comment has been minimized.

Copy link
Owner Author

@jan-koch 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

This comment has been minimized.

Copy link

@elmatador1170 elmatador1170 commented Mar 4, 2020

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

This comment has been minimized.

Copy link
Owner Author

@jan-koch jan-koch commented Mar 5, 2020

@elmatador1170

This comment has been minimized.

Copy link

@elmatador1170 elmatador1170 commented Mar 5, 2020

That's what I thought.

Still thanks Jan!

@jimvadams

This comment has been minimized.

Copy link

@jimvadams jimvadams commented Nov 5, 2020

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