So I have created a custom action button in my woocommerce order list, but I want the button to link to a page where I will print out information attached to that order. Now to do so I would like to carry data from the order to the page where I am going to print the information.
So I have created my custom button in the woocommerce order list with this code:
add_action( 'woocommerce_admin_order_actions_end', 'add_content_to_wcactions_column' );
function add_content_to_wcactions_column() {
// create some tooltip text to show on hover
$tooltip = __('Print details', 'textdomain');
// create a button label
$label = __('P1', 'textdomain');
$printurl = wc_get_order_item_meta($post_id, 'street-name', true);
echo '<a class="button tips custom-class" href="/order-info/?orderid='.$printurl.'" data-tip="'.$tooltip.'" target="_blank">'.$label.'</a>';
}
The button links to the print page which should carry the orders ‘street-name’ meta, but the meta doesnt show, it just appears blank in the url.
Heres what my order item information looks like:
I should say im using the WooCommerce Custom Product Addons plugin if that helps.
2
Answers
There are some mistakes and missing things in your code, like:
$order
argument is missing from the hooked function$post_id
is not defined.wc_get_order_item_meta()
functionReminder: An order can have many items (products).
In the following code we will get the first order Item (assuming that
street-name
is the correctmeta_key
to get the custom order item meta data value):Code goes in functions.php file of your active child theme (or active theme). It should work.
I am not sure if you meant that street-name is the meta key for the order or the item, so I covered both cases in the following code, you can delete what’s not relevant for you.
Here is an example of page template that will get order ID in the querystring, and will display some information.
To make this happen, you need to create a php file in your theme directory, you can call it “template-order-info.php” and paste this content into it.
Then, go to your admin and create a new page and assign the page template from the select box to be “Order Info” (the new file).
Then view the file, and add the following query string: /?order=#### (replace with the order ID). so for example: http://www.mysite.com/orderinfo/?order=1001