Reordering Woocommerce actions on single product page - php

I'm trying to redesign a Woccommerce single product page with the elements in the following order:
title
product tabs (description/reviews)
price
add to cart button
meta
As I understand it, I can simply remove the actions in my theme's functions.php file and then re-add them with the priorities I want, so I've done this:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 6 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 8 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 99 );
However, no matter what I do with the priority numbers, the product tabs appear at the end. There's obviously something I don't know. Can someone enlighten me?

Aha!
Funny how often you spend ages trying to solve a problem and then as soon as you ask for help you realise what the answer.
The secret is in the question, really...
I have been adding this action
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 6 );
when I should have been adding this:
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 6 );
The crucial difference is the "_after".
It was that simple. Naturally it was adding this action after all the woocommerce_single_product_summary template hooks had been done.

Related

WooCommerce product title cannot be removed on the single product page

I cannot remove the default title of WooCommerce product on single page.
The title doesn't have any tags for me to hide it via css.
I also tried using
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
but still not working.
Does anyone have a solution on this?
Give it a try in the following way
function customise_product_page() {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
add_action( 'woocommerce_before_single_product', 'customise_product_page' );

Move related products section before reviews in Woocommerce

I am working with woocommerce plugin. I currently have product, reviews and then it's related products in product detail page. I would like to change the display order. I want to display product, it's related products and then it's reviews. I have tried changing the priority in functions.php but it doesn't work.
Any help would be appreciated!
The review section is located in woocommerce product tabs by default… The following code will move related products section before that product tabs:
add_action( 'init', 'move_related_products_before_tabs' );
function move_related_products_before_tabs( ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 5 );
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Add below code to active theme's function.php
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_related_products', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 20 )
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 10 )
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 20 )

Unable to remove single product pages from woocommerce

I have added the following code snippet to functions.php after reseaching a lot:
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
This snippet seems to work for a lot of people.
I'm using the Salient wordpress theme, and this code snippet has no effect on the hyperlink wrap on single product grids.
Please HELP!
You should add it to a hook that proceeds when the actions have been set otherwise you won't be able to remove them. The actions should exist after the 'after_setup_theme' hook. Also ensure the hooks are removed with the same priority as they were set with.
function add_remove_hooks() {
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
}
add_action( 'after_setup_theme', 'add_remove_hooks' );

Move Woocommerce Single Products Title

I was trying to move the product title at Woocommerce single product page to different location. The accepted location is just under itemscope itemtype="http://schema.org/Product" and i was trying to remove first the title from current location which is remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 50); but not removed the title from current location.
Another problem is I can't add product title to new location which I have used do_action( 'woocommerce_moved_product_title_position' ); and then add_action('woocommerce_moved_product_title_position', 'woocommerce_template_single_title', 60);
I am using Woocommerce 2.4.13 and WordPress 4.4.1
Please help me to solve this. It'll be great for me.
Weirdly, you must call remove_action from inside a function.
function so_34845641_move_title(){
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 50);
add_action('woocommerce_moved_product_title_position', 'woocommerce_template_single_title', 60);
}
add_action( 'woocommerce_before_single_product', 'so_34845641_move_title' );
Just a suggestion that there are probably enough hooks without needing to add a custom do_action() in the templates.
Run the remove_action inside a function doesn't change anything , but change the priority work for me.
I give you an example:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 15 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
Pay attention and try with differents priorities.

Removing Composite Product Price on Product Page in WooCommerce

Hoping to get some assistance in removing this "add to cart" button along with the pricing shown here. Documentation on the plugin can be found here as well.
What I currently have to remove pricing within WooCommerce is:
add_filter('woocommerce_get_price_html','members_only_price');
function members_only_price($price){
if(is_user_logged_in() ){
return $price;
} else {
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_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
return 'Only Registered Users are able to view pricing.';
}
}
IIRC this was the original question which I was able to use the code from until we required Composite Products.
The solution to your problem is that you just need to add one more "remove_action" for the composite type of products.
To achieve this you need to remove the action woocommerce_composited_add_to_cart
The trick is that if you search this action you will get to know that this action is added by using class object so you need to remove the same using the same class object.
Tutorials regarding how to remove actions using class object is already on the net which you need to research.
This will surely help you to achieve your solution.

Categories