php - Adding product permalink on admin order page throwing error

I have added product permalink on admin order page using the below code:function fpd_custom_order_item_values1($item_id,

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745265785a4619446.html

相关推荐

  • php - Adding product permalink on admin order page throwing error

    I have added product permalink on admin order page using the below code:function fpd_custom_order_item_values1($item_id,

    7小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信