Extra field in product category page
-
Hi there.
Really hope you can help me with this one.I would like to have a extra field / number on my product category page.
——————–
I am building a webpage / web catalog where i would like to have an extra “manufacture no.” field below my SKU no.
You can see my product category page here:
As you can see – there is only a SKU number.If you go to a specific product or product page there is a “DB number”
I would also like to have this number on my product category page.
How do i do that ?Would the best way to do something like this
https://businessbloomer.com/woocommerce-show-product-custom-field-in-the-category-pages/Really hope you can help me
Cheers/Kimo
-
Hey there,
Thanks for that detailed explanation and the screenshots!
You’re on exactly the right track – this is indeed the snippet that you’d need to get started:
https://businessbloomer.com/woocommerce-show-product-custom-field-in-the-category-pages/Hi there Hannah
Thank you so much for your reply / answerTake a look here:
But i really much would like to have it underneath / below the SKU no.
Just cant find the right file to edit in.Thanks once again Hannah
Cheers
/KimIf I understand you correctly you’re wanting the SKU that shows on single product to appear on Category page as well or you’re trying to get an extra field that you can add a completely different number?
When I read this:
If you go to a specific product or product page there is a “DB number”
I would also like to have this number on my product category page.
How do i do that ?It sounds like you just want the SKU to show on Category pages. If that’s the case the easier way to do that is to add this to your functions file.
function ssd_shop_display_skus() { global $product; if ( $product->get_sku() ) { echo '<div class=”product-meta”>SKU:' . $product->get_sku() . '</div>'; } } add_action( 'woocommerce_after_shop_loop_item', 'ssd_shop_display_skus', 9 );If I’m mistaken at your request let me know.
Hi Stef – And thanks for your respons.
Infact i would like to have a “DB number” / “manufacture no.” right under / below the
SKU number.Right now the SKU number already shows on the catagory page – look here: https://imgur.com/TYauJze
I would also like to show a “DB number / manufacture number” right underneath the SKU
Do you have any idear on how to do that?Thanks for your help and respons Stef.
Cheers
/KimAh then I did misunderstand you. Yes that is the correct way like @fernashes said.
Simply go into backend. Make sure Custom Fields is enabled.
Scroll down to Custom Fields and click Enter New, then add loopdesc and add your value (the DB number) and then click Add Custom Field. Click update voila!
Front End
Hi Stef
Thank you so much for the replyI have done that, and now i have a DB field / number
But i would lige to move it down below / SKU number.
How do i do that? – I had a look in the archive-product.php file.
But it dosent really work.Stef – once again – Thanks mate
Cheers
/KimKim,
Just change the
woocommerce_after_shop_loop_item_titleto
woocommerce_after_shop_loop_itemHi Stef
thanks for your reply ..Dough .. cant find that line i this here .php file –
Could it really be it – You are the BEST – if that works 🙂Cheers
/Kim<?php /** * The Template for displaying product archives, including the main shop page which is a post type archive * * This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php. * * HOWEVER, on occasion WooCommerce will need to update template files and you * (the theme developer) will need to copy the new files to your theme to * maintain compatibility. We try to do this as little as possible, but it does * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * * @see https://docs.woocommerce.com/document/template-structure/ * @package WooCommerce/Templates * @version 3.4.0 */ defined( 'ABSPATH' ) || exit; get_header( 'shop' ); /** * Hook: woocommerce_before_main_content. * * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content) * @hooked woocommerce_breadcrumb - 20 * @hooked WC_Structured_Data::generate_website_data() - 30 */ do_action( 'woocommerce_before_main_content' ); ?> <header class="woocommerce-products-header"> <?php if ( apply_filters( 'woocommerce_show_page', true ) ) : ?> <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1> <?php endif; ?> <?php /** * Hook: woocommerce_archive_description. * * @hooked woocommerce_taxonomy_archive_description - 10 * @hooked woocommerce_product_archive_description - 10 */ do_action( 'woocommerce_archive_description' ); ?> </header> <?php if ( woocommerce_product_loop() ) { /** * Hook: woocommerce_before_shop_loop. * * @hooked woocommerce_output_all_notices - 10 * @hooked woocommerce_result_count - 20 * @hooked woocommerce_catalog_ordering - 30 */ do_action( 'woocommerce_before_shop_loop' ); woocommerce_product_loop_start(); if ( wc_get_loop_prop( 'total' ) ) { while ( have_posts() ) { the_post(); /** * Hook: woocommerce_shop_loop. * * @hooked WC_Structured_Data::generate_product_data() - 10 */ do_action( 'woocommerce_shop_loop' ); wc_get_template_part( 'content', 'product' ); } } woocommerce_product_loop_end(); /** * Hook: woocommerce_after_shop_loop. * * @hooked woocommerce_pagination - 10 */ do_action( 'woocommerce_after_shop_loop' ); } else { /** * Hook: woocommerce_no_products_found. * * @hooked wc_no_products_found - 10 */ do_action( 'woocommerce_no_products_found' ); } /** * Hook: woocommerce_after_main_content. * * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content) */ do_action( 'woocommerce_after_main_content' ); /** * Hook: woocommerce_sidebar. * * @hooked woocommerce_get_sidebar - 10 */ do_action( 'woocommerce_sidebar' ); get_footer( 'shop' );You don’t need to touch any template files. Simply add Roldolfo’s code snippet to your functions file as stated,(without all that other junk he likes to add) and you’re good to go.
I’d also change his excerpt class and call it dbnumb just in case your theme or someone else codes in an excerpt class. That’s just not unique enough.
//right here this line right here add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_woocommerce_product_excerpt', 35 ); function bbloomer_woocommerce_product_excerpt() { global $post; if ( is_home() || is_shop() || is_product() || is_product_category() || is_product_tag() ) { echo '<span class="dbnumb">'; echo get_post_meta( $post->ID, 'loopdesc', true ); echo '</span>'; } }Hi Stef
Aha – found it in the function file .. AND IT WORKS 🙂
Thank you so much – Stef.Although i would like to move the DB number up – right below the SKU number.
Look here : https://imgur.com/GrUPuiQBut it that poosible – As i see it, i would like it to be a part of : .product-loop-body See source code in img above.
Sorry all my questioning.
Once again Stef
Thanks for all/Kimo
-
This reply was modified 6 years, 6 months ago by
webactor.
For that you will need to copy the meta.php file over to your child theme,(I assume your using one) and add something like this:
<?php $loopdesc = get_post_meta(get_the_ID(), 'loopdesc', true); if(!empty($loopdesc)) { echo $loopdesc; } ?>Look for SKU in the meta file where I have the arrow (this won’t be the same as yours because I never code like somebody else) and add my snippet above this SKU like I have here.
Hi there Stef
Danm you are tough …Stef – The meta.php from where exactly? – wp-include?
I am usign a child theme – based on : https://demo2.madrasthemes.com/electro-wide/Cant seem to find any SKU in this here meta file.
Thanks Stef
/KimoMeta.php is located inside the single-product folder within woocommerce folder. Make a copy to your child theme and then edit. Take a screenshot of that file and I’ll tell you what line to place it on.
Hi Stef .. Dough
Saw it just now – thanks .. Let me just try if it works ../Kimo
😁🙃
-
This reply was modified 6 years, 6 months ago by
The topic ‘Extra field in product category page’ is closed to new replies.