Is it possible to change the Read More button of a out of stock product to redirect to a specific page/url or popup message instead of going to the single product view.
Whenever I have an out of stock product id like to have a popup message appear saying something in a Lightbox window.
Advertisement
Answer
The code below will change the product button link when product is out of stock on Woocommerce archive pages:
JavaScript
x
add_filter( 'woocommerce_product_add_to_cart_url', 'out_of_stock_read_more_url', 50, 2 );
function out_of_stock_read_more_url( $link, $product ) {
// Only for "Out of stock" products
if( $product->get_stock_status() == 'outofstock' ){
// Here below we change the link
$link = home_url("/custom-page/");
}
return $link;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.