• Resolved lawkwok

    (@lawkwok)


    Hi,

    Is anyone else not able to display product attributes after updating to WooCommerce 3.0.0?

    if(!empty($item[‘product’])) $wpo_wcpdf->product_attribute(‘attribute’, $item[‘product’])

    – Lawrence

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

    (@pomegranate)

    Works in my own tests. Are you using 1.6.1?

    Thread Starter lawkwok

    (@lawkwok)

    That is strange! I am using 1.6.1.

    I’ve done the following:
    – Disable all plugins except for WooCommerce
    – Changed to the TwentyFifteen theme
    – Use the Simple invoice theme
    – Prefix the attribute name with ‘pa_’

    Plugin Contributor Ewout

    (@pomegranate)

    What kind of attribute is this? I have tried a custom attribute:
    Custom attribute
    and a preset/regular attribute (WooCommerce > Attributes):
    regular attribute
    and both show up on the invoice:
    attributes on invoice

    Turning on/off “Visible on the product page” didn’t make any difference.

    Here’s the snippet I used:

    
    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_attributes', 10, 3 );
    function wpo_wcpdf_show_product_attributes ( $template_type, $item, $order ) {
        global $wpo_wcpdf;
        if(empty($item['product'])) return;
        printf('<div class="product-attribute">Custom attribute: %s</div>', $wpo_wcpdf->get_product_attribute('Custom Attribute', $item['product']));
        printf('<div class="product-attribute">Preset attribute: %s</div>', $wpo_wcpdf->get_product_attribute('color', $item['product']));
    }
    

    I also tested your version:

    
    $wpo_wcpdf->product_attribute('color', $item['product']);
    

    Which works just as well.

    Do you spot any differences?

    Thread Starter lawkwok

    (@lawkwok)

    I don’t see any differences. The code works on certain attributes, but not others. I have also tried custom and regular attributes.

    Even stranger is that even among two products with the same attributes, the invoice for product 1 shows the attribute, but not the invoice for product 2.

    Plugin Contributor Ewout

    (@pomegranate)

    do you have this issue with WC3.0.1 too?

    from the changelog:

    * Fix – Fixed display of variation attributes on old orders.

    Could you try resaving the product with the attributes that are not showing up to see if that solves the issue?

    Thread Starter lawkwok

    (@lawkwok)

    The WooCommerce update didn’t fix it ?? I’ve tried deleting the attribute and re-adding too.

    • This reply was modified 7 years, 11 months ago by lawkwok.
    Plugin Contributor Ewout

    (@pomegranate)

    I’m still investigating. It seems that WC3.0.2 even broke more, where $product->get_attribute() seems to crash on custom attributes…

    Plugin Contributor Ewout

    (@pomegranate)

    I opened an issue for this yesterday and at least the crash with the custom attributes is fixed: https://github.com/woocommerce/woocommerce/issues/14345
    Hopefully this fixes your issue too (with 3.0.3) – let me know!

    Thread Starter lawkwok

    (@lawkwok)

    Unfortunately both code snippets still don’t work. Are you able to display product attributes?

    I’m using WooCommerce PDF Invoices & Packing Slips 1.6.4 and WooCommerce 3.0.3

    Plugin Contributor Ewout

    (@pomegranate)

    Yes I’m still able to display product attributes with the above code snippets:
    However, it looks like WooCommerce is still changing how this works with the past releases. I have found that it only displays when:

    • The product is the main product
    • The product is a variation product and the attribute has been set as ‘Used for variations’

    It seems that if you want to show a product attribute of a variation that is not used for variations, you have to query the parent product…

    Thread Starter lawkwok

    (@lawkwok)

    I a, able to reproduce your findings.

    Below is the updated code to display a variation product’s attribute in WC 3 (without necessarily needing ‘Used for variations’ to be enabled):

    $wpo_wcpdf->product_attribute('brand', $item['product']->parent);

    You indeed need to query the parent product. Also, it only works with product_attribute() and not get_product_attribute().

    Thanks for your help as always, Ewout!

    • This reply was modified 7 years, 11 months ago by lawkwok.
    • This reply was modified 7 years, 11 months ago by lawkwok.
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Displaying product attributes no longer works’ is closed to new replies.