Change add to cart button text in WooCommerce if product is on backorder.
-
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)
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.