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!
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 );
Unfortunately, despite remove_action on the desired. page plus shipping costs. Does anyone know what this can do?
This is shown on my website. I want to remove it with php.
<p class="wc-gzd-additional-info">
<span class="wc-gzd-additional-info tax-info">inkl. 19 % MwSt.</span>
</p>
I already removed the title with
//remove product title only //This worked
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
Now I am trying to do the same but it does not work
<?php
/**
* WooCommerce Custom Hook
* woocommerce-hooks.php
*/
//remove product title only //This worked
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_shipping_costs_info', 7 )
// include plugin functions
include_once( ABSPATH . 'wp-admin/includes/plugin.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 like to remove the product thumbnails (not display:none, but completely remove action) on Product Category Pages. Any suggestions?
I tried adding the following in my Wordpress functions file but didn't work:
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
The hook used on the category page is: woocommerce_before_shop_loop_item_title.
So you need to do the following:
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
Remove thumbnail category, go to file content-product-cat.php and remove the following code:
/**
* woocommerce_before_subcategory_title hook
*
* #hooked woocommerce_subcategory_thumbnail - 10
*/
do_action( 'woocommerce_before_subcategory_title', $category );