woocommerce_umf_get_product_meta

The WooCommerce Upload My File woocommerce umf get product meta function.

Description

woocommerce_umf_get_product_meta( $product, (string) $field_name ); 

Parameters (2)

0. $product
The product.
1. $field_name (string)
The field name.

Usage

  1. if ( !function_exists( 'woocommerce_umf_get_product_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-upload-my-file/inc/umf-funct.php'; 
  3.  
  4. // The product. 
  5. $product = null; 
  6.  
  7. // The field name. 
  8. $field_name = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = woocommerce_umf_get_product_meta($product, $field_name); 
  12.  

Defined (1)

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

/inc/umf-funct.php  
  1. function woocommerce_umf_get_product_meta( $product, $field_name ) { 
  2.  
  3. if ( version_compare( WOOCOMMERCE_VERSION, "2.0.0" ) >= 0 ) { 
  4. // even in WC >= 2.0 product variations still use the product_custom_fields array apparently 
  5. if ( $product->variation_id && isset( $product->product_custom_fields[ '_' . $field_name ][0] ) && $product->product_custom_fields[ '_' . $field_name ][0] !== '' ) { 
  6. return $product->product_custom_fields[ '_' . $field_name ][0]; 
  7. // use magic __get 
  8. return maybe_unserialize( $product->$field_name ); 
  9. } else { 
  10. // use product custom fields array 
  11.  
  12. // variation support: return the value if it's defined at the variation level 
  13. if ( isset( $product->variation_id ) && $product->variation_id ) { 
  14.  
  15. if ( ( $value = get_post_meta( $product->variation_id, '_' . $field_name, true ) ) !== '' ) return $value; 
  16. // otherwise return the value from the parent 
  17. return get_post_meta( $product->id, '_' . $field_name, true ); 
  18.  
  19. // regular product 
  20. return isset( $product->product_custom_fields[ '_' . $field_name ][0] ) ? $product->product_custom_fields[ '_' . $field_name ][0] : null;