wc_gzd_cart_product_unit_price

Appends unit price to product price live data (while checkout) or order meta to product price.

Description

(string) wc_gzd_cart_product_unit_price( (string) $price, (array) $cart_item, (string) $cart_item_key = '' ); 

Returns (string)

Parameters (3)

0. $price (string)
The price.
1. $cart_item (array)
The cart item.
2. $cart_item_key — Optional. (string) => ''
The cart item key.

Usage

  1. if ( !function_exists( 'wc_gzd_cart_product_unit_price' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-germanized/includes/wc-gzd-cart-functions.php'; 
  3.  
  4. // The price. 
  5. $price = ''; 
  6.  
  7. // The cart item. 
  8. $cart_item = array(); 
  9.  
  10. // The cart item key. 
  11. $cart_item_key = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wc_gzd_cart_product_unit_price($price, $cart_item, $cart_item_key); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-gzd-cart-functions.php  
  1. function wc_gzd_cart_product_unit_price( $price, $cart_item, $cart_item_key = '' ) { 
  2.  
  3. $unit_price = ""; 
  4.  
  5. if ( isset( $cart_item[ 'data' ] ) ) { 
  6.  
  7. $product = apply_filters( 'woocommerce_cart_item_product', $cart_item[ 'data' ], $cart_item, $cart_item_key ); 
  8.  
  9. if ( wc_gzd_get_gzd_product( $product )->has_unit() ) 
  10. $unit_price = wc_gzd_get_gzd_product( $product )->get_unit_html( false ); 
  11.  
  12. } else if ( isset( $cart_item[ 'unit_price' ] ) ) { 
  13.  
  14. $unit_price = $cart_item[ 'unit_price' ]; 
  15.  
  16.  
  17. } else if ( isset( $cart_item[ 'product_id' ] ) ) { 
  18.  
  19. $product = wc_get_product( ! empty( $cart_item[ 'variation_id' ] ) ? $cart_item[ 'variation_id' ] : $cart_item[ 'product_id' ] ); 
  20.  
  21. if ( $product && wc_gzd_get_gzd_product( $product )->has_unit() ) 
  22. $unit_price = wc_gzd_get_gzd_product( $product )->get_unit_html( false ); 
  23.  
  24.  
  25. if ( ! empty( $unit_price ) ) 
  26. $price .= ' <span class="unit-price unit-price-cart">' . $unit_price . '</span>'; 
  27.  
  28. return $price;