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 ;
}
Related
How can I add space between shortcode and Contact us page in the header of the theme. I was able to add the shortcode successfully. Now I am unable to add the gap between shortcode and contact us.
Below I have attached the code to this header file. After
do_action( 'ciyashop_header_nav_content' );
I have added echo do_shortcode('[searchandfilter id="2819"]'); thats my shortcode.
<?php do_action( 'ciyashop_before_header_nav' );?>
<div class="<?php ciyashop_header_nav_classes('header-nav');?>">
<div class="header-nav-wrapper">
<?php
/**
* Functions hooked into ciyashop_before_header_nav_content action
*
* #hooked ciyashop_before_header_nav_content_wrapper_start - 10
*/
do_action( 'ciyashop_before_header_nav_content' );
/**
* Functions hooked into ciyashop_header_nav_content action
*
* #hooked ciyashop_category_menu - 10
* #hooked ciyashop_catmenu_primenu_separator - 15
* #hooked ciyashop_primary_menu - 20
*/
do_action( 'ciyashop_header_nav_content' );
/* echo do_shortcode('[searchandfilter id="2819"]'); */ My Shortcode
/**
* Functions hooked into ciyashop_after_header_nav_content action
*
* #hooked ciyashop_after_header_nav_content_wrapper_end - 10
*/
do_action( 'ciyashop_after_header_nav_content' );
?>
</div>
I need to filter the whole webshop in wordpress woocommerce by a tag. So the the webshop should only display the products if the product has a specific tag let's say (visible-shop) or something else. I know there is a visibilty option but thats not what I am looking for.
Please help.
archive-product.php
<?php
/**
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
<
get_header( 'shop' );
/**
* Hook: woocommerce_before_main_content.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
* #hooked WC_Structured_Data::generate_website_data() - 30
*/
do_action( 'woocommerce_before_main_content' );
if ( have_posts() ) {
/**
* Hook: woocommerce_before_shop_loop.
*
* #hooked wc_print_notices - 10
* #hooked woocommerce_result_count - 20
* #hooked woocommerce_catalog_ordering - 30
*/
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*
* #hooked WC_Structured_Data::generate_product_data() - 10
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
}
woocommerce_product_loop_end();
/**
* Hook: woocommerce_after_shop_loop.
*
* #hooked woocommerce_pagination - 10
*/
do_action( 'woocommerce_after_shop_loop' );
} else {
/**
* Hook: woocommerce_no_products_found.
*
* #hooked wc_no_products_found - 10
*/
do_action( 'woocommerce_no_products_found' );
}
/**
* Hook: woocommerce_after_main_content.
*
* #hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
/**
* Hook: woocommerce_sidebar.
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
get_footer( 'shop' );
You need to alter the product query and you can do it this way:
add_action('woocommerce_product_query', 'product_query');
function product_query($q)
{
$q->set('product_tag', 'visible-shop '); //Here you can define which tag you want
}
The code above is tested and working just put it in your functions.php
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.
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'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 );