WooCommerce中特定单个产品页面的附加自定义按钮 [英] Additional custom button for specific single product page in WooCommerce

查看:60
本文介绍了WooCommerce中特定单个产品页面的附加自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WooCommerce中,需要创建另一个重定向到联系我们"的按钮.我当前的添加到购物车"下方的表格特定产品页面的按钮(例如: http://offers.elements.com.sg/product/ha-power-dose-facial/).

In WooCommerce on need to create another button that redirects to "Contact Us" form below my current "Add to Cart" button for specific product page (example: http://offers.elements.com.sg/product/ha-power-dose-facial/).

最终产品页面:

  • 会有2个不同的按钮供用户选择
  • 一个将是添加到购物车"指向贝宝(PayPal)页面,另一页将导致与我们联系"表格
  • 用户可以选择其中之一.

我正在使用OceanWP主题.

I'm using on OceanWP theme.

推荐答案

基于答案代码,这是这样做的方法:

Based on additional add to cart button with fixed quantity in woocommerce single product pages answer code, here is the way to do it:

add_action( 'woocommerce_after_add_to_cart_button', 'additional_single_product_button', 20 );
function additional_single_product_button() {
    global $product;

    // Define your targeted product IDs in the array below 
    $targeted_product_ids = array( 37, 53 );

    if( in_array( $product->get_id(), $targeted_product_ids ) ) {
        
        $link = home_url('/contact-us/'); // <== Here set button link
        $name = esc_html_( "Contact Us", "woocommerce" ); // <== Here set button name 
        $class = 'button alt';
        $style = 'display: inline-block; margin-top: 12px;';
    
        // Output
        echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$name.'</a>';
    }
}

代码进入您的活动子主题(活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (active theme). Tested and works.

其他相关答案:

这篇关于WooCommerce中特定单个产品页面的附加自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