How to change the position of the the breadcrumbs using hooks? - php

I am learning Woocommerce. I am on shop page and I have to display the breadcrumbs below the product header. By default it is showing like below image.
I have to display the below of the header. I want to know that what hook I have to use it.
I tried below
add_action( 'woocommerce_breadcrumb_defaults', 'woocommerce_show_page_title', 10, 2 );
but it's not working even I am also not getting my home in the breadcrumbs

You must use the following hooks to display breadcrumb under the archive title:
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
add_action( 'woocommerce_archive_description', 'woocommerce_breadcrumb', 15 );
If you need to do this on specific pages, you should use conditional tags:
// just for Shop page
if ( is_shop() && ! is_product_tag() && ! is_product_category() ) {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
add_action( 'woocommerce_archive_description', 'woocommerce_breadcrumb', 15 );
}

Related

Remove WooCommerce messages from account content

I'm currently trying to remove all messages from the WooCommerce account with the following code line:
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 10 );
Sadly, the wrapper for messages is still there:
<div class="woocommerce-notices-wrapper">lol</div>
I've added a lol to the function that displays the wrapper and it's the correct function I'm trying to remove. No idea why it's not working...
If your active theme uses the default woocommerce templates and hooks for myaccount pages, then add the follows code snippet to achieve the above -
function modify_wc_hooks() {
// remove all wc my account's notices wrapper
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
}
add_action( 'init', 'modify_wc_hooks', 99 );
Codes goes to your active theme's functions.php

Remove single product tabs and add the related content instead In Woocommerce

