• 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

    (@alexmigf)

    Hi @romandas

    By template you mean document type?

    Thread Starter romandas

    (@romandas)

    Templates, I mean I created these custom templates:
    Picture of created templates
    Checkbox in Checkout page for buyer
    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, 8 months ago by romandas.
    • This reply was modified 4 years, 8 months ago by romandas.
    • This reply was modified 4 years, 8 months ago by romandas.
    • This reply was modified 4 years, 8 months ago by romandas.
    • This reply was modified 4 years, 8 months ago by romandas.
    • This reply was modified 4 years, 8 months ago by romandas.
    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.
Viewing 3 replies - 1 through 3 (of 3 total)

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