如何在WooCommerce PDF包装单上显示产品类别ACF(高级自定义字段)?

时间:2020-06-19 17:29:06

标签: php wordpress woocommerce

我正在尝试在装箱单上显示预计的交货时间。 (WP过夜WooCommerce PDF发票和装箱单)。

我正在使用显示类别字段或产品类别字段(如果有)的代码段。在我网站上的其他地方都可以正常工作。

我正在弄弄这个片段:https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-product-custom-fields/

这是我到目前为止所掌握的。

<?php
add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );

function wpo_wcpdf_product_custom_field( $template_type, $item, $order ) {
  if ( $template_type == 'packing-slip' ) {
    // check if product exists first
    if ( empty( $item[ 'product' ] ) ) return;
    // Check en display delivery time

    if ( $plevertijd = get_field( 'plevertijd', $item->get_product_id() ) ) {
      echo '
       <p style="font-size: small; margin-top: 10px;">Verwachte levertijd: ' . $plevertijd . ' (vanaf besteldatum)</p>
       ';
    } else {
      $terms = get_the_terms( $item->get_product_id(), 'product_cat' );

      if ( !empty( $terms ) ) {
        $term = array_pop( $terms );

        if ( $levertijd = get_field( 'levertijd', $term ) ) {
          echo '
            <p style="font-size: small; margin-top: 10px;">Verwachte levertijd: ' . $levertijd . ' (vanaf besteldatum)</p>
            ';
        }
      }
    }
  }
}
?>

但这给了我一个错误:

致命错误:在数组上调用成员函数get_product_id()

有人知道如何解决吗?

0 个答案:

没有答案