Simplify code for functions.php
-
Hi.
At ledlysp?rer.no I need to make some modification to woocommerce to add more product data. The code below works for making custom fields for the product data. But how to simplify that code? I have made three new fields in that code, but need ten, so simplifying it would be great to keep the size of functions.php down.
Thanks for all help ??
// Display Fields add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); // Save Fields add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' ); function woo_add_custom_general_fields() { global $woocommerce, $post; // Text area woocommerce_wp_textarea_input( array( 'id' => '_textarea', 'label' => __( 'Beskrivelse', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => 'true', 'description' => __( 'Enter the custom value here.', 'woocommerce' ) ) ); global $woocommerce, $post; // Text area2 woocommerce_wp_textarea_input( array( 'id' => '_textarea2', 'label' => __( '?rstall', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => 'true', 'description' => __( 'Enter the custom value here.', 'woocommerce' ) ) ); global $woocommerce, $post; // Text area3 woocommerce_wp_textarea_input( array( 'id' => '_textarea3', 'label' => __( 'Tidsepoke', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => 'true', 'description' => __( 'Enter the custom value here.', 'woocommerce' ) ) ); } function woo_add_custom_general_fields_save( $post_id ){ // Textarea $woocommerce_textarea = $_POST['_textarea']; if( !empty( $woocommerce_textarea ) ) update_post_meta( $post_id, '_textarea', esc_html( $woocommerce_textarea ) ); // Textarea2 $woocommerce_textarea = $_POST['_textarea2']; if( !empty( $woocommerce_textarea ) ) update_post_meta( $post_id, '_textarea2', esc_html( $woocommerce_textarea ) ); // Textarea3 $woocommerce_textarea = $_POST['_textarea3'];if( !empty( $woocommerce_textarea ) )update_post_meta( $post_id, '_textarea3', esc_html( $woocommerce_textarea ) ); }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Simplify code for functions.php’ is closed to new replies.