So I added to my Woocommerce Template Files to my Wordpress custom theme woocommerce folder, I can edit files, but when I try use div, it automatically removes them and sometimes all content inside it. Can't find any solutions, any way to walk around it?
There is my my-order.php inside mytheme/woocommerce folder, I edited few classes to change to bootstrap look, but when I wanted to wrap any line of code with div with class, but doesn't show up in page.
<?php
/**
* My Orders - Deprecated
*
* #deprecated 2.6.0 this template file is no longer used. My Account shortcode uses orders.php.
* #package WooCommerce\Templates
*/
defined( 'ABSPATH' ) || exit;
$my_orders_columns = apply_filters(
'woocommerce_my_account_my_orders_columns',
array(
'order-number' => esc_html__( 'Order', 'woocommerce' ),
'order-date' => esc_html__( 'Date', 'woocommerce' ),
'order-status' => esc_html__( 'Status', 'woocommerce' ),
'order-total' => esc_html__( 'Total', 'woocommerce' ),
'order-actions' => ' ',
)
);
$customer_orders = get_posts(
apply_filters(
'woocommerce_my_account_my_orders_query',
array(
'numberposts' => $order_count,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => array_keys( wc_get_order_statuses() ),
)
)
);
if ( $customer_orders ) : ?>
<h2><?php echo apply_filters( 'woocommerce_my_account_my_orders_title', esc_html__( 'Recent orders', 'woocommerce' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h2>
<div class="common-table table-1 desk">
<table class="table">
<thead>
<tr>
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
foreach ( $customer_orders as $customer_order ) :
$order = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count();
$a=0;
?>
<tr class="order">
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<td class="<?php if ($a == 0 ) {echo $x="text-start"; $a++;} ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php
/* translators: 1: formatted order total 2: total order items */
printf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = wc_get_account_orders_actions( $order );
if ( ! empty( $actions ) ) {
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
Changed editing from my-orders.php to orders.php and now it's working. They are same files, but orders.php for newest versions of woocommerce.
Related
I need to show users order list with my own html and css, like the number and the thumbnail in the left part of the item, and in the right part it has to be an order date, an order status, the quantity and the price, and my own meta.
I've founded how to add an image with the hook, it's not a problem. The problem is - that I can't customize the native structure of woocommerce/myaccount/orders.php. Even when I change table, tr,td,tbody to div-s, my wrappers don't help. It's a loop. And all that I add is adding for all items
foreach ( $customer_orders->orders as $customer_order ) {
$order = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count() - $order->get_item_count_refunded();
?>
<div class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_atdiv( $order->get_status() ); ?> order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<div class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_atdiv( $column_id ); ?>" data-title="<?php echo esc_atdiv( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ); ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo esc_atdiv( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php
/* divanslators: 1: formatted order total 2: total order items */
echo wp_kses_post( sprintf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ) );
?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = wc_get_account_orders_actions( $order );
if ( ! empty( $actions ) ) {
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</div>
<?php endforeach;
I need to separate the order-number and the added thumbnail to one wrapper, and all other metas to another.
I need something like global $product; product-> get_price(); but with the order.
Maybe there is some hooks of functions to display all order parts separately, and make a new loop?
As per our understanding, you want to create your own template page and show current user orders.
If I am right you should try like this:
<?php
/*
* Template Name: Order Page Template
*/
defined( 'ABSPATH' ) || exit;
global $woocommerce, $user_id;
if (!class_exists('WooCommerce') || !get_current_user_id()) {
return;
};
$user_id = get_current_user_id();
//$customer = wp_get_current_user();
$posts_per_page = 20;
// Get all customer orders
$customer__all_orders = get_posts(apply_filters('woocommerce_my_account_my_orders_query', array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'orderby' => 'date',
'order' => 'DESC',
'meta_value' => $user_id ,
'post_type' => wc_get_order_types(),
'post_status' => array_keys(wc_get_order_statuses()), 'post_status' => array('wc-processing'),
)));
$paged = isset($_REQUEST['order_page']) ? $_REQUEST['order_page'] : 1;
$total_records = count($customer__all_orders);
$total_pages = ceil($total_records / $posts_per_page);
$customer_orders = get_posts(array(
'meta_key' => '_customer_user',
'order' => 'DESC',
'meta_value' => $user_id ,
'post_type' => wc_get_order_types(),
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'post_status' => array_keys(wc_get_order_statuses()), 'post_status' => array('wc-processing'),
));
?>
<?php if (!empty($customer_orders)) : ?>
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order );
$item_count = $order->get_item_count() - $order->get_item_count_refunded();
?>
<tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?> order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ); ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php
/* translators: 1: formatted order total 2: total order items */
echo wp_kses_post( sprintf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ) );
?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = wc_get_account_orders_actions( $order );
if ( ! empty( $actions ) ) {
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php
}
?>
</tbody>
</table>
<div class="pagination">
<?php
$args = array(
'base' => '%_%',
'format' => '?order_page=%#%',
'total' => $total_pages,
'current' => $paged,
'show_all' => False,
'end_size' => 5,
'mid_size' => 5,
'prev_next' => True,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => False,
'add_fragment' => ''
);
echo paginate_links($args);
?>
</div>
<?php else : ?>
<div class="woocommerce-message woocommerce-message--info woocommerce-Message woocommerce-Message--info woocommerce-info">
<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>"><?php esc_html_e( 'Browse products', 'woocommerce' ); ?></a>
<?php esc_html_e( 'No order has been made yet.', 'woocommerce' ); ?>
</div>
<?php endif; ?>
Steps:
Create new page inside your active theme - template-order.php
Copy past above code inside your template-order.php apge and save.
Goto wordpress admin dashboard pages menu and click on new page
After create new page assign templete "Order Page Templete" and save
Now open your new page and you will get or order related to current logged in user
Note: You can also modify above code accordingly
This question already has an answer here:
Show product categories in a new column on WooCommerce "My account" orders table
(1 answer)
Closed 1 year ago.
There are orders that have already been completed or not, and they contain goods, clothing, courses, etc. In WordPress, I have all the products subdivided into categories, but I don't know how to display the names of these categories. Suppose I have an order from a T-shirt and some course, and in the category I have to display "Clothes, Courses" (In the picture below, it is marked in red where it is necessary to display). I was able to display only the "Categories" tab, but the categories themselves cannot be displayed at all :( Here is the code from the orders.php file
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
foreach ( $customer_orders->orders as $customer_order ) {
$order = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count() - $order->get_item_count_refunded();
?>
<tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-<?php echo esc_attr( $order->get_status() ); ?> order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ); ?>
</a>
<?php elseif ( 'order-cat' === $column_id ) : ?>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php
/* translators: 1: formatted order total 2: total order items */
echo wp_kses_post( sprintf( _n( '%1$s for %2$s item', '%1$s for %2$s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ) );
?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = wc_get_account_orders_actions( $order );
if ( ! empty( $actions ) ) {
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php
}
?>
</tbody>
</table>
And here is the picture:
enter image description here
$items = $order->get_items();
$cats = '';
foreach($items as $key => $item) {
$product_id = $item['product_id'];
$term_obj_list = get_the_terms($product_id, 'product_cat');
$terms_string = implode(', ', wp_list_pluck($term_obj_list, 'name'));
$cats .= $terms_string;
}
echo $cats;
Put this in correct elseif block of your given code.
Updated according to the comment with code comment:
//Getting all the items in the order
$items = $order->get_items();
$c_list = [];
/**
* Loop through all items and get their categories [a product can have multiple category]
*/
foreach($items as $key => $item) {
//We need the product id to retrieved the categories
$product_id = $item['product_id'];
//Retrieving all the categories that product has
$term_obj_list = get_the_terms($product_id, 'product_cat');
//Loop through all the categories the current product has and saving it in a array with category id as index
//so that if the save category is assigned to another product we do not get the duplicate category
foreach($term_obj_list as $term_obj) {
$c_list[$term_obj->term_id] = $term_obj->name;
}
}
//lastly we concatenating all the categories with ", "
$cats = implode(', ', $c_list);
//printing the final result
echo $cats;
Shortcode Display WooCommerce Product Variations Dropdown
How to display the Product Variations in WooC Commerce with Shortcode???
This is my code:
add_shortcode( 'test_shortcode', 'woo_display_variation_dropdown' );
function woo_display_variation_dropdown() {
global $product;
if( $product->is_type( 'variable' )) {
$attribute_keys = array_keys( $product->get_attributes() );
?>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( json_encode( $product->get_available_variations() ) ) ?>">
<?php do_action( 'woocommerce_before_variations_form' ); ?>
<?php if ( empty( $product->get_available_variations() ) && false !== $product->get_available_variations() ) : ?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php else : ?>
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $product->get_attributes() as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php endif; ?>
</form>
<?php }
}
It does not work as I would like. What I am doing wrong?
Any help is appreciated.
I am trying to display all the order on the admin order history page (including order customers's order). So that the admin can view the orders on the front end.
And I am trying to modify the template - my-order.php to show the orders on this page. However, I displayed a list of all orders, but when I clicked into the order, it said that Invalid order(Which is not admin own order).
/**my-order.php**/
$customer_orders = get_posts( apply_filters( 'wo<?php foreach ( $customer_orders as $k => $v) :
$order = wc_get_order( $customer_orders[ $k ]->ID );
$item_count = $order->get_item_count();
?>
<tr class="order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a>
How do I display all the orders the order history?
Thanks for helping.
Basicly, I would like to display the coupon used on Woocommerce thankyou.php. Here is the code I have added
$coupons = $order->get_items( 'coupon' );
foreach ( $coupons as $item_id => $item ) {
echo "<span class='coupon-name'><b>".$item['name']."</b></span>";
$post = get_post( $item_id );
echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
}
However, only the coupon code is shown while the description does not.
Here is where I placed my code:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( $order ) : ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p class="woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
<p class="woocommerce-thankyou-order-failed-actions">
<?php _e( 'Pay', 'woocommerce' ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php _e( 'My Account', 'woocommerce' ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<?php
$coupons = $order->get_items( 'coupon' );
foreach ( $coupons as $item_id => $item ) {
echo "<span class='coupon-name'><b>".$item['name']."</b></span>";
$post = get_post( $item_id );
echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
}
?>
<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<ul class="woocommerce-thankyou-order-details order_details">
<li class="order">
<?php _e( 'Order Number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
<div class="clear"></div>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
Could anyone please help me with this?
add_filter('woocommerce_get_order_item_totals','change_discount',10,3);
function change_discount($total_rows, $order, $tax_display){
if ( $order->get_total_discount() > 0 ) {
$coupons = $order->get_used_coupons();
$total_rows['discount'] = array( 'label' => __( 'Coupon code: '.implode(",",$coupons), 'woocommerce' ), 'value' => '-' . $order->get_discount_to_display( $tax_display ), );
}
return $total_rows;
}
you can get like this
if( $order->get_used_coupons() ) {
$coupons_count = count( $order->get_used_coupons() );
echo '<h4>' . __('Coupons used') . ' (' . $coupons_count . ')</h4>';
echo '<p><strong>' . __('Coupons used') . ':</strong> ';
$i = 1;
$coupons_list = '';
foreach( $order->get_used_coupons() as $coupon) {
$coupons_list .= $coupon;
if( $i < $coupons_count )
$coupons_list .= ', ';
$i++;
}
echo '<p><strong>Coupons used (' . $coupons_count . ') :</strong> ' . $coupons_list . '</p>'; }
Please use this code, I hope it will work for you:
<?php
add_action('woocommerce_thankyou', 'apply_product_on_coupon');
function apply_product_on_coupon() {
global $woocommerce;
if ( ! empty( $woocommerce->cart->applied_coupons ) ) {
$my_coupon = $woocommerce->cart->get_coupons() ;
foreach($my_coupon as $coupon){
if ( $post = get_post( $coupon->id ) ) {
if ( !empty( $post->post_excerpt ) ) {
echo "<span class='coupon-name'><b>".$coupon->code."</b></span>";
echo "<p class='coupon-description'>".$post->post_excerpt."</p>";
}
}
}
}
}
?>
If this will not work then use coupon shortcode plugin and call shortcode on the thankyou page
https://wordpress.org/plugins/woocommerce-coupon-shortcodes/
<?php echo do_shortcode('[coupon_shortcode]'); ?>