简体   繁体   English

更改缺货 Woocommerce 产品上的“阅读更多”按钮链接

[英]Change “Read More” button link on Out of stock Woocommerce products

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.每当我有一个缺货的产品 ID 时,我都喜欢在 Lightbox 窗口中显示一条弹出消息。

The code below will change the product button link when product is out of stock on Woocommerce archive pages:当 Woocommerce 存档页面上的产品缺货时,以下代码将更改产品按钮链接:

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).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM