• Resolved Benjamin Pau

    (@soapking)


    I’m currently trying to pull in data from woocommerce product custom field that I’ve created using WP Admin Site Enhancements pro plugin with the field name ‘availability’ as shown.

    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_item_availability', 10, 3 );
    
    function wpo_wcpdf_item_availability( $document_type, $order, $item ) {
      if ( $document_type === 'invoice' ) {
        if ( $item->get_cf( 'availability' ) ) {
          $availability = $item->get_cf( 'availability', true );
    
          ?>
          <tr class="availability">
            <th>Availability:</th>
            <td><?php echo esc_html( $availability ); ?></td>
          </tr>
          <?php
        } else {
          // Handle missing custom field (e.g., display message)
        }
      }
    }

    I tried the above snippet to add the custom field data after item meta but doesn’t seem like it is working.

    I’ve referred to the docs of the custom content type feature of the plugin here: https://www.wpase.com/documentation/custom-field-types/

    Is there anyone that could help? Thanks in advance.

    • This topic was modified 1 year, 3 months ago by Benjamin Pau.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @soapking:

    Please check this article from the plugin’s Docs:
    Displaying product custom fields

    Thread Starter Benjamin Pau

    (@soapking)

    Hi Yordan,

    I’ve tried using the below. But nothing is displayed.

    /**
     * Add product availability
     */
    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
    function wpo_wcpdf_product_custom_field ( $document_type, $item, $order ) {
        if ( $document_type == 'invoice' ) {
            if (empty($item['product'])) return;
            $field_name = 'availability';
            $availability = $item['product']->get_meta($field_name,true,'edit');
            if (!empty($availability)) {
                echo '<div class="product-availability">Availability: '.$availability.'</div>';
            }
        }
    }
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @soapking:

    Your code looks good to me: Are you sure availability is the correct meta key for your custom product field?

    See: Finding WooCommerce custom fields

    Thread Starter Benjamin Pau

    (@soapking)

    Pardon me, I assumed it was the field name that I’ve set as “availability”. According to the doc link that you have shared in your reply. I have installed the plugin Store Toolkit for WooCommerce. I went into my own order but I can’t seem to find anything related to my custom field “availability” in the Order Items Meta section…

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @soapking,

    Actually, you have to check that in the product details instead: The code above check for the custom field from the product data, not the order data.

    Based on your comment above:

    I’m currently trying to pull in data from woocommerce product custom field…

    …I understood that you wanted to get the custom field from the product.

    Was this maybe a mistake, and you want to pull the custom field from the order data instead?

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @soapking,

    Since we haven’t heard back from you in the last two weeks, we’re assuming you solved this issue, so I’ll go ahead and mark this ticket as?Resolved.

    Feel free to reply to this topic is you still need help with this, or open a new topic if you have any other questions!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Custom Field Data To Item’ is closed to new replies.