skip to Main Content

He everyone I would like to change the button “in de winkelmand” to sold-out when the product is sold out.

I have tried to disable the product single like attached below to get rid of that weird looking box.

But now need to change the text

.product .single_variation {
    display: none !important;
}

nm-variable-add-to-cart-button single_add_to_cart_button button alt disabled wc-variation-is-unavailable

Unfortunately without a result, can anyone point me in the right direction?

https://www.peachandhoney.nl/product/bella-rose-top/

is the link to the site. Xs is sold out on this product the rest is in stock.

Thank you.

3

Answers


  1. If I understand your question, you want to change the text? The add to cart text is filterable. Using the filter woocommerce_product_single_add_to_cart_text. This will show the button as long as you allow backorders.

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'dd_custom_single_add_to_cart_text' ); 
    function dd_custom_single_add_to_cart_text(){
        global $product;
        if ($product->get_stock_status() !== 'instock'){
            return __( 'Sold Out', 'woocommerce' );
        } else {
            return __( 'Add to cart', 'woocommerce' );
        }
    }
    
    Login or Signup to reply.
  2. This should work fine. Tested and confirmed.

    function change_loop_add_to_cart_button( $button, $product, $args = array() ) {
        if( !$product->is_in_stock() ){
            $button = '<a class="button disabled" style="cursor:not-allowed;color:#777;background-color:#aaa;">'.__('Sold Out', 'woocommerce').'</a>';
        }
       return $button;
    }
    add_filter( 'woocommerce_loop_add_to_cart_link', 'change_loop_add_to_cart_button', 20, 3 );
    
    Login or Signup to reply.
  3. Want to change “sold Out” text with another text, then this will solve your problem with WooCommerce Way. Please add this code to your theme functions.php. But please don’t forget to use a child theme

    add_filter( 'woocommerce_get_availability_text', 'amc_change_out_of_stock_text', 10, 2 );
    
     function amc_change_out_of_stock_text( $availability, $product ){
    
        if ( ! $product->is_in_stock() ) {
    
            $availability = __( 'in de winkelmand', 'woocommerce' );
    
        }
    
        return $availability;
    
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search