Crossed line in variables with 0 inventory in WooCommerce

This topic has 5 replies, 3 voices, and was last updated 10 months, 2 weeks ago ago by Luca Rossi

  • Avatar: mahdar
    MAHDAR
    Participant
    January 3, 2024 at 13:38

    Hello good time

    I want to have a cross line on the product page when a size runs out
    Please see the pictures

    Please, contact administrator
    for this information.
    4 Answers
    Avatar: mahdar
    MAHDAR
    Participant
    January 3, 2024 at 13:44

    Annex

    Please contact administrator
    for this information.
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    January 3, 2024 at 14:20

    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

    Avatar: mahdar
    MAHDAR
    Participant
    January 27, 2024 at 10:43

    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?

    Avatar: Justin
    Luca Rossi
    Support staff
    January 28, 2024 at 15:21

    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

  • Viewing 5 results - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.