# Slå sammen kode/ rydde opp i functions.php

**URL:** <http://webforumet.no/t/sla-sammen-kode-rydde-opp-i-functions-php/20328>\
**Category:** Innholds-kontroll\
**Tags:** wordpress\
**Created:** [januar 10, 2014, 3:09pm UTC](http://webforumet.no/t/sla-sammen-kode-rydde-opp-i-functions-php/20328 "2014-01-10T15:09:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tonny\_Kluften](http://webforumet.no/user_avatar/webforumet.no/tonny_kluften/32/1317_2.png) [@Tonny\_Kluften](http://webforumet.no/u/Tonny_Kluften)\
**Post date:** [januar 10, 2014, 3:09pm UTC](http://webforumet.no/t/sla-sammen-kode-rydde-opp-i-functions-php/20328/1 "2014-01-10T15:09:46Z")

</div>

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 ) );  
}[/PHP]
