• Resolved svg2018

    (@svg2018)


    Hi,

    I am using pickingpal for orderpicking but the picking list that gets generated looks awful, i would like to add the warehouse location from this extension to the woocommerce pdf packing slip.

    I am not great with PHP but i tried and i could not get it to work. Any suggestions?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    For anyone else with the same issue, @vg2018 shared this code with us via email, which was given to him by the pickingpal developers:

    
    ###################
    //1. get all printable locations
    add_action("wpo_wcpdf_before_order_details", function($type, $order) {
    	global $PP_warehouse_locations;
    	$PP_warehouse_locations = get_option(self::metakey_warehouse_locations, array());
    	$PP_warehouse_locations = array_filter($PP_warehouse_locations, function($e) {
    		return $e['enabled'] == 'on' && $e['pick_ticket'] == 'on';
    	});
    }, 10, 2);
    
    //2. print it
    add_action("wpo_wcpdf_after_item_meta", function($type, $item, $order) {
    	global $PP_warehouse_locations;
    	if (count($PP_warehouse_locations)) {
    		$_product = $order->get_product_from_item($item['item']);
    		$warehouse_locations_str = '';
    		$id = $_product->get_id();
    		$value = array();
    		foreach($PP_warehouse_locations as $key => $location):
    			$_value = get_post_meta($id, $key, true);
    			if (isset($_value) && !empty($_value)) {
    				$value[] = $location['label']. ': '.$_value;
    			}
    		endforeach;
    		$warehouse_locations_str = implode('<br>', $value);
    		echo "<dl class=\"meta\">$warehouse_locations_str</dl>";
    	}
    }, 10, 3);
    ######################
    
    Thread Starter svg2018

    (@svg2018)

    Unfortunately i can’t get it working by just copy & pasting it in the template-functions.php file. It breaks the .pdf

    • This reply was modified 7 years, 9 months ago by svg2018.
    • This reply was modified 7 years, 9 months ago by svg2018.
    Plugin Contributor Ewout

    (@pomegranate)

    Can you share the error you’re getting that breaks the PDF? (you may need to enable debug output)

    Thread Starter svg2018

    (@svg2018)

    The debug output looks like this:

    Fatal error: Uncaught Error: Undefined class constant 'metakey_warehouse_locations' in /home/staxvi1q/test.mydomain.nl/wp-content/themes/storefront/woocommerce/pdf/yourtemplate/template-functions.php:12 Stack trace: #0 /home/staxvi1q/test.mydomain.nl/wp-includes/class-wp-hook.php(286): WPO\WC\PDF_Invoices\Main->{closure}('invoice', Object(WC_Order)) #1 /home/staxvi1q/test.mydomain.nl/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/staxvi1q/test.mydomain.nl/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/staxvi1q/test.mydomain.nl/wp-content/themes/storefront/woocommerce/pdf/yourtemplate/invoice.php(82): do_action('wpo_wcpdf_befor...', 'invoice', Object(WC_Order)) #4 /home/staxvi1q/test.mydomain.nl/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abstract-wcpdf-order-document.php(618): include('/home/staxvi1q/...') #5 /home/staxvi1q/test.mydomain.nl/wp-content/plugins/woocommerce-pdf-invoices-packing-slips/includes/documents/abst in /home/staxvi1q/test.mydomain.nl/wp-content/themes/storefront/woocommerce/pdf/yourtemplate/template-functions.php on line 12

    Plugin Contributor Ewout

    (@pomegranate)

    Looks like the dev copied some of his own code that refers to the plugin class:

    
    $PP_warehouse_locations = get_option(self::metakey_warehouse_locations, array());
    

    if self::metakey_warehouse_locations is a constant option key, you should replace it with that, and that should fix it.

    Thread Starter svg2018

    (@svg2018)

    Hi Ewout, thanks for the reply.

    Should i replace

    $PP_warehouse_locations = get_option(self::metakey_warehouse_locations, array());
    

    for?
    self::metakey_warehouse_locations

    Is that what you are trying to say? Doing so gives the following error
    Parse error: syntax error, unexpected '$PP_warehouse_locations' (T_VARIABLE) in /home/username/test.mydomain.nl/wp-content/themes/storefront/woocommerce/pdf/yourtemplate/template-functions.php on line 13

    Plugin Contributor Ewout

    (@pomegranate)

    no self::metakey_warehouse_locations should be replaced with the actual option key. The Pickingpal devs should be able to tell you what it is.

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

The topic ‘Adding location to custom template’ is closed to new replies.