Display a custom field under WooCommerce single product image - woocommerce

I am trying to display a custom field on Woocommerce single product page just under the product image.
Does anyone know the hook for this custom field?

You can achieve the above by adding in follows hook -
function add_custom_field_just_under_image(){
global $product;
echo "Your custom code goes here";
}
add_action( 'woocommerce_product_thumbnails', 'add_custom_field_just_under_image', 10 );
Codes goes to active theme's functions.php

Related

Show content before main content based on color attribute

I found a code snippet to display the content before the main content and it worked.
Currently the content is displayed on all pages. (except shop page)
The code :
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
if(!is_shop()){
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
What I want to ask is, how to display content only for color attribute products in the form of links.
Example :
The display (content) will ONLY SHOW when the url is like this :
mysite.com/color/red/
Sorry if the explanation is not good because I don't really understand this.
Any help is greatly appreciated.
thank you
I understand your question is about displaying that extra content, if the current query is for a product archive page only showing products of a certain attribute 'color'.
Each WooCommerce attribute is an independent taxonomy.
WordPress's is_tax('parameter') function checks, if the query is for an existing custom taxonomy archive page (other than category & tag) & if the query is for that specific taxonomy 'parameter', in your case 'color'.
So, this code snippet in your functions.php or equivalent plugin should work:
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
(is_tax('color')) {
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
Though, to make the above template WooCommerce override work, declare WooCommerce support for your theme by adding the following lines to your functions.php or plugin equivalent:
function theme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'theme_add_woocommerce_support' );

How do I add product attributes to the product page in WooCommerce?

I'm using WooCommerce and Elementor Pro. Is there any way to add specific product attributes (e.g. gross and net weight) below the Add to cart button?
It seems like an obvious thing but I haven't found options or snippets for it.
First you add attributes to product. Then you use this snippet in functions.php:
// maybe remove tab with attributes
add_filter( 'woocommerce_product_tabs', 'remove_info', 100, 1 );
function remove_info( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// show attributes
add_action( 'woocommerce_single_product_summary', 'summary_attributes', 35 );
function summary_attributes() {
global $product;
if ( $product->has_attributes() ) {
wc_display_product_attributes( $product );
}
}
Setting Up WooCommerce Attributes
go to Products > Attributes
Add the attribute name
Slug will automatically be created, and we can leave the rest of these options untouched.
Click “Add attribute” button and your attribute will be added.
Configure The Attributes
After creating attribute, now we can add different variation on your product. Click on the Configure Terms option.
Enter the variation
Add some short description
Click on the add new tab
To understand it in a better way you can follow this tutorial

WP Genesis Framework - Remove post_content and restructure entry

I'm creating a Wordpress theme with Genesis.
1.In homepage and archive page, I want display only featured image and post title. How could I remove post_content in hompage and archive page only. This link: http://my.studiopress.com/snippets/entry-content/ remove all content including when I view the post.
By default, Genesis display title -> post_info ->featured image -> post_content in the archive page. How could I restructure it. I would to display featured image fist ->title->post_info
Thanks
1. Hiding the Entry Content from Home & Archive Pages in Genesis:
You are on right track with entry_content hook via remove_action however as you want to happen it only on Homepage or Archive pages, you need to wrap that genesis code in WordPress's template tags i.e
<?php
if (is_front_page() || is_home() || is_archive() ) {
//* Remove the post content (requires HTML5 theme support)
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
}
?>
2. Changing the Order of Entry Parts in Genesis Framework
You can change order by changing Hooks or if hook is same then WordPress's hook priority value. Default value is 10 , higher the value, lower the hook placement.
For Example Entry Info and Entry Title are added this way:
add_action( 'genesis_entry_header', 'genesis_do_post_title' );
add_action( 'genesis_entry_header', 'genesis_post_info', 12 );
As you can see title's hook is default 10, and info is set to 12.
If I wanted to move post info up, I could simple remove title from 10, and add back at 14 e.g.
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
add_action( 'genesis_entry_header', 'genesis_do_post_title', 14 );
Now you can do change something from lower hook to above. Like in case of image, it is added at this hook:
add_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
As genesis_entry_content hook is way lower than genesis_entry_header, you can remove this image from here and move to genesis_entry_header or different hook e.g.
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
add_action( 'genesis_entry_header', 'genesis_do_post_image', 8 );
Above code removes Post image from the content section and then adds back to header section above the title.
See this visual guide for order of different genesis hooks: https://genesistutorials.com/visual-hook-guide/

Add custom button in profile page of BuddyPress

I tried adding a custom button in BuddyPress profile page using below mentioned code. But when I added that code, only Name & Profile picture was appearing & no other content generated through BuddyPress was appearing:
function mapbtn_custom_button() {
echo '<div class="mapbtn">map<div>';
}
add_filter( 'bp_before_member_header_meta', 'mapbtn_custom_button' );
You're trying to hook a filter to an action call.
Try this instead:
add_action( 'bp_before_member_header_meta', 'mapbtn_custom_button' );

display custom fields automatically when a custom post type is displayed

I am trying to automatically display all the custom fields of a custom post type alongside it's title and content.(Not in admin but on my actual site)
I need to be able to do this with an action hook or filter, rather than creating a template.
After scouring the web I was able to find the 'publish_{custom_post_type_name}' hook:
function my_cool_hook() {
echo get_post_meta($post->ID, 'my-custom-field-name', true);
}
add_action( 'publish_past_symposia', 'my_cool_hook' );
but it doesn't seem to do anything when I view my published custom post type on my site. Any ideas?
add_action( 'publish_past_symposia', 'my_cool_hook' );
This hook triggered only if PUBLISH post type.
YOu need to trigger the hook on web part - so...
add_filter('the_content', 'my_cool_hook');
function my_cool_hook($content){
return $content.get_post_meta(get_the_id(), 'my-custom-field-name', true);
}
now the content body filtred and your string from custom fields added.

Resources