Default product short description - wordpress

On my woocommerce site I want to add the text "Only available in stores" to all my product's short description, and also have that same text be default for all future products I add.
I had a search but the solutions seemed way to complex for me. Is there some code I can paste in the functions.php?
Thanks!

You can solve this problem easily. You need to some code push to theme functions.php or use code snippets plugin. This code only works when the WooCommerce product short description is empty.
function wp_woocommerce_short_description_if_empty(){
global $post;
if (empty($post->post_excerpt)) {
$post_excerpt = '<p class="default-short-desc">';
$post_excerpt .= 'Your Custom Message Here.';
$post_excerpt .= '</p>';
echo $post_excerpt;
}
}
add_action('woocommerce_single_product_summary', 'wp_woocommerce_short_description_if_empty', 21);

You can also try this for your default product description, you can Add Custom Text before/after the Product Short Description
add_filter( 'woocommerce_short_description', 'woo_add_text_after_excerpt_single_product', 20, 1 );
function woo_add_text_after_excerpt_single_product( $post_excerpt ){
/* Method 1: Add Custom Text before the Product Short Description on product page */
/* $content= '<ul class="fancy-bullet-points red">
<li>'.__('Only available in stores').'</li>
</ul>';
return $content.'<br>'.$post_excerpt;
*/
/* Method 2: Add Custom Text after the Product Short Description on product page */
$post_excerpt .= '<ul class="fancy-bullet-points red">
<li>'.__('Only available in stores').'</li>
</ul>';
return $post_excerpt;
}
Note: Add Custom Text before the Product Short Description on the product page - code is commented so you can uncomment accordingly.

Related

Hide Short Description on hover on Product Archive Page - Woocommerce

I'm building a product catalog website using woocommerce. Everything is fine but Product short description is showing on product snippet hover on Archive page and it's not responsive. I have included the screenshot below.
How can I hide 'short description' on product hover on Archive page? It's showing when I hover on any part of product snippet. thanks!
enter image description here
I tried this code to add short description below product title:
`function webroom_add_short_description_in_product_categories() {
global $product;
$limit = 10;
if ( ! $product->get_short_description() ) return;
?>
<div itemprop="description">
<?php echo apply_filters( 'woocommerce_short_description', $product->get_short_description() ) ?>
</div>
<?php
}
add_action('woocommerce_after_shop_loop_item', 'webroom_add_short_description_in_product_categories', 5);
function remove_image_zoom_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
add_action('wp', 'remove_image_zoom_support', 100);
`
And, it's working fine. But it's also showing on product image when I hover. How can I hide it. thanks!

Woocommerce hook: How to add content inside the feature products on home page?

I'm trying to add the custom message inside the woocommerce website "Featured Product" section.
Like content goes inside the red box:
I've found the hook like below but it does not have any effect:
add_action('storefront_homepage_after_featured_products_title','homepage',15);
function homepage() {
echo "test";
}
I also try below code but that only display message under catalogue page.
add_action( 'woocommerce_after_shop_loop_item', 'catalogue_message', 15);
function catalogue_message() {
global $product;
$item_cost = $product->get_price();
if($item_cost != '') {
echo "TEST";
}
}
So not sure what's the name of woocommerce hook that can add the custom message on home page - Featured Product section.
Can anyone please let me know the name of the hook.
Thanks:)
Try this code to add html after price in featured product.
add_filter( 'woocommerce_get_price_html', 'theme_add_description_after_or_after_price', 2, 10 );
function theme_add_description_after_or_after_price($price, $product){
$description = ($product->is_featured()) ? 'Your HTML or text' : '';
return $price . $description ;
}

Add short description under the product title in WooCommerce archive pages

My site is https://outlet.ltd/deals. I tried to add a short description of the WooCommerce product to the achieve page grid (under product title) by following links but was not successful. Nothing shows up.
Add shortened description under the product title in WooCommerce archive pages
Adding A Short Description To Product Archives
I'm using REHub theme. Could anyone help?
You can do it with woocommerce_after_shop_loop_item_title hook
add_action('woocommerce_after_shop_loop_item_title','my_product_description');
function my_product_description() {
// get the global product obj
global $product;
// get the global product obj
$description = $product->get_short_description();
echo $description;
}
Add this code on your theme functions.php file.
// define the woocommerce_after_shop_loop_item_title callback
function action_woocommerce_after_shop_loop_item_title( ) {
global $product;
if( is_shop() ):
echo $product->get_short_description();
endif;
};
// add the action
add_action( 'woocommerce_after_shop_loop_item_title', 'action_woocommerce_after_shop_loop_item_title', 5 );
it works for me.

Wordpress custom button link output after the_content

I'm trying to insert a button to show at the end of each post on Wordpress in which the link it goes to is defined by a setup using the custom fields plugin. When creating each post, I am able to select the link I wish to display.
Here is the code I have which I know is wrong but I was hoping someone could help here.
function wpb_after_post_content($content){
if (is_single()) {
$content .= 'Contact Franchise →';
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
I assume $franchise_profile_url is a variable and you should concatenate it in the string like this
$content .= 'Contact Franchise →';
function afterContent($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='footNote'>";
$content.= "<h4>Click the below button if you like it:</h4>";
$content.= "<p><a href='#'>LIKE</a></p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'afterContent');
Use the above function. It will help you to achieve what you need.
Thanks for the help here, however, that code simply links back to the post itself and isn't pulling in the URL as set on the post using custom fields. This is the code I had set up before which was working on a default post setup but now I wish to use an alternative method in the functions.php file
<?php if( get_field('franchise_profile_url') ): ?>
Contact Franchise →
<?php endif; ?>

Disable WooCommerce SKU on Product Page

I have a WooCommerce store and I don't want to display the SKU on any single product page. Looking at their code, I found this filter:
/**
* Returns whether or not SKUS are enabled.
* #return bool
*/
function wc_product_sku_enabled() {
return apply_filters( 'wc_product_sku_enabled', true );
}
and I attempted to override it with this line of code I placed in a custom plugin:
apply_filters( 'wc_product_sku_enabled', false );
I also tried placing the apply_filter inside an action function for woocommerce_product_meta_start which fires right before but it still renders the SKU on the product page. Any ideas?
I think you shoul try with this:
add_filter( 'wc_product_sku_enabled', '__return_false' );
That will remove sku from all woo, back and front end. You can always hide it just by CSS if need it on admin.
The easiest way is with CSS:
.sku_wrapper {
display:none;
}
A more robust approach is to recreate the woocommerce template woocommerce/templates/single-product/meta.php in your own theme and simply comment out the line:
<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span>.</span>
To recreate a woocommerce template in your own theme, see:
http://docs.woothemes.com/document/template-structure/
Hiding the SKU/UGS by using cSS is not an efficient solution because it will be still part of the HTML code.
In order to hide it from the product single page and keep it in the admin page, you have to add this code in the child (or parent if you don’t have the child) functions.php :
// Remove the Product SKU from Product Single Page
add_filter( 'wc_product_sku_enabled', 'woocustomizer_remove_product_sku' );
function woocustomizer_remove_product_sku( $sku ) {
// Remove only if NOT admin and is product single page
if ( ! is_admin() && is_product() ) {
return false;
}
return $sku;
}
Make sure also in the product php page (it can have a different name depending on the theme you use) to have this condition to show the SKU in the product single page:
if (wc_product_sku_enabled() && $product->get_sku()) { // HTML code that shows the SKU in the product single page}
Make Sure to remove it from the frontend only by using this code on function.php usually you can edit the function file on theme editor
add_filter( 'wc_product_sku_enabled', 'my_remove_sku', 10 );
function my_remove_sku( $return, $product ) {
if ( !is_admin() && is_product() ) {
return false;
} else {
return true;
}
}
If you don’t need to use SKUs at all in your shop, you can disable them completely by using this plugin. simply install this plugin. https://wordpress.org/plugins/woocommerce-remove-sku/

Resources