Hi @romandas
By template you mean document type?
Plugin Contributor
kluver
(@kluver)
Hi @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, 8 months ago by
kluver.
-
This reply was modified 4 years, 8 months ago by
kluver.