Coupon Code
-
How can I make it so that if a coupon is used it shows up on either the packing slip or invoice?
Thanks!
-
Hi @creoadmin,
You can add used coupons with a small code snippet:
//Add used coupons to PDFs add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_coupons_used', 10, 2 ); function wpo_wcpdf_coupons_used ($template_type, $order) { if( $used_coupons = $order->get_used_coupons() ) { $coupons_list = implode(', ', $used_coupons); echo '<h4>' . __('Coupons used') . '</h4>'; echo '<p>' . $coupons_list . '</p>'; } }
This code snippet should be placed in the functions.php of your child theme. If you haven’t worked with code snippets or functions.php please read this: How to use filters
This is amazing and works PERFECTLY!!!
One more request, is there a way to include the order notes on the packing slips/invoices?
THANK YOU for your amazing support!
Hi @creoadmin,
Sure, please read the following guide: Displaying the order notes
Thanks for the compliment and if you haven’t already, we would really appreciate a good review. ??
I am so sorry to be reopening this thread, but I can no longer see what coupon codes have been used on my packing slips.
Also, you gave me a custom code to list user roles on my packing slips and that has stopped working too. Here is what you said for that:
add_action( ‘wpo_wcpdf_after_order_data’, ‘wpo_wcpdf_print_user_role’, 10, 2 );
function wpo_wcpdf_print_user_role ($template_type, $order) {
if ($template_type == ‘packing-slip’) {
$user = $order->get_user();
if ( $user && in_array( ‘gold_level_membership’, (array) $user->roles ) ) {
?>
<tr class=”user-role”>
<th>User role:</th>
<td>Gold Level</td>
</tr>
<?php
} else {
?>
<tr class=”user-role”>
<th>User role:</th>
<td>Customer</td>
</tr>
<?php
}
}
}Any ideas as to what happened that caused these to stop working? THANK YOU for all of your help!!
None of these filters have changed, so unless you made changes to the template files, they should still work.
Where did you put those code snippets exactly? Can you verify that they are still enabled/executed?HI, is there a way I could modify the code snippet to show which affiliate an order was placed through on the invoice?THank you!
Is this data stored in the order? If so you could retrieve it following this guide: Displaying a custom field
I did verify that they are still executed. They are running in the Code Snippets plugin. ??
Hi @creoadmin,
Have you made recent changes to your packing slip template? If the action hooks are still there and your filters are executed there should be no reason why they wouldn’t work.
@kluver
There is a column on woocommerce orders which shows the referral number, if the order was referred by an affiliate.If you click on the referral number, the affiliate’s id is stored with all other order data in the custom field box. This is how it identifies the affiliate
:”affiliate_id”;i:11;
I did add the store toolkit plugin, and I don’t see any meta data identifying the affiliate with the order. It appears that the only place that I can see affiliate id or username is through the AffiliateWP plugin.
Any advice is greatly appreciated.
Thank you,
JodieThe referral id is also available under order notes.
@kluver I am so confused why they stopped working! I haven’t made any recent changes to my packing slips template. They stopped working when I installed a new theme. That could be the problem?
@creoadmin if you switch back to the old theme, do the snippets start working again?
Checking if the code is still in Code Snippets is not a sure way to determine it is being executed, a better way would be a snippet without any conditions, if this doesn’t show ‘TEST’ anywhere on the invoice or packing slip it’s not executed:add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_test_filter', 10, 2 ); function wpo_wcpdf_test_filter ($template_type, $order) { echo "TEST"; }
You may also want to double check that the snippet in Code Snippets is set to “Run snippet everywhere”.
@jodiekieliszewski, I recommend contacting the WP Affiliate support to get help with this. Here’s a base code snippet that with the right information they should be able to help you further with:
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_delivery_date', 10, 2 ); function wpo_wcpdf_delivery_date ( $template_type, $order ) { // example order meta $meta_key = '_meta_key'; $order_meta = $order->get_meta($meta_key); ?> <tr class="order-meta"> <th>Order Meta:</th> <td><?php echo $order_meta; ?></td> </tr> <?php // example user meta, check if we have a user ID first if ( $user_id = $order->get_user_id() ): $meta_key = 'user_meta_key'; $user_meta = get_user_meta( $user_id, $meta_key, true ); ?> <tr class="user-meta"> <th>User Meta:</th> <td><?php echo $user_meta; ?></td> </tr> <?php endif; }
If you need more help with this, please open a new thread on this support forum, otherwise this original thread becomes too confusing with two different, unrelated topics!
We are definitely narrowing the problem! I added a new snippet with that test code and TEST appeared nowhere on the packing slip. But, I have verified that the snippets are activated everywhere.
https://leggingavenue.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-28-at-9.43.55-PM.png
Are you sure you are using this very plugin, “WooCommerce PDF Invoices & Packing Slips” and not another plugin? Are you using the Simple template (check under WooCommerce > PDF Invoices > General > Select a template)?
- The topic ‘Coupon Code’ is closed to new replies.