• Hi everyone,

    I am desperately looking for some help on getting product attributes information from a completed order.

    In fact, I have a PDF file generated and sent to customer when order is completed. This file get the information from attributes, but not if the attribute is set to “Any”. For now, I would have to generate all the variations from attributes to display the current “Any” attribute on my PDF file but this is not a solution I can consider (too much variation would be created)

    I found a topic where apparently someone had approximately the same purpose and gave a part of the solution, but, since I am not “fluent” in php, I cannot find the right code to do so…

    Here is the topic I am referring to :
    https://www.ads-software.com/support/topic/woocommerce-getting-variable-product-attribute-value-from-order/

    I contacted the support of the extension where I need to implement the attribute terms and they sent me a “global” code. Unfortunately, this code implement a bunch of information I do not need… Here is the code I have been sent :

    <?php if ( ! empty( $ticket['WooCommerceEventsVariations'] ) ) : ?>
      <?php
        $hidden_order_itemmeta = apply_filters(
          'woocommerce_hidden_order_itemmeta',
          array(
            '_qty',
            '_tax_class',
            '_product_id',
            '_variation_id',
            '_line_subtotal',
            '_line_subtotal_tax',
            '_line_total',
            '_line_tax',
            'method_id',
            'cost',
            '_reduced_stock',
            '_restock_refunded_items',
          )
        );
        // Get an instance of the WC_Order object from an Order ID
        $order = wc_get_order( $ticket["WooCommerceEventsOrderID"] ); 
    
        // Loop though order "line items"
        foreach( $order->get_items() as $item_id => $item ) :
          $meta_data = $item->get_all_formatted_meta_data( '' );
          if ( $meta_data ) :
            ?>
            
              <?php
              foreach ( $meta_data as $meta_id => $meta ) :
                if ( in_array( $meta->key, $hidden_order_itemmeta, true ) ) {
                  continue;
                }
                ?>
                <?php echo '<b>' . $meta->display_key . ':</b> ' . $meta->display_value ?>
              <?php endforeach; ?>
          <?php endif; ?>
        <?php endforeach; ?>
    <?php endif; ?>

    Can someone help me to find the solution I need please, including the <?php> tags and the right code ? I would be so grateful… It has been days since I am looking for a solution without knowing anyone to help in my area as my webmaster is on holidays

    Thanks in advance for any help you could give…

  • The topic ‘Woocommerce : Getting variable product attribute value from order’ is closed to new replies.