Created
October 6, 2017 13:49
-
-
Save sureshHARDIYA/97b78c9d72f4d1ab5237605b320d59e4 to your computer and use it in GitHub Desktop.
Saving custom fields in woocommerce
This file contains 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
<?php | |
function woo_add_custom_general_fields_save( $post_id ){ | |
// Text Field | |
$woocommerce_text_field = $_POST['_text_field']; | |
if( !empty( $woocommerce_text_field ) ) | |
update_post_meta( $post_id, '_text_field', esc_attr( $woocommerce_text_field ) ); | |
// Number Field | |
$woocommerce_number_field = $_POST['_number_field']; | |
if( !empty( $woocommerce_number_field ) ) | |
update_post_meta( $post_id, '_number_field', esc_attr( $woocommerce_number_field ) ); | |
// Textarea | |
$woocommerce_textarea = $_POST['_textarea']; | |
if( !empty( $woocommerce_textarea ) ) | |
update_post_meta( $post_id, '_textarea', esc_html( $woocommerce_textarea ) ); | |
// Select | |
$woocommerce_select = $_POST['_select']; | |
if( !empty( $woocommerce_select ) ) | |
update_post_meta( $post_id, '_select', esc_attr( $woocommerce_select ) ); | |
// Checkbox | |
$woocommerce_checkbox = isset( $_POST['_checkbox'] ) ? 'yes' : 'no'; | |
update_post_meta( $post_id, '_checkbox', $woocommerce_checkbox ); | |
// Custom Field | |
$custom_field_type = array( esc_attr( $_POST['_field_one'] ), esc_attr( $_POST['_field_two'] ) ); | |
update_post_meta( $post_id, '_custom_field_type', $custom_field_type ); | |
// Hidden Field | |
$woocommerce_hidden_field = $_POST['_hidden_field']; | |
if( !empty( $woocommerce_hidden_field ) ) | |
update_post_meta( $post_id, '_hidden_field', esc_attr( $woocommerce_hidden_field ) ); | |
// Product Field Type | |
$product_field_type = $_POST['product_field_type']; | |
update_post_meta( $post_id, '_product_field_type_ids', $product_field_type ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment