admin管理员组

文章数量:1417463

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?

本文标签: phpAdding product permalink on admin order page throwing error