• Hi I need change text on button when product is out of stock (0, -1 etc) but enabled for backorder. Not in single product page but in e-shop listing.

    I did not want use plugin if it is not necessarily.

    I tried some codes add in my functions.php but it editig only single product page

    add_filter( 'woocommerce_get_availability', 'custom_get_stock', 1, 2);
    function custom_get_stock( $availability, $_product ) {
    if ( !$_product->is_in_stock() ) $availability['availability'] = __('Backorder', 'woocommerce');
    return $availability;
    }
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'wc_ninja_change_backorder_button', 10, 2 );
    function wc_ninja_change_backorder_button( $text, $product ){
    	if ( $product->is_on_backorder( 1 ) ) {
    		$text = __( 'Pre-Order', 'woocommerce' );
    	}
    	return $text;
    }
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
    
    function woo_custom_cart_button_text() {
        global $product;
        $product->get_stock_quantity();
    
        if( $product == 0 ) {
            return __( 'Backorder', 'woocommerce' );
        } else {
            return __( 'Add to cart ', 'woocommerce' );
        }
    }

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have the same question I’m wanting txt on each product on the products page when inventory is 0 so customers don’t wast time clicking on an item to then find out its out of stock

    Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello there,
    The code is ok but you are using the wrong filter.

    This is the one you want to use: https://github.com/woocommerce/woocommerce/blob/master/templates/loop/add-to-cart.php#L25

    Thread Starter Barbora Kulichova

    (@hilleecz)

    Thanks I used tried first and second code and now using:

    add_filter( 'woocommerce_loop_add_to_cart_link', 'zmena_textu_button_vypis_produktu', 10, 2 );
    function zmena_textu_button_vypis_produktu( $text, $product ){
    	if ( $product->is_on_backorder( 1 ) ) {
    		$text = __( sprintf(
    		'<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
    		esc_url( $product->add_to_cart_url() ),
    		esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
    		esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
    		isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
    		esc_html( 'Objednat' )
    	), 'woocommerce' );
    	}
    	return $text;
    }

    It work on listing but I have text “Objednat” (order) on product with variations when one of variation is out of stock but other are in stock. Is possible solve this?

    Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:

    1. WooCommerce Slack Community: https://woocommerce.com/community-slack/
    2. WooCommerce FB group: https://www.facebook.com/groups/advanced.woocommerce/
    Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Kind regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change add to cart button text in WooCommerce if product is on backorder.’ is closed to new replies.