I have a client who wants to pull the information that defaults into tabs on single product pages in WooCommerce into a different location on the page and remove the tabs entirely.
There are three default product tabs:
product Description,
Additional Information
and Reviews.
Removing the tabs and setting up the Description to display was easy enough to set up in
/wp-content/plugins/woocommerce/includes/wc-template-hooks.php:
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
function woocommerce_template_product_description() {
woocommerce_get_template( 'single-product/tabs/description.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_description', 10 );
That works fine.
I tried to repeat the process by building out new functions that access the template files for Additional Info and Reviews like so:
function woocommerce_template_product_addinfo() {
woocommerce_get_template( 'single-product/tabs/additional-information.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_addinfo', 20 );
function woocommerce_template_product_reviews() {
woocommerce_get_template( 'single-product/review-rating.php' );
}
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_product_reviews', 30 );
But neither is displaying. What am I doing wrong here?
First woocommerce_get_template() is deprecated and replaced by wc_get_template() instead. After some searching and testing (mainly to get the reviews displayed), I have found the way:
add_action( 'woocommerce_after_single_product_summary', 'removing_product_tabs', 2 );
function removing_product_tabs(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary', 'get_product_tab_templates_displayed', 10 );
}
function get_product_tab_templates_displayed() {
wc_get_template( 'single-product/tabs/description.php' );
wc_get_template( 'single-product/tabs/additional-information.php' );
comments_template();
}
Code goes in function.php file of your active child theme (or theme). Tested and work (WC 3+).

Change Woocommerce single product templates order based on product tag

I have two templates, one for Panorama & Multi-Panel photographs, the other for Normal ones.
I'm trying to code a conditional statement that checks the product tag in order to select the relevant template to be displayed.
Panorama photos have the product tag 'panorama' or 'multi-panel'.
If the 'panorama' or 'multi-panel' tag is true >> perform some remove_action and add_action functionality on the Panorama product page...
...otherwise do nothing to the Normal product page...
This is what I have been dappling with to no affect!!
function robhemphill_panorama_layout () {
if ( has_tag( array( 'panorama', 'multi-panel'))) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_excerpt', 10 );
} else {
// Do nothing
}
}
add_action( 'woocommerce_single_product_summary', 'robhemphill_panorama_layout' );
Any thoughts or ideas would be great, can't find anything online!
As you are targeting Woocommerce product tags (but not WordPress tags) try this instead:
add_action( 'woocommerce_single_product_summary', 'robhemphill_panorama_layout', 1 );
function robhemphill_panorama_layout () {
global $product;
if ( has_term( array( 'panorama', 'multi-panel' ), 'product_tag', $product->get_id() ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_excerpt', 10 );
}
}
Code goes in function.php file of your active child theme (or theme).
Tested and works.

remove woocommerce storefront homepage title php

I am using storefront theme by woocommerce. I need to remove homepage title (h1) with php, i know css solution, but i don't want to use it, because i want to add h1 to other place in that page and it's bad for seo to have 2 h1's in one page! I also know about plugins that remove page title, but they are working as css display:none; property!
I tried all the snippets that i could find in web, but no luck!
Here is my site domain BrightBells.com
Here is PHP code snippets that i tried one by one by adding to my functions.php file, but none of its help!
Snippet 1
function wc_hide_page_title() {
if( is_front_page() )
return true;
}
add_filter( 'woocommerce_show_page_title', 'wc_hide_page_title' );
Snippet 2
function sf_change_homepage_title( $args ) {
remove_action( 'storefront_page', 'storefront_page_header', 10 );
}
add_action( 'init', 'sf_change_homepage_title' );
Snippet 3
function sf_change_homepage_title( $args ) {
remove_action( 'storefront_page', 'storefront_page_header', 10 );
}
add_action( 'wp', 'sf_change_homepage_title' );
Snippet 4
function sf_change_homepage_title( $args ) {
remove_action( 'storefront_page', 'storefront_page_header', 10 );
}
add_action( 'after_setup_theme', 'sf_change_homepage_title' );
Snippet 5
function sf_change_homepage_title( $args ) {
if(is_front_page()) {
remove_action( 'storefront_page', 'storefront_page_header', 10 );
}
}
add_action( 'init', 'sf_change_homepage_title' );
Snippet 6
if ( is_front_page() ) {
remove_action( 'storefront_page', 'storefront_page_header' );
}
Snippet 7
if ( is_page('page id') )
{
add_filter( 'the_title', '__return_false' );
}
None of this snippets help, please help!
Here is page settings screenshots!
setting page screenshot
page screenshot
Thanks in advance
I hope you are using a child theme or plugin in doing this.
Because it will just be removed when your theme updates.
In storefront version 2.2.5, it can be done with this code:
remove_action( 'storefront_homepage', 'storefront_homepage_header', 10 );
Update:
if on a child theme please do something like this:
if ( ! function_exists( 'storefront_homepage_header' ) ) {
function storefront_homepage_header() { }
}
Child themes are run first before the parent theme. By doing so, we will define this storefront_homepage_header function first. In that case, the parent theme will not create it. Applicable only on themes that uses function_exists, luckily, storefront does.
remove_action will not work because the action has not been added yet.
Try this ---
if ( is_front_page() || is_home() )
{
add_filter( 'the_title', '__return_false' );
}

Hide product prices and add-to-cart buttons but not variations for unregistered users in WooCommerce

In my WooCommerce shop I want to hide the prices until the customer has logged in. I've got the following code working that does exactly that:
add_action('init','hide_price');
function hide_price(){
if(!is_user_logged_in()){
remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart',10);
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart',30);
remove_action('woocommerce_single_product_summary','woocommerce_template_single_price',10);
remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price',10);
add_action('woocommerce_single_product_summary','print_login_to_see',31);
add_action('woocommerce_after_shop_loop_item','print_login_to_see',11);
}
}
function print_login_to_see(){
echo '' . __('Login to see prices','theme_name') . '';
}
However this also removes the variation drop down and I would like to keep that.
Is there any direct way to keep the variation drop down menu but still hide the prices until the customer has logged in?
Thanks
Updated:
You will need to separate shop and archives pages from single product pages. In single product pages you will target variable products to add and remove the specific hooked functions.
Last thing, in your function print_login_to_see(), woocommerce_get_page_id() is obsolete and it's replaced by wc_get_page_id() …
So your code will look to this:
// For product archives pages
add_action( 'init', 'hide_product_archives_prices' );
function hide_product_archives_prices(){
if( is_user_logged_in() ) return;
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10) ;
add_action ( 'woocommerce_after_shop_loop_item', 'print_login_to_see', 10 );
}
//
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
if( is_user_logged_in() ) return;
global $product;
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
if( ! $product->is_type('variable') ){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary','print_login_to_see', 30 );
} else {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10);
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
add_action( 'woocommerce_single_variation', 'print_login_to_see', 20 );
}
}
// Display a my account link
function print_login_to_see(){
echo '' . __('Login to see prices','theme_name') . '';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested on WooCommerce 3+ and works.

Categories