Cost of Goods not showing in export as csv

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #111816
    santosh
    Participant

    Hello,

    We have written a custom export script to export the order detail, but cost of the products always shows as zero.

    To get the cost of the product we have used the below code.

    foreach ($order_items as $item) {
    $product_id = $item->get_product_id();
    $product_cost = $item->get_meta(‘_alg_wc_cog_cost’, true);

    But the cost column in the csv is always empty,
    Please advice if we have used the correct meta? or is there another way of doing this.

    Thanks
    Santosh

    #111821
    santosh
    Participant

    I changed the code to

    $product_cost = get_post_meta( $item_id, ‘_alg_wc_cog_cost’, true );

    It now works

    Thanks
    Santosh

    #112159
    Pablo
    Moderator
    Plugin Support

    Hi Santosh,

    Since you’re getting the cost from an order item, it’s probably more reliable to get it from the order item meta instead of the product meta. You could do it like this:

    foreach ( $order->get_items() as $item_id => $item ) {
    wc_get_order_item_meta( $item_id, '_alg_wc_cog_item_cost' );
    
    • This reply was modified 1 year, 8 months ago by Pablo.
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.