代码之家  ›  专栏  ›  技术社区  ›  Rok Benko

WooCommerce:简单产品的“选择选项”?

  •  0
  • Rok Benko  · 技术社区  · 4 年前

    那么,有没有一种方法可以在简单产品上设置一个“选择选项”按钮,将其重定向到单个产品页面(与可变产品的情况相同)?

    先谢谢你。

    1 回复  |  直到 4 年前
        1
  •  1
  •   rank    4 年前

    woocommerce_loop_add_to_cart_link 为了这个。您可以在函数.php你的主题是:

    add_filter( 'woocommerce_loop_add_to_cart_link', 'custom_add_to_cart_button', 10, 2 );
    function custom_add_to_cart_button($button,$product) {
        // Do not change the button for variable products
        if( $product->is_type('variable') ) return $button;
    
        $buttontext = __( "SELECT OPTIONS", "woocommerce" ); // your button text
    
        // replace the button to be a link to the product detail page
        return '<a class="button" href="' . $product->get_permalink() . '">' . $buttontext . '</a>';
    }