Jan Gale
Jan Gale

Reputation: 11

Add a custom text to items in Woocommerce order received (thank you) page

I have custom bulk discount function where I call two hooks:

Now, I'd like to add discount text "(10% discount)" for each item to my order received page.

Is there any hook which could help me achieve something similar I did with prices before order received page?

Upvotes: 1

Views: 3154

Answers (2)

LoicTheAztec
LoicTheAztec

Reputation: 254362

You can use a custom function hooked in woocommerce_order_item_name filter hook to add your custom text "(10% discount)" to each item title:

add_filter( 'woocommerce_order_item_name', 'custom_orders_items_names', 10, 2 );
function custom_orders_items_names( $item_name, $item ) {
    // Only in thankyou "Order-received" page
    if(is_wc_endpoint_url( 'order-received' ))
        $item_name .= ' ' . __('(10% discount)', 'woocommerce');
    return $item_name;
}

Code goes in any php file of your active child theme (or active theme).

Tested and works.

Upvotes: 2

Avag Sargsyan
Avag Sargsyan

Reputation: 2523

You can make changes in the {your theme}\woocommerce\order\order-details-item.php file. In case if you haven't yet copied to your theme/woocommerce directory, copy it.

You can also take use of hooks woocommerce_order_item_meta_start, woocommerce_order_item_meta_end, which you can find in the mentioned file.

Upvotes: 0

Related Questions