Woocommerce Short_Description in Details Order - php

I'm creating my new website with Wordpress and Woocommerce. I would like to display the short description in the order detail.
I found this code :
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_excerpt', 5);
But that shows me the description in home.
Is there a way to make it appear in the order detail?

It can be done with a custom unction hooked in woocommerce_order_item_name filter hook, this way:
add_filter( 'woocommerce_order_item_name', 'add_single_excerpt_to_order_item', 10, 3 );
function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
$product_id = $item->get_product_id(); // Get the product Id
$excerpt = get_the_excerpt( $product_id ); // Get the short description
return $item_name . '<br><p class="item-description">' . $excerpt ; '</p>';
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works. It will display the short description in Order items below the item name.

Related

Woocommerce - Display the product category under product title in shop/archive page

I want to add the product's category between the title and the price of each product. As long as I edited the archive-product.php file with codes i found here, nothing seemed to work. I created a copy of the file on the active theme too.
we can use 'woocommerce_after_shop_loop_item_title' action for this case
function product_category_in_shop_loop() {
global $product;
$product_id = $product->get_id();
$cat = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'names'));
if( !empty($cat[0]) ){
echo '<p class="catil">'.$cat[0].'</p>';
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'product_category_in_shop_loop', 40 );
code goes to child theme function.php.

Replace the product name by the Sku in the order received page

Using Woocommerce, I would like to add the SKU instead of the product name in the thank you page and order pages like in Order received (thankyou) and Order pay pages.
I use the woocommerce_cart_item_name filter hook like in this previous thread, but it works only My account > View order pages.
I have also tried to use woocommerce_add_order_item_meta filter hook, but it doesn't work.
Can I know the correct complete code to add to function.php to be able to replace the product name by the SKU in Order received (thankyou) and Order pay pages.
To replace the product name by the SKU on Order received, Order pay (and my account Order view) pages, you need to use the following:
add_filter( 'woocommerce_order_item_name', 'display_sku_in_order_item', 20, 3 );
function display_sku_in_order_item( $item_name, $item, $is_visible ) {
if( is_wc_endpoint_url() ) {
$product = $item->get_product();
if( $sku = $product->get_sku() )
$item_name = '' . __( "Product ", "woocommerce") . $sku . '';
}
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.
Related: Woocommerce conditional tags reference

Add the product thumbnail on Woocommerce Thankyou page

In woocommerce, on Order received page (Thankyou page) the product image is not displayed in the order items.
How can I display the product image in order items on Order received page?
Is there a usable hook for that?
Or do I have to override the template order/order-details-item.php file?
Any help is appreciated.
To display the thumbnail image in the order items on Order received page (thankyou), you will use:
// Display the product thumbnail in order received page
add_filter( 'woocommerce_order_item_name', 'order_received_item_thumbnail_image', 10, 3 );
function order_received_item_thumbnail_image( $item_name, $item, $is_visible ) {
// Targeting order received page only
if( ! is_wc_endpoint_url('order-received') ) return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $product->get_image_id() > 0 ){
$product_image = '<span style="float:left;display:block;width:56px;">' . $product->get_image(array(48, 48)) . '</span>';
$item_name = $product_image . $item_name;
}
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Change Woocommerce product quantity in checkout table

I would like to change the way Woocommerce is displaying the product quantity in the order review table. I would like the quantity to be underneath the product name instead of after it.
I found this post which helped, but the code only changes the quantity layout for variable products.
How can I change it for EVERY product, even simple ones?
This can be done in multiple ways:
1) Overriding template checkout/review-order.php via your child theme.
2) Customizing the product item name:
add_filter( 'woocommerce_cart_item_name', 'customizing_checkout_item_name', 10, 3);
function customizing_checkout_item_name( $item_name, $cart_item, $cart_item_key ) {
if( is_checkout() )
$item_name .= '<br>';
return $item_name;
}
Code goes in function.php file of the active child theme (or active theme).
3) Customizing the product item quantity (the best way):
add_filter( 'woocommerce_checkout_cart_item_quantity', 'customizing_checkout_item_quantity', 10, 3);
function customizing_checkout_item_quantity( $quantity_html, $cart_item, $cart_item_key ) {
$quantity_html = ' <br>
<span class="product-quantity">' . __('Quantity:') . ' <strong>' . $cart_item['quantity'] . '</strong></span>';
return $quantity_html;
}
Code goes in function.php file of the active child theme (or active theme).
All code is tested and works.

Add custom content Next add-to-cart In button for a specific Product

I am trying to add content next to add to cart button in woocommerce for specific product, I have used the bellow woocommerce hook, But unfortunately it didn't work:
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart_button_func' );
function add_content_after_addtocart_button_func() {
$current_product = $product->id;
if($current_product === '13333') {
echo '<div class="second_content">Place your content here!</div>';
}
}
Any one can help me on this?
Thanks
Update: Added compatibility with WC +3
This custom function hooked in woocommerce_single_product_summary action hook, will display a custom content after add-to-cart button for a specific product ID in the single product page:
add_action( 'woocommerce_single_product_summary', 'add_content_after_addtocart_button_func', 35 );
function add_content_after_addtocart_button_func() {
global $product;
// Added compatibility with WC +3
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if($product_id == 13333)
echo '<div class="custom-content">'.__('Place your content here!','woocommerce').'</div>';
}
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.

Categories