Hi there,
Trying to add a custom field above the product title on all category pages, assuming the field is filled out. Pretty simple, but I’m a novice here. Can you help out?
Something like this, but the syntax is not correct:
add_action('woocommerce_shop_loop_item_title', 'custom_pre_title');
function custom_pre_title(){
if ((is_product_category() && get_field('product_attribute_1')) {
<div class="styling"><?get the_field('product_attribute_1'); ?></div>
Hello,
Would you advise on this please?
You need to supply ACF with the post ID, in this case that is the product ID.
https://stackoverflow.com/questions/27385920/woocommerce-get-current-product-id
add_action('woocommerce_shop_loop_item_title', 'custom_pre_title');
function custom_pre_title(){
global $product;
$id = $product->get_id();
$field_value = get_field('field_name', $id);
}
Thanks for the response.
What if I wanted it to apply for all product category pages?
As far as I know that should apply to all pages where products are listed. I’m not a regular WC user so I cannot really answer your questions. That would be a question more specific to WC.