I'm using woocommerce and installed a print delivery note plugin. What I am trying to do is edit the print file so if someone selects a certain 'additional shipping rate', it will print the relevant printed postage impression - 1st class vs 2nd class
I have in my head an IF statement based on the value of the shipping (FREE vs £1) which I can I do.
BUT, I'm having problems trying to extract the value so I can check it.
Digging deep it looks like I need to use the get_shipping() method in the WC_Order class so I can check the value - http://docs.woothemes.com/wc-apidocs/class-WC_Order.html - and this is where I fail.... miserably.
Looking at this page - http ://docs.woothemes.com/document/class-reference/#listofclassesinwoocommerce - I can copy and paste the WC_Cart example directly into the .php file that is used to print from and echo the value successfully, but when I change it to what I think is correct to use get_shipping(), I get "Fatal error: Call to a member function get_shipping() on a non-object in....." instead.
Here's what I put
<?php global $woocommerce;
$order_shipping_total = $woocommerce->order->get_shipping();
echo $order_shipping_total ;
?>
Now I am guessing, as I have reached the limit of my ability, I need to initialise the WC_Order class but I'm stumped at how to do this.
Any help would be greatly received.
Cheers
You were almost there! You need to initialise the order indeed. $woocommerce
has no idea which order you are talking about. So you create an object from the order:
$order = new WC_Order( $order_id);
Now all information from this order (including your shipping value) is accessible via $order
. The only thing you need to know is the appropriate $order_id
.
Since you are in the print delivery notes environment, you can access that value via
$wcdn->print->order_id
.
this will do what you need:
<?php
global $wcdn;
$order = new WC_Order($wcdn->print->order_id);
$order_shipping_total = $order->get_total_shipping();
echo $order_shipping_total;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With