2
I’m having a problem with Woocommerce. I added a field that does not have in the standard of Woocommerce that would add the amount of products that go inside the master box of the product.
The code I’m using in my Function.php is as follows::
<?php
//ADICIONANDO UM NOVO CAMPO NA AREA DE EDICAO DO PRODUTO
/// 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' );
/**Fields Container
**/
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Textarea
woocommerce_wp_text_input(
array(
'id' => '_embalageminput',
'label' => __( 'Embalagem', 'woocommerce' ),
'placeholder' => '',
'description' => __( 'Quantidade de Peças por Caixa.', 'woocommerce' )
)
);
// END Textarea
echo '</div>';
}
function woo_add_custom_general_fields_save(){
// Textarea
$woocommerce_embalagem = $_POST['_embalageminput'];
if( !empty( $woocommerce_embalagem ) )
update_post_meta( $post_id, ‘_embalageminput’, esc_attr( $woocommerce_embalagem) );
echo get_post_meta( get_the_ID(), '_embalageminput', true );
}
?>
When I update the product and come back it does not have the field with the displayed value. Does anyone know what I might be missing?