Skip to content

Instantly share code, notes, and snippets.

@imran-khan1
Last active January 29, 2020 07:14
Show Gist options
  • Save imran-khan1/b87c78626b3a698303a4cb775a05d3ab to your computer and use it in GitHub Desktop.
Save imran-khan1/b87c78626b3a698303a4cb775a05d3ab to your computer and use it in GitHub Desktop.
<?php
// Save All Fields
add_action( 'woocommerce_process_product_meta', 'ci_custom_general_tab_fields_save' );
//Saving Fields Values
function ci_custom_general_tab_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 One
$custom_field_one = esc_attr( $_POST['_field_one'] );
update_post_meta( $post_id, '_custom_field_one', $custom_field_one );
// Custom Field Two
$custom_field_two = esc_attr( $_POST['_field_two'] );
update_post_meta( $post_id, '_custom_field_two', $custom_field_two );
// 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