互联网上的大多数文章都是关于如何删除/替换“查看产品”或“阅读更多”按钮的。
我找不到与允许两个按钮一起工作相关的东西。
我有兴趣让两个按钮并行工作(同时)。要显示的第一个按钮应该是“查看产品”(在同一页面上打开),然后在“添加到购物车”下方
目前,我的商店只显示添加到购物车按钮。我正在使用店面主题(+ 自定义子主题)。
有人会这么好心并告诉我该怎么做吗?
互联网上的大多数文章都是关于如何删除/替换“查看产品”或“阅读更多”按钮的。
我找不到与允许两个按钮一起工作相关的东西。
我有兴趣让两个按钮并行工作(同时)。要显示的第一个按钮应该是“查看产品”(在同一页面上打开),然后在“添加到购物车”下方
目前,我的商店只显示添加到购物车按钮。我正在使用店面主题(+ 自定义子主题)。
有人会这么好心并告诉我该怎么做吗?
使用这个挂在动作钩子中的自定义函数woocommerce_after_shop_loop_item
,添加链接到产品的自定义按钮(变量和分组产品类型除外):
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button', 5 );
function add_a_custom_button() {
global $product;
// Not for variable and grouped products that doesn't have an "add to cart" button
if( $product->is_type('variable') || $product->is_type('grouped') ) return;
// Output the custom button linked to the product
echo '<div style="margin-bottom:10px;">
<a class="button custom-button" href="' . esc_attr( $product->get_permalink() ) . '">' . __('View product') . '</a>
</div>';
}
代码在您的活动子主题(或活动主题)的functions.php 文件中。
经过测试并且仍然可以在 WooCommerce 3.7.x 上完美运行(带有最后一个店面主题):
嵌入您的样式(与作者评论相关):
add_action('wp_head', 'custom_button_styles', 9999 );
function custom_button_styles() {
if( is_shop() || is_product_category() || is_product_tag() ):
// The styles
?>
<style>
.button.custom-button { background-color: white !important;
color: black !important; border: 2px solid #4CAF50 !important; }
.button.custom-button:hover { background-color: black !important;
color: white !important; border: 2px solid black !important; }
</style>
<?php
endif;
}
代码在您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。
测试和工作。