• Resolved Sarun developer

    (@saruncloudspring)


    Hi,

    If customer purchase order based on particular shipping method then i want to high light that particular shipping method name in invoice. For example customer selected shipping1 method then i only want to highlight that text in PDF invoice. Dont want to high light other shipping method name. I know plugin is using this
    function wpo_wcpdf_after_order_details for display order details. But where i can check shipping condition ? Please help

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m trying to do excatly the same but only for packing slips. When customers choose pickup, then highlight shipping method.

    I managed to do it with javascript.. But i can’t make it execute the javascript when the pdf i opened..

    It works perfectly in an html document, but just not when the PDF is opened. See working codePen here: https://codepen.io/Molin449/pen/GRKrppR

    Hope someone can help!

    Plugin Contributor kluver

    (@kluver)

    Hi @molin449 and @saruncloudspring,

    You can target this part of the Simple template with some custom CSS via the following code snippet:

    add_action( 'wpo_wcpdf_before_document', 'wpo_wcpdf_highlight_shipping_method', 10, 2 );
    function wpo_wcpdf_highlight_shipping_method ( $template_type, $order ) {
    	$highlighted_methods = array( 'Flat Rate', 'Free Shipping' );
    	if ( in_array($order->get_shipping_method(), $highlighted_methods ) ) {
    		?>
    		<style type="text/css">
    			.shipped_via { background:yellow; }
    		</style>
    		<?php
    	}
    }

    You can add shipping methods you want to highlight in the $hightlighted_methods array. If you want to only apply this on the packing slip you can extend the snippet like this:

    add_action( 'wpo_wcpdf_before_document', 'wpo_wcpdf_highlight_shipping_method', 10, 2 );
    function wpo_wcpdf_highlight_shipping_method ( $template_type, $order ) {
    	$highlighted_methods = array( 'Flat Rate', 'Free Shipping' );
    	if ( in_array($order->get_shipping_method(), $highlighted_methods ) && $template_type == 'packing-slip' ) {
    		?>
    		<style type="text/css">
    			.shipped_via { background:yellow; }
    		</style>
    		<?php
    	}
    }

    This snippet should be placed in the functions.php of your child theme. If you haven’t worked with code snippets or functions.php before please read this: How to use filters

    Awesome! It worked!

    But i had to change the CSS selector to “.shipping-method td” for it to work. But that was a minor change. Thank you so much for this answer !

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I want to highlight the shipping method name in invoice’ is closed to new replies.