• Resolved IZALK

    (@izalk)


    Hi,

    First of all: great plugin!

    I ran into a problem when editing the template.

    I have added 2 fields to each product variable.
    So lets say you have a T-SHIRT with 3 sizes: M, L, XL. Each of those sizes has it’s own EAN Code and SKU Code.

    On the cart and in the regular order emails I can echo those fields by doing this:

    <?php
    $_product     = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    
    $getean = get_field( "_ean_code", $_product->variation_id );
    $getsku = get_field( "_var_sku", $_product->variation_id );
    echo '<dl class="variation"><dt class="ean-cart">EAN:</dt><dd class="ean-cart"><p>' . $getean . '</p></dd></dl>';
    echo '<dl class="variation"><dt class="sku-cart">SKU:</dt><dd class="sku-cart"><p>' . $getsku . '</p></dd></dl>';
    
    ?>

    Now, I know you use a different global variable, I tried a few different codes with this variable and whatnot, I also used your custom field explanation. but I can’t seem to reach those fields….

    Any pointers? Any help would be appreciated ??

    Thanks in advance.

    https://www.ads-software.com/plugins/woocommerce-pdf-invoices-packing-slips/

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

    (@pomegranate)

    Hello IZALK,
    The product is loaded in $item[‘product’], so I’m guessing that if you replace the first line by:

    $_product = $item['product']

    it should do what you want. Note that it won’t have the woocommerce_cart_item_product filter applied to it, but I think that should not matter in this case. There’s no cart_item data to pass through the filter so there’s no point in running it (I also guess that filter is specifically for the cart and not the order emails?)

    Let me know if that works!
    Ewout

    Thread Starter IZALK

    (@izalk)

    Hi Ewout,

    Thanks for your fast reply..

    I actually just solved it.

    After trying a lot of different things this turned out to work:

    <?php
    $product_var_id = $item['variation_id'];
    $getean = get_field( "_ean_code", $product_var_id );
    $getsku = get_field( "_var_sku", $product_var_id );
    ?>

    Then echo the ean/sku var’s…

    So $item[‘variation_id’]; works….

    Again, thanks for your quick reply.
    Your plugin works really well.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get a custom field from a variable product.’ is closed to new replies.