Created
February 28, 2024 08:27
-
-
Save ihslimn/832a5a150dbf5007f98551b48b3eda94 to your computer and use it in GitHub Desktop.
JetWooBuilder Show product atributes in cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'get_post_metadata', function( $value, $post_id, $key ) { | |
if ( $key !== 'cart_product_atributes' ) { | |
return $value; | |
} | |
if ( ! get_post( $post_id ) ) { | |
return $value; | |
} | |
$atts = get_post_meta( $post_id, '_product_attributes', true ); | |
$result = array(); | |
foreach ( $atts as $slug => $params ) { | |
if ( $params['is_taxonomy'] === 0 ) { | |
$result[] = $params['value']; | |
} else { | |
$attributes = wc_get_product_terms( $post_id, $slug ); | |
if ( ! is_array( $attributes ) ) { | |
continue; | |
} | |
$result[] = implode( ', ', array_column( $attributes, 'name' ) ); | |
} | |
} | |
$value = implode( ', ', $result ); | |
return $value; | |
}, 0, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment