Support » Plugin: WooCommerce PDF Invoices & Packing Slips » Local pickup vs Invoice and Packing slips

  • Resolved gore.m

    (@gorem)


    Hello,
    I have one issue with Local pickup vs Invoice and Packing slips:
    If customer chose an delivery option + fills in shipping form and than change his mind and chose local pickup instead, Woocommerce keeps filled in shipping form and than shipping address is on invoice and packing slips too.
    I’ve tried manipulate shipping form via jQuery, but than I have problems with packing slips names etc…
    So, Is there way (if local pickup has been chosen):
    – to disable some of checkout fields on invoice (via filter/action, without tweaking template)?
    – replace some of fields on packing slips by billing fields, for example set shipping name same as billing name?
    – replace shipping title on invoice?

    Or is there better solution?

    Thanks you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Ewout

    (@pomegranate)

    Hi! What you describe sounds more of a Local Pickup/WooCommerce issue than an issue with the PDF Invoices & Packing Slips plugin.

    You can use any of the regular filters and actions in the PDF and query the order data to see if the shipping method is local pickup:

    
    $shipping_method = $order->get_shipping_method();
    

    You can change the shipping title on the invoice with wpo_wcpdf_shipping_method, here’s an example (you’ll need to change the shipping method title to the one used by Local pickup for this to work):

    
    add_filter('wpo_wcpdf_shipping_method','wpo_wcpdf_shipping_method_pickup',10, 2);
    function wpo_wcpdf_shipping_method_pickup( $shipping_method, $document ) {
    	if ( $shipping_method == "Pickup" ) {
    		$shipping_method = "NEW TITLE";
    	}
    	return $shipping_method;
    }
    

    Hope that helps!
    Ewout

    gore.m

    (@gorem)

    Hi Ewout,
    Thanks you for your reply!

    You are right that my question is more Woocoommerce / Local Pickup issue, so I decided to go back to my jQuery solution and work on it.
    There was an misunderstanding by “shipping title”, I was talking about this template lines: <h3><?php _e( 'Ship To:', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
    and this <?php _e( 'Shipping Address:', 'woocommerce-pdf-invoices-packing-slips' ); ?>
    because if local pickup has been chosen ‘Ship To:’ and ‘Shipping Address:’ is not right, more logical would be “Recipient”. Is it possible to change it dynamically?

    Thanks you

    Plugin Author Ewout

    (@pomegranate)

    Is it possible to change it dynamically?

    Technically, yes, you could use the gettext filter. But you’re entering hacky territory here 🙂

    Without warranty:

    
    add_action('wpo_wcpdf_before_html','wpo_wcpdf_dynamic_shipping_address_title',10,2);
    function wpo_wcpdf_dynamic_shipping_address_title( $document_type, $document ) {
    	if (!empty($document->order)) {
    		$shipping_method = $document->order->get_shipping_method();
    		if ( $shipping_method == "Pickup" ) {
    			add_filter('gettext', function( $translation, $text, $domain ) {
    			    if ( $domain == 'woocommerce-pdf-invoices-packing-slips' && ( $text == 'Ship To:' || $text == 'Shipping Address:' ) ) {
    			        $translation = $translation = 'Recipient:';
    			    }
    			    return $translation;
    			}, 10, 3 );
    		}
    	}
    }
    

    (as with the previous filter, change Pickup for the shipping method you want to address)

    gore.m

    (@gorem)

    You are awesome, it works! .-)
    What did you mean by “hacky territory” :-)))? Do you think, that would be “safer” to edit template?

    Plugin Author Ewout

    (@pomegranate)

    Very glad to hear that works for you 🙂

    What I meant is that overriding translations programmatically is not very transparent and this method is not quite transparent even though it does exactly what you need right now.
    It’s not necessarily unsafe but it’s certainly more ‘readable’ (for others or for yourself in say a year from now) to do this in the template. The choice is up to you.

    gore.m

    (@gorem)

    Thanks you very much @pomegranate, I very appreciate your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Local pickup vs Invoice and Packing slips’ is closed to new replies.