-
AuthorPosts
-
December 5, 2023 at 10:23 pm #1427270
Hi
I am trying to add some text above my products in woocommerce. I’d like it to show the category of the product.
I have this code that adds the text, but I don’t know how to pull the category of the product:add_action( 'woocommerce_before_single_product_summary', 'enfold_customization_woocommerce_extra_text', 1); function enfold_customization_woocommerce_extra_text(){ echo 'category goes here'; }
I have a checkout page with the checkout field labels used as placeholders, but I would rather have them above the input fields. I inherited this site and it seems that isn’t the default layout since I can find the code to use them as placeholders but not to move them above the fields.
can you help me with this?
thanks
Nancy- This topic was modified 1 year ago by Munford.
December 6, 2023 at 4:07 am #1427292Hi Munford,
Please try to use this code instead:
add_action( 'woocommerce_before_single_product_summary', 'enfold_customization_woocommerce_extra_text', 1); function enfold_customization_woocommerce_extra_text() { // Get the product categories $product_categories = get_the_terms(get_the_ID(), 'product_cat'); // Check if there are categories if ($product_categories && !is_wp_error($product_categories)) { $category = reset($product_categories); echo '<p>Category: ' . esc_html($category->name) . '</p>'; } }
Hope it helps.
Best regards,
NikkoDecember 6, 2023 at 9:49 am #1427313thanks!
That gave me the text “Category: Beni Ouarain” (for example) above the photo.
I removed the “Category” text since I just want the category name, but I need to move it above the title.
Can that be done?If I use this code:
add_action( 'woocommerce_before_single_product_summary', 'enfold_customization_woocommerce_extra_text', 1); function enfold_customization_woocommerce_extra_text(){ echo 'category goes here';
it puts the text above the title which is what I want but your code puts it above the photo.
Aso: Any suggestions for the checkout field labels?
best
NancyDecember 7, 2023 at 3:20 am #1427387Hi Nancy,
Please try to change the hook from woocommerce_before_single_product_summary to woocommerce_single_product_summary
Then add this CSS code in Enfold > General Styling > Quick CSS:
.single-product-summary .product_title { margin-top: 0; }
Hope it helps.
Best regards,
NikkoDecember 7, 2023 at 9:32 am #1427422fantastic! it worked perfectly.
thanks so much!December 7, 2023 at 12:02 pm #1427440Hi,
Glad Nikko was able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘code for woocommerce categories & checkout field labels’ is closed to new replies.