• Resolved Kyle_Irving

    (@kyle_irving)


    Hi
    First up thanks for your excellent plugin.

    Can you advise us on how we would get the country and not the country code to display on the packing slip?

    Currently, this is the code on the template but that displays the country code and not the country

    <?php echo !empty($this->order->get_shipping_country()) ? $this->order->get_shipping_country() . '<br>' : ''; ?>

    Thanks

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

    (@dpeyou)

    Hi @kyle_irving,

    To display the country, you’d need to use WC()->countries, like this:

    WC()->countries->countries[ $order->get_shipping_country() ];

    So you could use this code snippet to display the country after the order data:

    add_action('wpo_wcpdf_after_order_data', 'wpo_wcpdf_show_country', 10, 2); 
    function wpo_wcpdf_show_country ( $template_type, $order ) {
    	// if order is empty, bail!
    	if ( empty($order) ) {return;}
    	
    	$country = WC()->countries->countries[ $order->get_shipping_country() ];
    	
    	?>
    	<tr>
    		<th>Country: </th>
    		<td><?php echo $country; ?></td>
    	</tr>
    	<?php
    }

    If you haven’t used hooks before, check this guide out: https://docs.wpovernight.com/general/how-to-use-filters/

    Thread Starter Kyle_Irving

    (@kyle_irving)

    Thank you @dpeyou
    We’ve added your snippet to our child theme’s function.php but on the packing slip the country is still displaying as a code.
    Could you advise us on where we are going wrong?

    Thanks

    @dpeyou looking at your snippet it doesn’t appear that you’ve changed the country parameter. From what @kyle_irving is asking I think they want to do something like this:

    CA => CANADA
    GB => United Kingdom
    US => United States

    Right now the snippet looks to just echo the country code but @kyle_irving would like it to echo the full country name.

    Plugin Contributor Darren Peyou

    (@dpeyou)

    @kyle_irving @jamesgiroux ,

    This is how the above code shows the country for me:

    Screenshot-from-2021-05-05-09-55-50

    So if you see “Country: ” but still get the country-code only, then there must be some WooCommerce setting that needs to be changed.

    @kyle_irving could you at least confirm you see “Country: ” part appear in your invoice?

    Thread Starter Kyle_Irving

    (@kyle_irving)

    Hi @dpeyou

    It’s the packing slip and on the packing slip custom template is this code:

    <?php echo !empty($this->order->get_shipping_country()) ? $this->order->get_shipping_country() . '<br>' : ''; ?>

    This is on our custom template that was created using a guide we found on your site a few years ago. However, I’ve reviewed your template and I can see that the way the address is called is different now. We’ve updated our custom template and it seems to be working now. Thank you for your support and patience.

    We will come back if we have more problems.

    Great support + great plugin. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display country not country code on packing slip’ is closed to new replies.