Display product price under the product image - php

In WooCommerce, I would like to display product varation price under image. I am using some code in my functions.php but not working please any help will be appreciated. Thanks
add_action( 'woocommerce_product_thumbnails','woocommerce_single_variation',30 );

For that you need to:
Remove the woocommerce_template_single_price in woocommerce_single_product_summary hook:
/**
* 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
*/
To add it in woocommerce_before_single_product_summary hook:
/**
* woocommerce_before_single_product_summary hook.
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
So your code will be:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_product_thumbnails','woocommerce_template_single_price', 30 );
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.

Related

I am doing remove_action before do_action but action is still fired?

I don't understand why this doesn't work. My understanding is that you must remove the action after it is added but before it is fired. That is what I'm doing here? Is there something here that I'm not understanding? Debugging wordpress really confuses me because you can't really step through it?
<?php
/**
* Functions hooked into storefront_header action
*
* #hooked storefront_header_container - 0
* #hooked storefront_skip_links - 5
* #hooked storefront_social_icons - 10
* #hooked storefront_site_branding - 20
* #hooked storefront_secondary_navigation - 30
* #hooked storefront_product_search - 40
* #hooked storefront_header_container_close - 41
* #hooked storefront_primary_navigation_wrapper - 42
* #hooked storefront_primary_navigation - 50
* #hooked storefront_header_cart - 60
* #hooked storefront_primary_navigation_wrapper_close - 68
*/
remove_action('storefront_header', 'storefront_product_search', 40);
do_action( 'storefront_header' );
?>
Please see the contributed notes from the Wordpress documentation for remove_action:
If an action has been added from within a class, for example by a plugin, removing it will require accessing the class through a variable that holds the class instance.
...
To remove an action, the priority must match the priority with the function that was originally added.

Relocating product link in WooCommerce archives pages

The link I am trying to relocate is the link that wraps each product on the shop page which takes you to that products own page. As it is right now it wraps the image, product name, product sku and price. I only want it to wrap the image and product name.
Here's the code which is creating each product.
<li <?php post_class( $boot_classes ); ?>>
<?php
/**
* woocommerce_before_shop_loop_item hook.
*
* #hooked woocommerce_template_loop_product_link_open - 10
*/
do_action( 'woocommerce_before_shop_loop_item' );
/**
* woocommerce_before_shop_loop_item_title hook.
*
* #hooked woocommerce_show_product_loop_sale_flash - 10
* #hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
/**
* woocommerce_shop_loop_item_title hook.
*
* #hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item_title hook.
*
* #hooked woocommerce_template_loop_rating - 5
* #hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
/**
* woocommerce_after_shop_loop_item hook.
*
* #hooked woocommerce_template_loop_product_link_close - 5
* #hooked woocommerce_template_loop_add_to_cart - 10
*/
do_action( 'woocommerce_after_shop_loop_item' );
?>
</li>
How is this possible?
You can change the location of the product link close as you expect, this way:
add_action('init', 'change_location_of_loop_product_link_close' );
function change_location_of_loop_product_link_close(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
add_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20 );
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works.

How to remove title from woocommerce_single_product_summary hook?

On my product template, I execute this action :
<?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');
?>
What I want is do remove the woocommerce_template_single_title hook so in my functions.php file I wrote this code :
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 1);
But it does not work and I don't know how.
Thanks for your help
!! EDIT !!
Nevermind I solved it by writing this:
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
The priority have to match
The author has added the one-liner to his question; as suggested by #Bugs, here it is as an answer.
// Remove title hook Woocommerce
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);

Edit product hook WooCommerce

On my product template, I execute this action :
<?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');
?>
What I want is to edit woocommerce_template_single_excerpt so I wrote this code in functions.php :
add_action('woocommerce_template_single_excerpt', 'woocommerce_custom_single_excerpt', 20);
function woocommerce_custom_single_excerpt() {
global $post;
echo '<p class="product-description">';
echo $post->post_excerpt;
echo '</p>';
}
But it does not override at all.
Thanks for your help!
Please try this code snippet.
add_action('woocommerce_single_product_summary', 'woocommerce_custom_single_excerpt', 15);
function woocommerce_custom_single_excerpt() {
global $post;
echo '<p class="product-description">';
echo "hello";
echo '</p>';
}

Sample Product, change location of Price | Wordpress Woocommerce

I am trying to change the location of Price of all sample Products from the current location, which is below the title to just about "add to cart".
If i do it with CSS, that is affecting the responsiveness of the website.
i want to make this change on a PHP, so that it can impact all the SAMPLE products which i upload now on..
can i make any changes on the PHP so that the "SAMPLE Product" Price always shows up just above "add to cart" ?
at present:
what i need is:
the code in content-single-product.php
<div class="single clearfix row-fluid">
<div class="wrap span6 product-left">
<?php
/**
* woocommerce_show_product_images hook
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
</div>
<div class="span6">
<div class="product-detail">
<?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' );
//echo do_shortcode("[yith_wcwl_add_to_wishlist]");
?>
</div>
</div>
</div>
In the below code, you are overwriting the WooCommerce hook inclusion/priority order. So the price will be included after woocommerce_template_single_excerpt which has a priority value of 20
Include the following code in functions.php.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
WooCommerce displays the price between the product title and product description on the single product page by default.
If you’d like to move the price after the content, you can do so easily by adding the following hook to your theme’s functions.php file:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
By changing the number from 10 to 25, you move the price below the single excerpt (which has a priority of 20).
The WooCommerce templates/content-single-product.php file shows the hook priorities for the single product loop.
Here you can get WooCommerce Action and Filter Hook
-https://docs.woothemes.com/wc-apidocs/hook-docs.html

Categories