I am trying to remove a page title from the top of Product page of my WooCommerce theme. (WooTheme's Homestore) to the right-hand side. I have managed to add the right-hand side page where I would like it but now need to remove the main page title.
I added the right-hand side page title like this in the functions.php
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
Here is a bit of the content-single-product.php template:
<?php
/**
* Hook: woocommerce_before_single_product_summary.
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
<div class="summary entry-summary">
<?php
/**
* Hook: woocommerce_single_product_summary.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
* #hooked WC_Structured_Data::generate_product_data() - 60
*/
do_action( 'woocommerce_single_product_summary' );
?>
</div>
So where I'm confused is, how do I remove the page title when it's not even appearing within the tag?
The page title appears above the images at the moment and that's the title I'd like to remove using a hook or filter in my functions.php file.
To remove title for single product page. you can add this hook in content-single-product.php. just before the do_action.
//remove product title only
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
As you are saying "The page title appears above the images". You can change it in theme css or theme woocommerce file. Anyway
All functions in the below list are binded in woocommerce_single_product_summary .
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', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
It is highly recommend, first you need to copy all the files and folder from your woocommerce plugin's folder -> woocommerce/templates folder to woocommerce folder in child-theme's folder yourtheme/woocommerce.
Now open the content-single-product.php file and paste this line of code just like as I did.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
/**
* Hook: woocommerce_single_product_summary.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
* #hooked WC_Structured_Data::generate_product_data() - 60
*/
do_action( 'woocommerce_single_product_summary' );
This way, you will remove the title on product page.
Related
I am a beginner at PHP but I have basic in web development,
I have the following code at content-single-product.php
<?php
/**
* Hook: woocommerce_single_product_summary.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
* #hooked WC_Structured_Data::generate_product_data() - 60
*/
do_action( 'woocommerce_single_product_summary' );
?>
and when I am trying to add a new action to Hook in the single product page
I customized this section to be as the following
<?php
/**
* Hook: woocommerce_single_product_summary.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 20
* #hooked woocommerce_template_single_add_to_cart - 30
* #hooked woocommerce_template_single_meta - 40
* #hooked woocommerce_template_single_sharing - 50
* #hooked WC_Structured_Data::generate_product_data() - 60
*/
function carzyFunction(){
echo'<h1>crazy statement</h1>';
}
add_action( 'woocommerce_single_product_summary', 'carzyFunction', 15 );
do_action( 'woocommerce_single_product_summary' );
?>
what I can't understand is that, although assign the carzyFunction() priority of 15, it appears at the end of the single product summary section,
why it didn't show up between price section and product description section
add_filter( 'woocommerce_get_price_html', 'njengah_text_after_price' );
function njengah_text_after_price($price){
$text_to_add_after_price = echo'<h1>crazy statement</h1>';;
return $price .'<br>'. $text_to_add_after_price ;
}
I am creating a bundled product in WOO Commerce using YITH Plugin. How to change the position of Price?
Add the following code to functions.php of your theme,
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
try by changing the value 25 which indicates the priority of the hook.The priorities are in the order
#hooked woocommerce_template_single_title – 5
#hooked woocommerce_template_single_price – 10
#hooked woocommerce_template_single_excerpt – 20
#hooked woocommerce_template_single_add_to_cart – 30
#hooked woocommerce_template_single_meta – 40
#hooked woocommerce_template_single_sharing – 50
I want to add a cart button and quantity before content. I am using this hook but not working
add_action('woocommerce_before_main_content',
'woocommerce_template_single_add_to_cart', 30);
if i want add to cart button under image use this hook
add_action( 'woocommerce_product_thumbnails',
'woocommerce_template_single_add_to_cart', 30 );
give me the following error
Cannot redeclare print_attribute_radio() (previously declared in /opt/lampp/htdocs/lifeformchairs.com/wp-content/plugins/wc-variations-radio-buttons-master/templates/single-product/add-to-cart/variable.php:17) in /opt/lampp/htdocs/lifeformchairs.com/wp-content/plugins/wc-variations-radio-buttons-master/templates/single-product/add-to-cart/variable.php on line 26
Add-to-cart action is executed inside content-single-product.php like this:
<?php
/**
* woocommerce_single_product_summary hook
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 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' );
?>
here the number describes priority of particular action executed.
you can change this priority by removing it and adding it like this in function.php file of your theme:
/** woocommerce: change position of add-to-cart on single product **/
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', 9 );
Add-to-cart Button now should show after title and before price as its priority is 9.
Code Reference
I am trying to re-position the Woocommerce message
"X Product" HAS BEEN ADDED TO YOUR CART.
But with no success. I tried with the hooks like these
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
add_action( 'woocommerce_before_single_product_summary', 'wc_print_notices', 10 );
The above did not work at all.
Any suggestion will be appreciated.
Edit
I also tried to call the template tag directly in the content-single-product.php file somewhere at the bottom like this
<?php wc_print_notices(); ?>
Still no message shows at the desired place.
<div class="summary entry-summary">
<?php
/**
* woocommerce_single_product_summary hook.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 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' );
?>
</div><!-- .summary -->
<php wc_print_notices();?>
To remove it you could just hide it with CSS:
.woocommerce-message, .woocommerce-info { display:none; }
Or to reposition:
//Remove Message:
remove_action( 'woocommerce_before_single_product', 'woocommerce_show_messages' );
//Show message call this function where you want the message displayed
woocommerce_show_messages();
//Might be a very late but to people looking still you could try these.
remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
add_action('woocommerce_before_single_product','your_function_name');
function your_function_name(){
//your code here
}
//Here is the template that returns the output notices
//if you want to include in the banner as well
<div class="woocommerce-notices-wrapper">
<?php wc_print_notices(); ?>
</div>
I'm trying to change the layout of woocommerce single product page.
Just want to change the title, excerpt and add to cart button position. ( title and excerpt before the image, button below the image ).
What I have now
What I'm looking for
The layout of the page is decided in woocommerce with templates and with the WordPress actions within the templates. You will probably have to use a combination of css, removing and adding actions and changing the template.
The templates are located in wp-content/plugins/woocommerce/templates/. The most important template for your situation is content-single-product.php. These templates can be overwritten in the theme by placing your own template files with the same name in wp-content/themes/yourtheme/woocommerce. I'd recommend the following:
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
Then
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_excerpt', 15 );
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
In addition to that in the custom template you make in your theme, you wrap do_action( 'woocommerce_before_single_product_summary' ); in it's own div. You float this div left and give it the same grey background. This div contains anything outputted at the woocommerce_before_single_product_summary action. The div with class image you may need to stop that from floating left.
From the outside that's about as specific as we can get.
EDIT: Here's the content-single-product.php file with div of class before-single-product-summary added to wrap the action.
<?php
/**
* The template for displaying product content in the single-product.php template
*
* Override this template by copying it to yourtheme/woocommerce/content-single-product.php
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php
/**
* woocommerce_before_single_product hook
*
* #hooked wc_print_notices - 10
*/
do_action( 'woocommerce_before_single_product' );
if ( post_password_required() ) {
echo get_the_password_form();
return;
}
?>
<div itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="before-single-product-summary">
<?php
/**
* woocommerce_before_single_product_summary hook
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
</div>
<div class="summary entry-summary">
<?php
/**
* woocommerce_single_product_summary hook
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 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' );
?>
</div><!-- .summary -->
<?php
/**
* woocommerce_after_single_product_summary hook
*
* #hooked woocommerce_output_product_data_tabs - 10
* #hooked woocommerce_upsell_display - 15
* #hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
<meta itemprop="url" content="<?php the_permalink(); ?>" />
</div><!-- #product-<?php the_ID(); ?> -->
<?php do_action( 'woocommerce_after_single_product' ); ?>
Then you add this css:
.before-single-product-summary{
float: left;
background: #3c3f4e;
}
.product .images{
float: none;
}
I can't guarantee this modification will fix your problem but it will start you down the right track.
We need to look at the content-single-product.php template file. Here are the two sections we we need to look at in that file:
Located: plugins/woocommerce/templates/content-single-product.php
<?php
/**
* woocommerce_before_single_product_summary hook.
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
<div class="summary entry-summary">
<?php
/**
* woocommerce_single_product_summary hook.
*
* #hooked woocommerce_template_single_title - 5
* #hooked woocommerce_template_single_rating - 10
* #hooked woocommerce_template_single_price - 10
* #hooked woocommerce_template_single_excerpt - 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' );
?>
</div><!-- .summary -->
The two action we can see here -
The first action that is for product image is -
1] woocommerce_before_single_product_summary
The second action outputs the product title is -
2] woocommerce_single_product_summary
Let’s pull the title out of the summary block and place it in the block that precedes it so the product title is above the product images.
Step 1: Remove action from woocommerce_single_product_summary -
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
Step 2 : Add action into woocommerce_before_single_product_summary -
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_title', 5 );