2017-10-28 107 views
-1

在互联网上的大多数文章是关于如何删除/替换“查看产品”或“阅读更多”按钮。
我找不到有关允许两个按钮一起工作的内容。添加“查看产品”按钮波纹管添加到购物车按钮WooCommerce档案页

我对两个按钮并行工作感兴趣(同时)。 第一个按钮将显示应为“查看产品”(在同一页上打开),那么下面“加入购物车

此刻,我的商店只显示添加到购物车按钮。 我使用店面主题(+自定义小孩主题)。

会有人会这么善良,告诉我该怎么做?

回答

0

使用该自定义函数中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>'; 
} 

代码放在您的活动子主题(或主题)的function.php文件或者也在任何插件文件中。

经过测试和工作。


嵌入您的样式(创作评论相关)

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文件或也以任何插件文件。

经过测试和工作。

+0

惊人的,它的工作原理。非常感谢 !另一个问题是,是否可以单独编辑背景颜色和该按钮的文本颜色?谢谢 – NoiTrade88

+0

,我观察到两个按钮之间有相当大的差距,这个距离可以缩小吗?谢谢 – NoiTrade88

+0

谢谢,系统不允许我发布一个新问题(新帐户),除了这个原始问题被低估了。 – NoiTrade88

相关问题