This topic has 5 replies, 3 voices, and was last updated 10 months, 3 weeks ago ago by Luca Rossi
Hello good time
I want to have a cross line on the product page when a size runs out
Please see the pictures
Annex
Hello, MAHDAR,
Thank you for reaching out to us with your concern.
We kindly request you to activate the “Hide out of stock items from the catalog” option. You can find this option by navigating to WooCommerce > Settings > Products > Inventory.
Kind Regards,
8theme team
add_action( ‘woocommerce_before_shop_loop_item_title’, ‘wk_out_of_stock_variations_loop’ );
function wk_out_of_stock_variations_loop(){
global $product;
if ( $product->product_type == ‘variable’ ) { // if variation product is out of stock
$available = $product->get_available_variations();
if ( $available )foreach ( $available as $instockvar ) {
if ( isset($instockvar[‘attributes’][‘attribute_pa_groesse’] ) ) {
if ( ( $instockvar[‘attributes’][‘attribute_pa_groesse’] == $_GET[‘filter_groesse’] ) && (!$instockvar[‘max_qty’]>0) ) {
global $product;
$id = $product->get_id();
echo “
“;
// echo ‘
OUT OF STOCK
‘;
}
}
}
}
if ( !$product->is_in_stock() ) { // if single product is out of stock
echo ‘
OUT OF STOCK
‘;
}
}
Hello
I use this piece of code and when I enable the “Hide out of stock items from the catalog” option
This code does not work because of the WooCommerce system
Do you have another way to activate the cross line mode on the product variable when the products become unavailable?
Hi @MAHDAR,
Please uncheck the option, then also add the following codes under your functions.php file locates in your child theme:
add_filter('pre_option_woocommerce_hide_out_of_stock_items', 'n2t_woocommerce_hide_out_of_stock_items', 100);
function n2t_woocommerce_hide_out_of_stock_items($value){
if(!is_admin() && is_singular('product')){
return 'yes';
}
return $value;
}
The code above will cross-line the out-of-stock variation products in the product page ONLY.
Kind Regards,
8theme team
You must be logged in to reply to this topic.Log in/Sign up