There is this plugin WooCommerce Availability Chart that shows the available stock amount. Maybe this could help to create a code..
Hi newshop!
You’re right!
Please, try to follow the following steps to customize plugin
1. Overwrite default wishlist-view.php template, copying it from wp-content/plugins/yith-woocommerce-wishlist/includes and pasting it under wp-content/themes/<your theme or child folder>/woocommerce/
2. In your brand new template, replace the following code
<?php
if( $stock_status == 'out-of-stock' ) {
$stock_status = "Out";
echo '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>';
} else {
$stock_status = "In";
echo '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>';
}
?>
(lines 189-197) with this code
<?php
if( $product->is_type( 'variable' ) ){
$variations = $product->get_available_variations();
if( ! empty( $variations ) ){
foreach ( $variations as $variation ){
$variation = $product->get_child( $variation['variation_id'] );
echo $variation->get_formatted_variation_attributes();
echo $variation->is_in_stock() ? '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>' : '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>';
}
}
}
elseif( $stock_status == 'out-of-stock' ) {
$stock_status = "Out";
echo '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>';
} else {
$stock_status = "In";
echo '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>';
}
?>
Hope this helps
Have a nice day
Thank you very much! First I thought everything works like a charm but then I noticed that the products in stock are marked as “not in stock” and vice versa. I think I have to switch a part of the code but I dont know how. Could you please help me with that?
Ok, I just switched the two spans and now its correct. Do you agree with my changes?
Yes, of course 🙂
Sorry for the issue 😀
I’m marking this topic as solved
If you enjoy our plugin and our support, please, don’t forget to leave us a 5 star rating, and to consider buying our premium version of wishlist plugin 🙂
Have a nice day
Awesome, thank you so much for the great support, 5star rating will follow!
Hello, I wanted to include the code you gave me in a shortcode and then I wanted to include that shortcode in a form that I created with contact form 7 and contact form 7 dynamic text extension. But it didnt work. The author of contact form 7 dynamic text extension gave me the following advice, but I dont know how to edit the code correctly. Could you please help me with that? Many thanks in advance!
Your shortcode is not coded correctly and you need to fix it. You are echoing your output, not returning it.
All shortcodes must return, not echo.
Your $output variable that you are returning isn’t even defined, so you’re returning null. You need to define it at the beginning of your function, append your strings to that variable, and then return it. Don’t echo anything.
Here is the code I used:
function availability_info() {
global $product;
if( $product->is_type( 'variable' ) ){
$variations = $product->get_available_variations();
if( ! empty( $variations ) ){
foreach ( $variations as $variation ){
$variation = $product->get_child( $variation['variation_id'] );
echo $variation->get_formatted_variation_attributes() . (":") .(" "); echo $variation->is_in_stock() ? ("<span style=color:#00b805;>") . __( 'In Stock', 'yith-woocommerce-wishlist' ). ("</span>") . ("<br />") : ("<span style=color:#cb0000;>") . __( 'Out of Stock', 'yith-woocommerce-wishlist' ). ("</span>") . ("<br />");
}
}
}
elseif( $stock_status == 'out-of-stock' ) {
$stock_status = "Out";
echo __( 'Out of Stock', 'yith-woocommerce-wishlist' );
}
else {
$stock_status = "In";
echo __( 'In Stock', 'yith-woocommerce-wishlist' );
}
return $output;
}
add_shortcode( 'instock', 'availability_info' );
-
This reply was modified 9 years, 4 months ago by
newshop.