Untitled

 avatar
unknown
php
3 years ago
1.4 kB
7
Indexable

/**
* Snippet Name:     WooCommerce show the price per unit on the Checkout, Thank You page, Emails, and order view in My Account.
* Snippet Author:   ecommercehints.com
*/

// Show product unit price on the Thank You Page, Emails, and order view in My Account.
function ecommercehints_return_unit_price( $product ) {
   $unit_price = wc_price($product->get_price());
   if (!empty($unit_price )) {
      return '<br><small><strong>(Styckpris: ' . $unit_price . ')</strong></small>';
   } else {
      return '';
   }
}
add_action( 'woocommerce_order_item_meta_start', 'ecommercehints_show_unit_price_below_product_name', 10, 4 );
function ecommercehints_show_unit_price_below_product_name( $item_id, $item, $order, $plain_text ) {
   $product = $item->get_product();
   echo ecommercehints_return_unit_price( $product );
}

// Show Product Unit Price On The Checkout
add_filter( 'woocommerce_cart_item_subtotal', 'ecommercehints_show_unit_price_below_subtotal', 10, 3 );
function ecommercehints_show_unit_price_below_subtotal( $wc, $cart_item, $cart_item_key ) {
 if ( ! is_cart() ) { // The cart already shows unit price so no need to show it again here
 	$product = wc_get_product($cart_item['product_id']);
  $unit_price = wc_price($product->get_price());
  return $wc . '<br><small><strong>(Styckpris: ' . $unit_price . ')<strong></small>';
 } else {
 return $wc;
 }
}
Editor is loading...