Kjapp og trygg hosting for Wordpress

Slå sammen kode/ rydde opp i functions.php

Tonny Kluften

Administrator
Hvordan kan jeg skrive følgende funksjon enklere?

PHP:
// 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 ) );
}
 
Topp