Tagged: product pages, single product page, woocommerce
-
AuthorPosts
-
January 13, 2015 at 12:55 am #378593
Hi,
I’m trying to get a Custom Field called “Product Code” to appear on my product pages. It appears when the 2012 theme is activated but as soon as I switch to Enfold, it goes away. I have added this code (via WooCommerce Support) to the functions.php Child Theme file:
add_action( 'woocommerce_single_product_summary', 'add_custom_field', 31 ); function add_custom_field() { global $post; echo get_post_meta( $post->ID, 'Product Code', true ); return true; }
You can see how I want each product page to look here (this was with 2012 activated): http://cld.wthms.co/1hfmt
January 13, 2015 at 9:10 pm #379117Hey imagemakerswi!
Try switching the first line to this.
add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );
That will have it display above our tabs and after the summary.
Regards,
ElliottJanuary 14, 2015 at 10:04 pm #379755Below is the code that I have in my child theme’s functions.php file & it didn’t change anything on the product pages…
-CT<?php /* * Add your own functions here. You can also copy some of the theme functions into this file. * WordPress will use those functions instead of the original functions then. */ add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 ); function add_custom_field() { global $post; echo get_post_meta( $post->ID, 'meta:Product Code', true ); return true; }
January 15, 2015 at 6:25 pm #380249Hey!
Are you sure the meta name is correct? If you change the line to this.
echo 'testing testing';
Then you’ll see it’s the correct spot to display the post meta.
Cheers!
ElliottJanuary 16, 2015 at 11:35 pm #381134This reply has been marked as private.January 16, 2015 at 11:38 pm #381135This reply has been marked as private.January 18, 2015 at 11:51 am #381436Hi!
Try to replace the code with this:
add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 ); function add_custom_field() { global $post; echo "<div class='prod-code'>Product Code: "; echo get_post_meta( $post->ID, 'Product Code', true ); echo "</div>"; return true; }
Add this on Quick CSS to adjust the position of the product code:
.prod-code { position: absolute; margin-top: -23px; right: 20%; }
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.