I have created a new attribute for my woocommerce products with the slug 'short-title'. The idea being that I want to override the title on the shop pages with the short title. I have set up a loop with the following:
if (get_post_meta($product->id, 'short-code', true)) {
$product_name = (get_post_meta($product->id, 'short-code', true));
} else {
$product_name = get_the_title();
}
echo '<div class="product-below"><h4 class="product-name">'.$product_name.'</h4>';
But this is not overriding the title when I enter a value in the short title field for a product. I think I need a different function from get_post_meta
You can try :
global $product;
$product_name = $product->get_attribute( 'short-code' );
instead of
$product_name = get_post_meta($product->id, 'short-code', true)
And if it not works for you then please also once confirm the slug for the added attribute that it is short-code
or short_code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With