• Resolved mpantogi

    (@mpantogi)


    Hello,

    i try to display an advanced custom field which i have created in my products to the pdf invoice, below the product, using the below code:

    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
    function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
        // check if product exists first
        if (empty($item['product'])) return;
      
        // replace 'Location' with your custom field name!
        $field_name = 'Supermarket';
        $explain_idea_1 = method_exists($item['product'], 'get_meta') ? $item['product']->get_meta($field_name,true,'edit') : get_post_meta( $item['product']->id, $field_name, true );
        if (!empty($explain_idea_1)) {
            echo '<div class="product-Supermarket">Supermarket: '.$explain_idea_1.'</div>';
        }
    }

    This doesn’t work, nothing change. Also i tried to insert _explain_idea_1 instead for explain_idea_1, but this doesn’t work too.

    Please can you advise
    Thank you

    • This topic was modified 6 years ago by mpantogi.
    • This topic was modified 6 years ago by mpantogi.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! To be able to help you we need a bit more information about where the sypermarket name is stored. The method you’re currently using retrieves it from the product custom fields. Could you show us a screenshot of where this data is stored and under what name? If you could install the Store Toolkit that would also help find the actual internal name (meta key) for the custom field (much like described in our “Finding WooCommerce Custom Fields” guide, except yours would be in the product instead of the order, if I understand correctly).

    Let us know what you find!

    Thread Starter mpantogi

    (@mpantogi)

    Hello Sir,

    Please check the associate image for that.

    View post on imgur.com

    Regards

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! Instead of:

    
    $field_name = 'Supermarket';
    

    you need:

    
    $field_name = 'explain_idea_1';
    

    This should work:

    
    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_product_custom_field', 10, 3 );
    function wpo_wcpdf_product_custom_field ( $template_type, $item, $order ) {
        // check if product exists first
        if (empty($item['product'])) return;
      
        $field_name = 'explain_idea_1';
        $explain_idea_1 = $item['product']->get_meta( $field_name, true );
        if (!empty($explain_idea_1)) {
            echo '<div class="product-Supermarket">Supermarket: '.$explain_idea_1.'</div>';
        }
    }
    
    Thread Starter mpantogi

    (@mpantogi)

    Thank you Very much, It works fine.
    You are awesome.

    Plugin Contributor Ewout

    (@pomegranate)

    very glad to hear that. Have a fabulous weekend!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display Woocommerce Advanced custom field’ is closed to new replies.