最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom PLU field in woocommerce email

programmeradmin2浏览0评论

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. 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' );
发布评论

评论列表(0)

  1. 暂无评论