Skip to content

Instantly share code, notes, and snippets.

@trys
Created April 10, 2015 16:28
Show Gist options
  • Save trys/ec42ccea1cdd919be406 to your computer and use it in GitHub Desktop.
Save trys/ec42ccea1cdd919be406 to your computer and use it in GitHub Desktop.
Add field to WooCommerce product information panel
/**
* Add field to product options
*
* @return void
*/
function projectnamespace_add_product_fields() {
woocommerce_wp_checkbox(
array(
'id' => '_projectnamespace_enquiry_only',
'label' => __( 'Enquiry Only', 'woocommerce' ),
)
);
}
add_action( 'woocommerce_product_options_pricing', 'projectnamespace_add_product_fields' );
/**
* Save field to product post meta
*
* @param int $post_id
* @return void
*/
function projectnamespace_save_product_fields( $post_id ) {
$fields = array( '_projectnamespace_enquiry_only' );
foreach ( $fields as $field )
update_post_meta( $post_id, $field, esc_attr( isset( $_POST[ $field ] ) ? $_POST[ $field ] : '' ) );
}
add_action( 'woocommerce_process_product_meta', 'projectnamespace_save_product_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment