Skip to content

Instantly share code, notes, and snippets.

@ihslimn
Created February 28, 2024 08:27
Show Gist options
  • Save ihslimn/832a5a150dbf5007f98551b48b3eda94 to your computer and use it in GitHub Desktop.
Save ihslimn/832a5a150dbf5007f98551b48b3eda94 to your computer and use it in GitHub Desktop.
JetWooBuilder Show product atributes in cart
<?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