0

I have added product permalink on admin order page using the below code:

function fpd_custom_order_item_values1($item_id, $item,$product) {
  global $post_id;  

    if (!empty( $product->get_id())){
    $url =  get_permalink( $product->get_id() );

  $itemdata = array($product->get_sku(), $post_id,$url);  


  echo '<p>' . implode('_', $itemdata) . '</p>';
}
}

add_action( 'woocommerce_before_order_itemmeta', 'fpd_custom_order_item_values1', 100, 3);

This is throwing up this error when the order contains flat rate shipping:

 Uncaught Error: Call to a member function get_id() on null

However, when there is no shipping in order, the code works fine. I have enclosed the code in this if condition if (!empty( $product->get_id())){ but the error is still there. How to resolve this error?

  • What does $product contain? Also, is it an object or an array? – user173076 Aug 6 at 11:44
  • try isset() instead of !empty() – Peter HvD Aug 6 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.