Created
April 10, 2015 16:28
-
-
Save trys/ec42ccea1cdd919be406 to your computer and use it in GitHub Desktop.
Add field to WooCommerce product information panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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