• Resolved technkl

    (@technkl)


    I have a custom checkout field option with 3 boxes to select. They add to the final price of the order and show in the order page in WooCommerce but they don’t show up in the packing slip.

    I created a custom template and I tried using the add custom field instructions from this page: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/ but nothing shows up.

    Is it possible to add this in the packing slip so everything that’s supposed to ship in the order shows in the packing slip?

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

    (@pomegranate)

    Hi! It’s possible you’re not using the correct internal name for the custom fields. Can you check this guide to see if you can find the custom field in the order data, the come back here posting the name of the custom field you found and the code you’re using to display the custom field in the packing slip template?

    Since you mention that it’s a select box that changes prices (and more?) in the order, this sounds like it may be somewhat different from default custom fields.

    Let me know what you find!
    Ewout

    Thread Starter technkl

    (@technkl)

    I was able to use the plugin you mentioned in the guide to find the ID of the custom field. It was _wccf_cf_temp_packs but here’s a link to how it looked with additional fields below it: https://drive.google.com/open?id=0B4YMBFXALG_GM1ZERzhUME4tMG8

    It is a select box that on order checkout gives the buyer 3 options (they can select all 3) and it adds a temperature pack to their order.

    Here’s what it looks like when they’re on check out: https://drive.google.com/open?id=0B4YMBFXALG_GMDV0NlAwaEhwamc

    I used this code to try to put the custom field in the packing slip: <?php $this->custom_field('_wccf_cf_temp_packs'); ?> and it still shows up as blank. Not sure what code to use to get it to display if and what temperature pack is in the order.

    Plugin Contributor Ewout

    (@pomegranate)

    I see, it looks like this data is somewhat more complex. The internal name of the selection is stored in the order, but the actual text shown to the customer is not. Moreover, the _wccf_cf_temp_packs contains an array of choices, since people can select multiple options at once if I interpret the checkboxes correctly. This means you have to make a loop to display the values (which would then still not be the text since that seems to be taken from somewhere else…).

    Here’s an example that converts the options (incomplete but you should be able to substitute the other values.

    
    <?php
    $temp_packs = $this->get_custom_field('_wccf_cf_temp_packs');
    foreach ($temp_packs as $temp_pack) {
        switch ($temp_pack) {
            case 'temp_packs_hot':
                echo 'Hot Packs<br>';
                break;
            case 'temp_packs_cold_3oz':
                echo 'Cold Packs 3oz<br>';
                break;
            case 'temp_packs_cold_6oz':
                echo 'Cold Packs 6oz<br>';
                break;
            default:
                echo $temp_pack.'<br>';
                break;
        }
    }
    ?>
    

    Hope that helps!
    Ewout

    Thread Starter technkl

    (@technkl)

    That absolutely worked perfectly just as you put it. Thank you so much! I created a new row in the table outside the order loop and placed this loop in there and it now shows after the order details.

    Thank you!

    Thread Starter technkl

    (@technkl)

    This solution worked perfect but I’m now trying to put another custom field in the PDF template and for some reason when I formulate it exactly as the above (minus one option) it makes the whole PDF blank.

    It’s a radio button option with only two options that can be in the custom field (or it could be blank if it’s old).

    Right now I have this in there:

    $order_delivery = $this->get_custom_field('_wccf_cf_order_delivery');
    echo $order_delivery;

    It works like that for putting the field in there but it prints the exact custom field which means it’s lowercase and with an underscore. Is there a simple way to define that if the value is home_address then it prints as Home Address?

    I still don’t understand why the above code doesn’t work modified. Maybe I just messed up the modification (which I did triple check).

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! I’m afraid this is somewhat beyond what we can do for you as free support, but it sounds like your order delivery field is not an array but a string (if it displays when you just echo the content. In that case this may solve your issue:

    
    $order_delivery = $this->get_custom_field('_wccf_cf_order_delivery');
    switch ($order_delivery) {
        case 'option_1':
            echo 'Option 1';
            break;
        case 'option_2':
            echo 'Option 2';
            break;
        default:
            echo $order_delivery;
            break;
    }
    

    Hope that helps!
    Ewout

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Possible to add a custom checkout field to the packing slip?’ is closed to new replies.