Skip to main content

How to add custom meta value in edit order page in Woo-commerce in Wordpress?

Add custom meta value in edit order page in Woo-commerce in Wordpress? 


//===============add meta data on edit order page =========================
/**
 * @param $item_id
 * @param $item
 * @param $product   Product
 */
function wpcodekit_order_meta_customized_display( $item_id, $item, $product ) {
global $woocommerce, $post;
    /*
    *  The default key to "$all_meta_data" can be: _qty,_tax_class,_line_tax,_line_tax_data,_variation_id,_product_id,_line_subtotal, _line_total,_line_subtotal_tax
    */
    $all_meta_data = get_metadata( 'order_item', $item_id, "", "" );  
//print_r($product);
echo $product->get_id();
echo $order_id = $post->ID;
/* 
$order = new WC_Order($post->ID);
//to escape # from order id 
echo $order_id = trim(str_replace('#', '', $order->get_order_number())); */



    ?>
    <div class="order_data_column" style="width: 50%; padding: 0 5px;">
        <h4><?php _e( 'Customized Values' ); ?></h4>
        <?php
            echo '<p><span style="display:inline-block; width:100px;">' . __( "Item to show 01" ) . '</span><span>:&nbsp;' . "Value to show 01" . '</span></p>';
    ?>
     </div>
<?php
}


add_action( 'woocommerce_after_order_itemmeta', 'wpcodekit_order_meta_customized_display',10, 3 );

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...