| @@ 22-45 (lines=24) @@ | ||
| 19 | * @param WC_Product |
|
| 20 | * @return string |
|
| 21 | */ |
|
| 22 | public static function get_product_categories_concatenated( $product ) { |
|
| 23 | if ( ! class_exists( 'WooCommerce' ) ) { |
|
| 24 | return ''; |
|
| 25 | } |
|
| 26 | ||
| 27 | if ( ! $product ) { |
|
| 28 | return ''; |
|
| 29 | } |
|
| 30 | ||
| 31 | $variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : ''; |
|
| 32 | if ( is_array( $variation_data ) && ! empty( $variation_data ) ) { |
|
| 33 | $line = wc_get_formatted_variation( $variation_data, true ); |
|
| 34 | } else { |
|
| 35 | $out = array(); |
|
| 36 | $categories = get_the_terms( $product->get_id(), 'product_cat' ); |
|
| 37 | if ( $categories ) { |
|
| 38 | foreach ( $categories as $category ) { |
|
| 39 | $out[] = $category->name; |
|
| 40 | } |
|
| 41 | } |
|
| 42 | $line = join( "/", $out ); |
|
| 43 | } |
|
| 44 | return $line; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Gets a product's SKU with fallback to just ID. IDs are prepended with a hash symbol. |
|
| @@ 397-417 (lines=21) @@ | ||
| 394 | * @param object $product WC_Product. |
|
| 395 | * @return string |
|
| 396 | */ |
|
| 397 | public function get_product_categories_concatenated( $product ) { |
|
| 398 | ||
| 399 | if ( ! $product instanceof WC_Product ) { |
|
| 400 | return ''; |
|
| 401 | } |
|
| 402 | ||
| 403 | $variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : ''; |
|
| 404 | if ( is_array( $variation_data ) && ! empty( $variation_data ) ) { |
|
| 405 | $line = wc_get_formatted_variation( $variation_data, true ); |
|
| 406 | } else { |
|
| 407 | $out = array(); |
|
| 408 | $categories = get_the_terms( $product->get_id(), 'product_cat' ); |
|
| 409 | if ( $categories ) { |
|
| 410 | foreach ( $categories as $category ) { |
|
| 411 | $out[] = $category->name; |
|
| 412 | } |
|
| 413 | } |
|
| 414 | $line = join( '/', $out ); |
|
| 415 | } |
|
| 416 | return $line; |
|
| 417 | } |
|
| 418 | ||
| 419 | } |
|
| 420 | ||