Support » Theme: GeneratePress » Change add to cart button text in WooCommerce if product is on backorder. genera

  • 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' );
        }
    }
Viewing 1 replies (of 1 total)
  • Leo

    (@leohsiang)

    Hi there,

    This is something you will need to check with WooCommerce support unfortunately.

    The free theme doesn’t add/modify anything within WooCommerce.

    If WooCommerce support can help you with the code that works in a twenty series default WordPress theme, it would work in GP as well 🙂

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