Friday, June 10, 2022
HomeWordPress Developmentwoocommerce offtopic - Show customized product possibility in admin order particulars

woocommerce offtopic – Show customized product possibility in admin order particulars


I am making an attempt to show the customized product possibility in admin order panel.

I used to be in a position to move all the information till the order is accomplished, however within the admin panel the information is returned is empty array.

I share the code

add_action('woocommerce_checkout_create_order_line_item', 'save_order_item_product_fitting_color', 10, 4 );
perform save_order_item_product_fitting_color( $merchandise, $cart_item_key, $cart_item, $order ) {
    
        //$item->update_meta_data( 'orderSpec', $cart_item['orderSpec'] );
         // The WC_Product occasion Object
         $product = $item->get_product();
    
         // Get worth
         $cart_item = $product->get_meta( 'orderSpec' );
         
         // NOT empty
         if ( ! empty ( $cart_item ) ) {
             $item->update_meta_data( 'orderSpec', $cart_item );
         }

    
}

// Add header
perform action_woocommerce_admin_order_item_headers( $order ) {
    // Set the column title
    $column_name = __( 'Specifiche', 'woocommerce' );
    
    // Show the column title
    echo '<th  class="my-class">' . $column_name . '</th>';
}
add_action( 'woocommerce_admin_order_item_headers', 'action_woocommerce_admin_order_item_headers', 10, 1 );



//Add content material
perform action_woocommerce_admin_order_item_values( $product, $merchandise, $item_id ) {
    // Just for "line_item" gadgets sort, to keep away from errors
    if ( ! $item->is_type('line_item') ) return;

    // Get worth
    $cart_item = $item->get_meta( 'orderSpec' );
    
    

    // NOT empty
    if ( ! empty ( $cart_item ) ) {
        echo '<td>';
         foreach($cart_item as $key => $worth){ 
            
        echo '<robust>'.$key.'</robust> : '.$worth;
    
    } 
    echo '</td>';
    } else {
        echo '<td>Meta not discovered!</td>';        
    }
}
add_action( 'woocommerce_admin_order_item_values', 'action_woocommerce_admin_order_item_values', 10, 3 );

Thanks to your assist

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments