Adding location to custom template
-
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?
-
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); ######################Can you share the error you’re getting that breaks the PDF? (you may need to enable debug output)
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 12Looks 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_locationsis a constant option key, you should replace it with that, and that should fix it.Hi Ewout, thanks for the reply.
Should i replace
$PP_warehouse_locations = get_option(self::metakey_warehouse_locations, array());for?
self::metakey_warehouse_locationsIs 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 13no
self::metakey_warehouse_locationsshould be replaced with the actual option key. The Pickingpal devs should be able to tell you what it is.
The topic ‘Adding location to custom template’ is closed to new replies.