I am using a child theme of the Wordpress, WooCommerce theme Storefront.
Storefront header hooked functions are ordered this way:
<?php
/**
* Functions hooked into storefront_header action
*
* #hooked storefront_skip_links - 0
* #hooked storefront_social_icons - 10
* #hooked storefront_site_branding - 20
* #hooked storefront_secondary_navigation - 30
* #hooked storefront_product_search - 40
* #hooked storefront_primary_navigation_wrapper - 42
* #hooked storefront_primary_navigation - 50
* #hooked storefront_header_cart - 60
* #hooked storefront_primary_navigation_wrapper_close - 68
*/
do_action( 'storefront_header' ); ?>
I would like to change the order so the product_search comes before the secondary_navigation.
I have been through the storefront files and cannot find where this order is set, only the items individually.
Can anyone please help me to hook or do what is needed to change the order please?
The suggestion from #loictheaztec was missing the add_action as below -
add_action( 'init' , 'add_and_remove' , 15 );
function mh_add_and_remove() {
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
}
For that purpose you will need first to remove it with remove_action() function and then you will hook it again with add_action() function, changing the priority from 40 to 25.
Priority 25 is located between:
#hooked storefront_site_branding - priority 20
and #hooked storefront_secondary_navigation - priority 30
Paste this code snippet in function.php of your active theme folder (or better in your active child theme folder):
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
Not sure if Loic got his answer to solve the duplicate issue, but to all that may need an answer, it needs to be wrapped in a function as suggested by Scott Eldo initially.
So...
add_action( 'init' , 'add_and_remove' , 15 );
function mh_add_and_remove() {
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
}
as opposed to just putting it in function.php as such...
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
I tried editing the accepted answer, got rejected...
Every answer in this post has an error, the function name is not coincident with the add_action command....
So, it should be...
add_action( 'init' , 'change_header_order' , 15 );
function change_header_order() {
remove_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_product_search', 25 );
}
You can remove the actions, then add them in the order you would like them to appear:
add_action( 'init' , 'mh_add_and_remove' , 15 );
function mh_add_and_remove() {
remove_action( 'storefront_header','storefront_header_container', 0 );
remove_action( 'storefront_header','storefront_skip_links', 5 );
remove_action( 'storefront_header', 'storefront_site_branding', 20);
remove_action( 'storefront_header','storefront_secondary_navigation', 30);
remove_action( 'storefront_header', 'storefront_product_search', 40 );
remove_action( 'storefront_header', 'storefront_header_container_close', 4);
add_action( 'storefront_header','storefront_header_container', 69 );
add_action( 'storefront_header','storefront_skip_links', 90 );
add_action( 'storefront_header', 'storefront_site_branding', 91);
add_action( 'storefront_header','storefront_secondary_navigation', 92);
add_action( 'storefront_header', 'storefront_product_search', 93 );
add_action( 'storefront_header', 'storefront_header_container_close', 94);
}
Related
I have a child theme that I am trying to override a WooCommerce function.
WooCommerce file in plugin location: woocommerce/includes/wc-template-hooks.php. I created a new file in the same hierarchy in my child theme and it's located here: my-child-theme/woocommerce/includes/wc-template-hooks.php
My edited section is I commented out the product title in child theme:
/**
* Product Summary Box.
*
* #see woocommerce_template_single_title()
* #see woocommerce_template_single_rating()
* #see woocommerce_template_single_price()
* #see woocommerce_template_single_excerpt()
* #see woocommerce_template_single_meta()
* #see woocommerce_template_single_sharing()
*/
//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); //commented
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
However, when I goto my product page, I still see the title.
Any idea what I am doing wrong?
You need to remove action woocommerce_single_product_summary to this work properly.
add_action( 'woocommerce_before_single_product', 'remove_woocommerce_single_product_summary', 10 );
function remove_woocommerce_single_product_summary() {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
Just add this to your functions.php and will do the magic.
You also can try to add remove_action() out of the add_action(). Just like this...
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 15 );
...directly to functions.php
Play with it.
TIPS & TRICKS
If you want to change your HTML in the title or do anything you want, here is example:
add_action( 'woocommerce_before_single_product', 'remove_woocommerce_single_product_summary', 10 );
function remove_woocommerce_single_product_summary() {
// First, we remove it
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
// Second, we add new title
add_action( 'woocommerce_single_product_summary', 'woocommerce_my_new_title', 1 );
}
function woocommerce_my_new_title(){
echo '<h1 class="some-my-custom-classes">' . the_title() . '</h1>';
}
If your active theme does not support Woocommerce and you want to add
a Woocommerce template to your active theme, you must register
WooCommerce, or give Woocommerce features.
Check out these links for more details:
https://github.com/woocommerce/woocommerce/wiki/Declaring-WooCommerce-support-in-themes
https://docs.woocommerce.com/document/template-structure/
One important thing:
If you change the template folder within the Woocommerce plugin, there is a good chance that you will lose your settings after the plugin update. That is why it is better to work in an active theme.
function my_custom_action() {
echo '<p>Hello here</p>';
};
add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 );
I'm customizing my woocommerce to fit the layout of my custom theme. I have an issue with the product description, it will not be displayed in the single product page, only the short description will be showed. I don't know why there is this problem, I didn't touched the relative hook. Is there a fix for this? I have this remove hooks in my functions.php file:
/* WooCommerce default hooks remotion */
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
//remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
//remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
remove_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );
remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
//remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
and this is the template for a single product
<?php
/**
* The template for displaying product content within loops
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-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.6.0
*/
defined( 'ABSPATH' ) || exit;
global $product;
// Ensure visibility.
if ( empty( $product ) || ! $product->is_visible() ) {
return;
}
?>
<div <?php wc_product_class( 'col-sm-12 col-md-4 col-lg-3', $product ); ?>>
<div class="card shop-product-card">
<?php
/**
* Hook: woocommerce_before_shop_loop_item.
*
* #hooked woocommerce_template_loop_product_link_open - 10
*/
do_action( 'woocommerce_before_shop_loop_item' );
/**
* Hook: woocommerce_before_shop_loop_item_title.
*
* #hooked woocommerce_show_product_loop_sale_flash - 10
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
/**
* Hook: woocommerce_shop_loop_item_title.
*
* #hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* Hook: woocommerce_after_shop_loop_item_title.
*
* #hooked woocommerce_template_loop_rating - 5
* #hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
/**
* Hook: woocommerce_after_shop_loop_item.
*
* #hooked woocommerce_template_loop_product_link_close - 5
* #hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
?>
</div>
</div>
please make sure that you have declared add_theme_support('woocommerce') in your functions.php
I am trying to move add to cart button under button(cart form) under the product image and leave variations where they are.
But with below hook variations are also going under the product image
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
Any way to make only button move under the image and not variations form.
Here is the screenshot:
Thank You
Tried following solution but no Luck
Try 1:
remove_action( 'woocommerce_single_variation', 'remove_variation', 10 );
function remove_variation(){
woocommerce_single_variation();
}
Try 2:
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
Default Actions:
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
Remove Default Actions:
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
Add Custom Action:
add_action( 'woocommerce_single_variation', 'new_custom_action', 5 );
function new_custom_action() {
echo 'TEST';
}
If you look at the default variable template in woocommerce/templates/single-product/add-to-cart/variable.php you can see that for variable products, it combines both the variations drop-downs and the add to cart button together in the 'woocommerce_single_variation' hook:
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
You can either customise this file within your theme to change this behaviour, or remove the woocommerce_single_variation function from this hook and add it somewhere else.
I'm making a woocommerce theme and I'm having trouble reordering the single page hooks. I want the product short description to appear under the product title.
I've been able to move the short description under the title using the remove / add action, I added this to the function.php file
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 7 );
Here's what my content-single-product file looks like
<div class="summary entry-summary">
<?php
/**
* woocommerce_single_product_summary hook
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_excerpt - 7
* #hooked woocommerce_template_single_rating - 20
* #hooked woocommerce_template_single_price - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
*/
do_action( 'woocommerce_single_product_summary' );
?>
The problem is now the description is showing up twice, once in the new position (under the title) and another time it's original position (under the price)
Any help would be greatly appreciated! Thanks.
Ok I've been able to change the hook position in the wp-template-hooks.php file directly.
* Product Summary Box
*
* #see woocommerce_template_single_title()
* #see woocommerce_template_single_price()
* #see woocommerce_template_single_excerpt()
* #see woocommerce_template_single_meta()
* #see woocommerce_template_single_sharing()
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 7 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
My question now is why can't I change these by Removing/Adding actions to the functions.php file?
add this function to your theme functions.php
add_action( 'init', 'remove_content' );
function remove_content() {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 7 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );}
In case you like add some elements again, use add_action and change priorities if needed.
I've bitten off more than I can chew and need some help with WooCommerce.
I'm trying to edit the shop front page (i've managed to do the product single pages fine) but can't find the out put for the hooks anywhere.
Basically, all i'm trying to do is make the Title of the product appear before the thumbnail and add a"view" button after the thumbnail.
I'm literally pulling my hair out so if anyone could help i'd be extremely grateful!
Add below on function.php
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 90 );
Adding above code will duplicate you thumbnail, then add below CSS will do trick.
.product-images { display: none; }
You should to see in plugin/woocommerce/woocommerce-hook.php
Form Line 100 - 107
/**
* Before Single Products Summary Div
*
* #see woocommerce_show_product_images()
* #see woocommerce_show_product_thumbnails()
*/
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
/**
Form Line 120 - 132
/**
* Product Summary Box
*
* #see woocommerce_template_single_title()
* #see woocommerce_template_single_price()
* #see woocommerce_template_single_excerpt()
* #see woocommerce_template_single_meta()
* #see woocommerce_template_single_sharing()
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
/**
Change order of add_action
Change value of the second arg
Good luck!