I have added my custom PLU field to the woocommerce product. I need to add this field to admin email after order. Im not sure how to do it.
Or if you have any other option how to add PLU code what can be a custom product field available for admin only.... Thank you for any help
function woocommerce_render_plu_field() {
$input = array(
'id' => '_plu',
'label' => sprintf(
'<abbr title="%1$s">%2$s</abbr>',
_x( 'Vlastny identifikator', 'field label', 'my-theme' ),
_x( 'PLU', 'abbreviated field label', 'my-theme' )
),
'value' => get_post_meta( get_the_ID(), '_plu', true ),
'desc_tip' => true,
'description' => __( 'Vlastny identifikator (PLU, UPC, EAN, ISBN, atd.)', 'my-theme' ),
);
?>
<div id="plu_attr" class="options_group">
<?php woocommerce_wp_text_input( $input ); ?>
</div>
<?php
}
add_action( 'woocommerce_product_options_inventory_product_data', 'woocommerce_render_plu_field' );
/**
* Save the product's PLU number, if provided.
*
* @param int $product_id The ID of the product being saved.
*/
function woocommerce_save_plu_field( $product_id ) {
if (
! isset( $_POST['_plu'], $_POST['woocommerce_meta_nonce'] )
|| ( defined( 'DOING_AJAX' ) && DOING_AJAX )
|| ! current_user_can( 'edit_products' )
|| ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' )
) {
return;
}
$plu = sanitize_text_field( $_POST['_plu'] );
update_post_meta( $product_id, '_plu', $plu );
}
add_action( 'woocommerce_process_product_meta','woocommerce_save_plu_field' );