mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://www.dimeforum.com/threads/how-to-change-woocommerce-out-of-stock-read-more-button-text.383/
24 lines
904 B
Text
24 lines
904 B
Text
add_filter( 'woocommerce_product_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
|
|
add_filter( 'woocommerce_product_single_add_to_cart_text', 'customizing_add_to_cart_button_text', 10, 2 );
|
|
/**
|
|
* Replace read more buttons for out of stock items
|
|
*
|
|
* @param button $button_text comment.
|
|
* @param product $product comment.
|
|
* @return return $button_text.
|
|
*/
|
|
function customizing_add_to_cart_button_text( $button_text, $product ) {
|
|
global $product;
|
|
$sold_out = __( 'Add to Cart', 'woocommerce' );
|
|
$availability = $product->get_availability();
|
|
$stock_status = $availability['class'];
|
|
// For all other cases (not a variable product on single product pages).
|
|
if ( ! $product->is_type( 'variable' ) && ! is_product() ) {
|
|
if ( 'out-of-stock' === $stock_status ) {
|
|
$button_text = $sold_out;
|
|
}
|
|
} else {
|
|
$button_text;
|
|
}
|
|
return $button_text;
|
|
}
|