Skip to content

Instantly share code, notes, and snippets.

@organizm
Last active August 17, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save organizm/9cb09a9de496390c3dfecfe6a541bd38 to your computer and use it in GitHub Desktop.
Save organizm/9cb09a9de496390c3dfecfe6a541bd38 to your computer and use it in GitHub Desktop.
Add new field to woocommerce product metabox (this example for pricing tab simple product) #wordpress #woocommerce
<?php
add_action('woocommerce_product_options_pricing', 'atlantean_coming_soon');
function atlantean_coming_soon() {
woocommerce_wp_checkbox( array(
'id' => '_coming_soon',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'Coming soon', 'woocommerce' ),
'description' => __( 'Enable coming soon label', 'woocommerce' )
) );
}
add_action('woocommerce_process_product_meta_simple', 'atlantean_save_coming_soon');
function atlantean_save_coming_soon($post_id) {
update_post_meta($post_id, '_coming_soon', esc_attr($_POST['_coming_soon']));
}
add_action( 'category_add_form_fields', '___add_form_field_term_meta_text' );
function ___add_form_field_term_meta_text() { ?>
<?php wp_nonce_field( basename( __FILE__ ), 'term_meta_text_nonce' ); ?>
<div class="form-field term-meta-text-wrap">
<label for="term-meta-text"><?php _e( 'TERM META TEXT', 'text_domain' ); ?></label>
<input type="text" name="term_meta_text" id="term-meta-text" value="" class="term-meta-text-field" />
</div>
<?php }
// ADD FIELD TO CATEGORY EDIT PAGE
add_action( 'category_edit_form_fields', '___edit_form_field_term_meta_text' );
function ___edit_form_field_term_meta_text( $term ) {
$value = ___get_term_meta_text( $term->term_id );
if ( ! $value )
$value = ""; ?>
<tr class="form-field term-meta-text-wrap">
<th scope="row"><label for="term-meta-text"><?php _e( 'TERM META TEXT', 'text_domain' ); ?></label></th>
<td>
<?php wp_nonce_field( basename( __FILE__ ), 'term_meta_text_nonce' ); ?>
<input type="text" name="term_meta_text" id="term-meta-text" value="<?php echo esc_attr( $value ); ?>" class="term-meta-text-field" />
</td>
</tr>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment