Add a custom text under featured products price in Woocommerce product widget
I am trying to add a line of text under the price of my featured products on my homepage.
I have tried editing the content-widget-product.php so it looks like this -
if ( ! defined( 'ABSPATH' ) )
exit;
global $product;
if ( ! is_a( $product, 'WC_Product' ) )
return;
?>
<li>
<?php do_action( 'woocommerce_widget_product_item_start', $args ); ?>
<a href="<?php echo esc_url( $product->get_permalink() ); ?>">
<?php echo wp_kses_post( $product->get_image() ); ?>
<span class="product-title"><?php echo esc_html( $product->get_name() ); ?></span>
</a>
<?php if ( ! empty( $show_rating ) ) : ?>
<?php echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>
<?php endif; ?>
<?php echo wp_kses_post( $product->get_price_html() ); ?>
<p class="deliveryline">DELIVERY THROUGHOUT GREATER CAPE TOWN AREA</p>
<?php do_action( 'woocommerce_widget_product_item_end', $args ); ?>
</li>
I added the "Delivery throughout line"... but it doesn't do anything though. Can someone please tell me why it's not working. Thanks!
php wordpress woocommerce widget product
add a comment |
I am trying to add a line of text under the price of my featured products on my homepage.
I have tried editing the content-widget-product.php so it looks like this -
if ( ! defined( 'ABSPATH' ) )
exit;
global $product;
if ( ! is_a( $product, 'WC_Product' ) )
return;
?>
<li>
<?php do_action( 'woocommerce_widget_product_item_start', $args ); ?>
<a href="<?php echo esc_url( $product->get_permalink() ); ?>">
<?php echo wp_kses_post( $product->get_image() ); ?>
<span class="product-title"><?php echo esc_html( $product->get_name() ); ?></span>
</a>
<?php if ( ! empty( $show_rating ) ) : ?>
<?php echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>
<?php endif; ?>
<?php echo wp_kses_post( $product->get_price_html() ); ?>
<p class="deliveryline">DELIVERY THROUGHOUT GREATER CAPE TOWN AREA</p>
<?php do_action( 'woocommerce_widget_product_item_end', $args ); ?>
</li>
I added the "Delivery throughout line"... but it doesn't do anything though. Can someone please tell me why it's not working. Thanks!
php wordpress woocommerce widget product
add a comment |
I am trying to add a line of text under the price of my featured products on my homepage.
I have tried editing the content-widget-product.php so it looks like this -
if ( ! defined( 'ABSPATH' ) )
exit;
global $product;
if ( ! is_a( $product, 'WC_Product' ) )
return;
?>
<li>
<?php do_action( 'woocommerce_widget_product_item_start', $args ); ?>
<a href="<?php echo esc_url( $product->get_permalink() ); ?>">
<?php echo wp_kses_post( $product->get_image() ); ?>
<span class="product-title"><?php echo esc_html( $product->get_name() ); ?></span>
</a>
<?php if ( ! empty( $show_rating ) ) : ?>
<?php echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>
<?php endif; ?>
<?php echo wp_kses_post( $product->get_price_html() ); ?>
<p class="deliveryline">DELIVERY THROUGHOUT GREATER CAPE TOWN AREA</p>
<?php do_action( 'woocommerce_widget_product_item_end', $args ); ?>
</li>
I added the "Delivery throughout line"... but it doesn't do anything though. Can someone please tell me why it's not working. Thanks!
php wordpress woocommerce widget product
I am trying to add a line of text under the price of my featured products on my homepage.
I have tried editing the content-widget-product.php so it looks like this -
if ( ! defined( 'ABSPATH' ) )
exit;
global $product;
if ( ! is_a( $product, 'WC_Product' ) )
return;
?>
<li>
<?php do_action( 'woocommerce_widget_product_item_start', $args ); ?>
<a href="<?php echo esc_url( $product->get_permalink() ); ?>">
<?php echo wp_kses_post( $product->get_image() ); ?>
<span class="product-title"><?php echo esc_html( $product->get_name() ); ?></span>
</a>
<?php if ( ! empty( $show_rating ) ) : ?>
<?php echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>
<?php endif; ?>
<?php echo wp_kses_post( $product->get_price_html() ); ?>
<p class="deliveryline">DELIVERY THROUGHOUT GREATER CAPE TOWN AREA</p>
<?php do_action( 'woocommerce_widget_product_item_end', $args ); ?>
</li>
I added the "Delivery throughout line"... but it doesn't do anything though. Can someone please tell me why it's not working. Thanks!
php wordpress woocommerce widget product
php wordpress woocommerce widget product
edited Nov 12 '18 at 11:01
LoicTheAztec
85.5k136095
85.5k136095
asked Nov 12 '18 at 8:05
MichelleMichelle
597
597
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try the following code that will add your custom text to the widget Products items for featured products only under the price in the home page:
add_action( 'woocommerce_widget_product_item_end', 'home_widget_features_products', 10, 1 );
function home_widget_features_products( $args )
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
Addition: If you use a shortcode in your home page like for example:
[products limit="3" columns="3" visibility="featured"]
You will use the following code (that works for products in the loop):
add_action( 'woocommerce_after_shop_loop_item_title', 'home_loop_features_products', 20 );
function home_loop_features_products()
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
To display this custom text everywhere for all products (in all Woocommerce archive pages as shop and in all Woocommerce loops as related products, upsells, cross-sells…)
You will use the same code without the if statement:
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258008%2fadd-a-custom-text-under-featured-products-price-in-woocommerce-product-widget%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try the following code that will add your custom text to the widget Products items for featured products only under the price in the home page:
add_action( 'woocommerce_widget_product_item_end', 'home_widget_features_products', 10, 1 );
function home_widget_features_products( $args )
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
Addition: If you use a shortcode in your home page like for example:
[products limit="3" columns="3" visibility="featured"]
You will use the following code (that works for products in the loop):
add_action( 'woocommerce_after_shop_loop_item_title', 'home_loop_features_products', 20 );
function home_loop_features_products()
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
To display this custom text everywhere for all products (in all Woocommerce archive pages as shop and in all Woocommerce loops as related products, upsells, cross-sells…)
You will use the same code without the if statement:
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
|
show 3 more comments
Try the following code that will add your custom text to the widget Products items for featured products only under the price in the home page:
add_action( 'woocommerce_widget_product_item_end', 'home_widget_features_products', 10, 1 );
function home_widget_features_products( $args )
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
Addition: If you use a shortcode in your home page like for example:
[products limit="3" columns="3" visibility="featured"]
You will use the following code (that works for products in the loop):
add_action( 'woocommerce_after_shop_loop_item_title', 'home_loop_features_products', 20 );
function home_loop_features_products()
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
To display this custom text everywhere for all products (in all Woocommerce archive pages as shop and in all Woocommerce loops as related products, upsells, cross-sells…)
You will use the same code without the if statement:
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
|
show 3 more comments
Try the following code that will add your custom text to the widget Products items for featured products only under the price in the home page:
add_action( 'woocommerce_widget_product_item_end', 'home_widget_features_products', 10, 1 );
function home_widget_features_products( $args )
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
Addition: If you use a shortcode in your home page like for example:
[products limit="3" columns="3" visibility="featured"]
You will use the following code (that works for products in the loop):
add_action( 'woocommerce_after_shop_loop_item_title', 'home_loop_features_products', 20 );
function home_loop_features_products()
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
To display this custom text everywhere for all products (in all Woocommerce archive pages as shop and in all Woocommerce loops as related products, upsells, cross-sells…)
You will use the same code without the if statement:
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Try the following code that will add your custom text to the widget Products items for featured products only under the price in the home page:
add_action( 'woocommerce_widget_product_item_end', 'home_widget_features_products', 10, 1 );
function home_widget_features_products( $args )
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
Addition: If you use a shortcode in your home page like for example:
[products limit="3" columns="3" visibility="featured"]
You will use the following code (that works for products in the loop):
add_action( 'woocommerce_after_shop_loop_item_title', 'home_loop_features_products', 20 );
function home_loop_features_products()
global $product;
// Featured product on home page (when using the loop)
if( $product->is_featured() && is_front_page() )
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
Code goes in function.php file of your active child theme (active theme). Tested and works.
To display this custom text everywhere for all products (in all Woocommerce archive pages as shop and in all Woocommerce loops as related products, upsells, cross-sells…)
You will use the same code without the if statement:
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;
echo '<p class="deliveryline">' . __("DELIVERY THROUGHOUT GREATER CAPE TOWN AREA", "woocommerce") . '</p>';
edited Nov 12 '18 at 12:20
answered Nov 12 '18 at 11:01
LoicTheAztecLoicTheAztec
85.5k136095
85.5k136095
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
|
show 3 more comments
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
oh great... Thanks!! i left the content-widget-product.php the way it was above... and pasted this into my function.php page, but it doesn't work :( am i doing something wrong? the url is flowersforeveryone.feedmybeta.com
– Michelle
Nov 12 '18 at 11:08
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
@Michelle On your link it doesn't seem that you are using any Product widget on your home page, but a text widget with a shortcode maybe. So you should try my 2nd code instead that works on any products loop (even shortcode or others). My code target only the home page (just as you need). If it doesn't work, Try to show us a screen shot of the related widget settings.
– LoicTheAztec
Nov 12 '18 at 11:16
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
ohh it works! Thank you!! What if i want this text on every page the product is located... e.g the home page and the category pages? Also, is there a way to get the text just underneath the price? Thanks
– Michelle
Nov 12 '18 at 11:54
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
@Michelle So you want that on all pages like archives (shop, product category pages), related products, upsells, cross-sells? But only for featured products? or for all products?
– LoicTheAztec
Nov 12 '18 at 12:01
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
yes please.. everywhere the product is displayed with the title, star rating and price like that and for all products.
– Michelle
Nov 12 '18 at 12:03
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258008%2fadd-a-custom-text-under-featured-products-price-in-woocommerce-product-widget%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown