Good day or night,
I would like to display a custom product field value of a specific category (Shirts) on a woo commerce checkout page. I've succeeded in checking for the category, but my attempts to print the product attribute have failed. Where am I going off track?
add_action('woocommerce_before_calculate_totals', 'personalization_check_category_in_cart');
function personalization_check_category_in_cart() {
// Set $cat_in_cart to false
$cat_in_cart = false;
// Loop through all products in the Cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// If Cart has category term, set $cat_in_cart to true
if ( has_term( 'Personalize', 'product_cat', $cart_item['product_id'] ) ) {
$cat_in_cart = true;
break;
}
}
if ( $cat_in_cart ) {
// Print product
echo '<div class="checkout-personalization-message-container><p>';
// === ? Print product custom field value here ? ===
//global $product;
//echo wc_display_product_attributes( $product ); // doesn't work
//global $product;
//$product->get_attribute( 'product_personalization_note' ); // doesn't work
//get_post_meta( $order->get_id(), 'product_personalization_note', true ); // doesn't work
echo '</p></div>';
}
}
For reference: the code that produced the custom product field value can be found here: