Tagged: hide price
-
AuthorPosts
-
January 25, 2017 at 10:20 pm #738620
How do I hide the price of a sold item, and have it displayed as sold throughout the site.
Right now, it only lists as sold when you click on the item, not on the main page for the Shop.
This is what I have in my Enfold Child functions.php:
}
add_filter( “woocommerce_variable_sale_price_html”, “theanand_remove_prices”, 10, 2 );
add_filter( “woocommerce_variable_price_html”, “theanand_remove_prices”, 10, 2 );
add_filter( “woocommerce_get_price_html”, “theanand_remove_prices”, 10, 2 );function theanand_remove_prices( $price, $product ) {
if ( ! $product->is_in_stock()) {
$price = “”;
}
return $price;
}January 30, 2017 at 3:59 pm #740239Hey!
Please add following code to Functions.php file in Appearance > Editor
add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 ); //create our function function wcs_stock_text_shop_page() { //returns an array with 2 items availability and class for CSS global $product; $availability = $product->get_availability(); //check if availability in the array = string 'Out of Stock' //if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock' if ( $availability['availability'] == 'Out of stock') { echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] ); } }
Best regards,
YigitJanuary 30, 2017 at 6:46 pm #740347Thanks Yigt, I really appreciate your help.
When I add your code to functions.php, I run into this error:
Parse error: syntax error, unexpected ‘&’ in /lareventeart.com/wp-content/themes/enfold-child/functions.php on line 24
January 31, 2017 at 3:38 pm #740691Hi,
Please copy the code from our forum. It does work fine on my end. If that too does not help, please post FTP and WP admin logins here privately.
Best regards,
YigitJanuary 31, 2017 at 6:58 pm #740824It worked this time – thanks.
The only problem is that the price appears when item is “Out of stock”- on catalogue view and product view.
And the change only appears in English. I also have French (as the primary language) through WPML.
It would be nice to include this change as well:
add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);
function custom_get_availability( $availability, $_product ) {
//change text “In Stock’ to ‘Available’
if ( $_product->is_in_stock() ) $availability[‘availability’] = __(‘Available’, ‘woocommerce’);//change text “Out of Stock’ to ‘SOLD OUT’
if ( !$_product->is_in_stock() ) $availability[‘availability’] = __(‘Sold’, ‘woocommerce’);
return $availability;
}January 31, 2017 at 10:15 pm #740903Hey!
Thanks a lot for the suggestion!
We will do ask Kriesi, although it is something that as seems, it is better to be as an extra function.
Let us know if we can do anything else to assist you further.Thanks a lot
Best regards,
BasilisJanuary 31, 2017 at 10:31 pm #740906Hi Basilis,
Is there any way to display sold on the French side as well?
And to remove the price when sold?
Thanks!
February 6, 2017 at 5:06 am #743118Hi,
Do you want to translate the “Sold” text to french? If you do, you can use the following plugin.
// https://wordpress.org/plugins/say-what/
Please provide a link to a product without stock on the French version.
Best regards,
IsmaelFebruary 6, 2017 at 2:07 pm #743364Thanks Ismael, I already modified the WMPL String Translation so I don’t think I need this plugin now.
The remaining issue is the “Out of Stock” message only appears on the English catalog page: https://www.lareventeart.com/en/
And the price is still listed when sold. I would like that to be removed in the event of a sale.
The out of stock message does not appear at all on the French catalog page: https://www.lareventeart.com/
Same issue with the price showing.
February 7, 2017 at 9:54 am #743767Hey!
Did you translate these products? Did you set the Stock status after the “duplication” or “translation” process? Please post the login details here and we’ll check the settings.
Cheers!
IsmaelFebruary 7, 2017 at 2:27 pm #743916Yes, all products are translated and some are listed as sold (example: Dil Hildebrand, painting).
I appreciate you taking a look!
February 9, 2017 at 3:54 am #744583Hi!
Thank you for the info. We modified the code in the functions.php file. Please remove browser cache before checking the page.
add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 ); function wcs_stock_text_shop_page() { global $product; $availability = $product->get_availability(); if (!empty($availability['availability'])) { echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] ); } }
Regards,
IsmaelFebruary 9, 2017 at 2:37 pm #744823Is there a way to hide price when the product is sold?
When I remove the price manually, it does not show as a sold item..
Thanks for your help!
February 9, 2017 at 2:39 pm #744824And this little tweak does not work anymore, maybe there is a conflict?
}
add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);
function custom_get_availability( $availability, $_product ) {
//change text “In Stock’ to ‘Available’
if ( $_product->is_in_stock() ) $availability[‘availability’] = __(‘Available’, ‘woocommerce’);//change text “Out of Stock’ to ‘Sold’
if ( !$_product->is_in_stock() ) $availability[‘availability’] = __(‘Sold’, ‘woocommerce’);
return $availability;
}February 10, 2017 at 8:50 am #745258Hi!
The “out of stock” and “vendu” text are displaying when I checked both languages.
// https://www.lareventeart.com/en/
// https://www.lareventeart.com/If you want to remove the price on “out of stock” products, please add this in the Quick CSS field.
.outofstock .price { display: none !important; }
Cheers!
IsmaelFebruary 10, 2017 at 3:16 pm #745442I hoping to change the text ‘Out Of Stock’ to ‘Sold’.
It’s artwork, so out of stock makes it sound like a mass produced product.
Everything else worked like a charm!
February 11, 2017 at 7:31 am #745705Hi!
Thank you for the update.
We modified the filters a bit. Please remove browser cache before checking the page.
Best regards,
IsmaelFebruary 11, 2017 at 3:14 pm #745766Awesome, thanks so much Ismael – you’re the best!
February 13, 2017 at 5:16 am #746099 -
AuthorPosts
- The topic ‘Woocommerce Hide price, mark sold throughout website’ is closed to new replies.