• Resolved infosws

    (@nicksws)


    I’m trying to add the column for the Parent SKU of the product.

    I’ve tried adding this code to the Misc code area and also theme functions.php

    add_filter('woe_get_order_product_value_parent_sku', function ($value, $order, $item, $product, $item_meta) {
       $parent_id = $product->get_parent_id();
       $value = get_post_meta($parent_id , '_sku', true);
       return $value;
    }, 10, 5);

    This code seems to work fine when I preview the export but not when I run it.
    I get

    PHP Fatal error: Uncaught Error: Call to a member function get_parent_id()

    I’ve looked over the forum and support website and snippets but can’t find how to do this.

    Can you help?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hi

    the product was deleted and $product=false
    Could you try this version ?

    add_filter('woe_get_order_product_value_parent_sku', function ($value, $order, $item, $product, $item_meta) {
       if($product) {
         $parent_id = $product->get_parent_id();
         $value = get_post_meta($parent_id , '_sku', true);
       }
       return $value;
    }, 10, 5);
    Thread Starter infosws

    (@nicksws)

    Hi,

    It wasn’t that the product was deleted but it may be due to some products being single and not variable products.
    Strange that it didn’t seem to show the error while previewing the export.

    But the proposed code did work and return the correct value in the export for variable products.

    Many thanks for your help.

    Plugin Author algol.plus

    (@algolplus)

    Button Preview exports first 5 orders by default.

    You’re welcome

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Export parent SKU of product’ is closed to new replies.