在 WooCommerce 中,需要创建另一个按钮,该按钮重定向到特定产品页面当前“添加到购物车”按钮下方的“联系我们”表单(例如:http://offers.elements.com.sg/product/ha-power-dose-facial/ http://offers.elements.com.sg/product/ha-power-dose-facial/).
最终产品页面:
- 将有2个不同的按钮供用户选择
- 一个将是“添加到购物车”,导致 PayPal 页面,另一个将导致“联系我们”表单
- 用户可以选择其中之一。
我正在使用 OceanWP 主题。
基于woocommerce 单一产品页面中具有固定数量的附加“添加到购物车”按钮 https://stackoverflow.com/questions/48759369/additional-add-to-cart-button-with-fixed-quantity-in-woocommerce-single-product/48759944#48759944答案代码,这是执行此操作的方法:
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="'.$link.'" class="'.$class.'" style="'.$style.'">'.$name.'</a>';
}
}
代码位于活动子主题(活动主题)的 function.php 文件中。经过测试并有效。
其他相关回答:
- 在单个产品页面中的“添加到购物车”按钮后添加自定义按钮 https://stackoverflow.com/questions/43423819/adding-a-custom-button-after-add-to-cart-button-in-single-product-pages/43426508#43426508
- 添加到购物车后添加一个按钮并将其重定向到 WooCommerce 中的某个自定义链接 https://stackoverflow.com/questions/38675675/add-a-button-after-add-to-cart-and-redirect-it-to-some-custom-link-in-woocommerc/38681079#38681079
- 基于产品类型的 WooCommerce“添加到购物车”按钮旁边的自定义按钮 https://stackoverflow.com/questions/37228791/custom-button-next-to-add-to-cart-button-of-woocommerce-based-on-product-type/37229440#37229440
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)