Title: Switch between templates automatically?
Last modified: August 19, 2021

---

# Switch between templates automatically?

 *  [romandas](https://wordpress.org/support/users/romandas/)
 * (@romandas)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/switch-between-templates-automatically/)
 * Hi,
 * I want to add in woocommerce checkout page checkbox for customer to select language
   for invoice. I know, how to add checkbox and I know how to create custom invoice
   templates. Is there a hook to put in checkbox for selecting different template?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [alexmigf](https://wordpress.org/support/users/alexmigf/)
 * (@alexmigf)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/switch-between-templates-automatically/#post-14784920)
 * Hi [@romandas](https://wordpress.org/support/users/romandas/)
 * By template you mean document type?
 *  Thread Starter [romandas](https://wordpress.org/support/users/romandas/)
 * (@romandas)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/switch-between-templates-automatically/#post-14784995)
 * Templates, I mean I created these custom templates:
    [Picture of created templates](https://i.imgur.com/Kdc2WS2.png)
   [Checkbox in Checkout page for buyer](https://i.imgur.com/0H5H7Cl.png) I want
   default to be LT, and if customer selects EN template in checkout page, it would
   be generated according to EN template.
 * Any hint how to accomplish that would be very appreciated.
    -  This reply was modified 4 years, 9 months ago by [romandas](https://wordpress.org/support/users/romandas/).
    -  This reply was modified 4 years, 9 months ago by [romandas](https://wordpress.org/support/users/romandas/).
    -  This reply was modified 4 years, 9 months ago by [romandas](https://wordpress.org/support/users/romandas/).
    -  This reply was modified 4 years, 9 months ago by [romandas](https://wordpress.org/support/users/romandas/).
    -  This reply was modified 4 years, 9 months ago by [romandas](https://wordpress.org/support/users/romandas/).
    -  This reply was modified 4 years, 9 months ago by [romandas](https://wordpress.org/support/users/romandas/).
 *  Plugin Contributor [kluver](https://wordpress.org/support/users/kluver/)
 * (@kluver)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/switch-between-templates-automatically/#post-14787634)
 * Hi [@romandas](https://wordpress.org/support/users/romandas/),
 * There is no easy way to switch between two custom templates based on order meta.
   You will have to build your logic into one custom template.
 * If the layout between the LT en EN documents are roughly the same you can collect
   the data of your custom checkbox at the top of your document and use it to hide
   or show certain elements. Or change text based on its value.
 *     ```
       $english = $order->get_meta( 'your_meta_key_here' );
   
       if ( $english ) {
           //EN logic here...
       } else {
           //LT logic here...
       }
       ```
   
 * If the layout of your LT and EN documents is completely different you will have
   to customize a second document. For instance the packing slip. If you are already
   using the packing slip you can purchase our Professional extension. This will
   give you access to the proforma, which you can customize to suit your needs.
 * After you’ve setup your two documents you can use a filter to block one of the
   two from being created and/or sent based on the value of your checkbox.
 *     ```
       add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_send_document_based_on_checkout_language', 10, 2 );
       function wpo_wcpdf_send_document_based_on_checkout_language ( $condition, $document ) {
       	if ( $order = $document->order ) {
   
       		$english = $order->get_meta( 'your_meta_key_here' );
       		$document_type = $document->type;
   
       		switch ( $document_type ) {
       			case 'invoice': // Block LT document when checkbox is checked
       				if ( $english ) $condition = false;
       				break;
       			case 'packing-slip': // Block EN document when checkbox is unchecked
       				if ( !$english ) $condition = false;
       				break;
       		}
       	}
       	return $condition;
       }
       ```
   
 * Code snippets like this should be added to the functions.php of your child theme
   or via a plugin like Code Snippets.
    -  This reply was modified 4 years, 9 months ago by [kluver](https://wordpress.org/support/users/kluver/).
    -  This reply was modified 4 years, 9 months ago by [kluver](https://wordpress.org/support/users/kluver/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Switch between templates automatically?’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices-packing-slips/assets/icon-256x256.
   png?rev=2189942)
 * [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/)

## Tags

 * [hook](https://wordpress.org/support/topic-tag/hook/)
 * [pdf](https://wordpress.org/support/topic-tag/pdf/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 3 replies
 * 3 participants
 * Last reply from: [kluver](https://wordpress.org/support/users/kluver/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/switch-between-templates-automatically/#post-14787634)
 * Status: not resolved