WooCommerce产品类别存档页面

时间:2017-11-12 22:46:26

标签: php wordpress image woocommerce product

是否有一种简单的方法可以将Woocommerce 3.x设置为链接到完整尺寸的图像,而不是类别页面上的产品详细信息(您可以看到产品的大拇指)?

所以基本上它可以作为某种类型的画廊使用'添加到购物车'每个图像下方的按钮。

我假设我必须在includes\wc-template-functions.php编辑woocommerce_template_loop_product_link_open()函数并更改:

esc_url( get_the_permalink() ) 

还有别的......

1 个答案:

答案 0 :(得分:1)

  

重要说明:永远不要覆盖任何核心文件,因为您可以使用可用的挂钩   (或者您也可以override WooCommerce templates via a Theme ...

要将Woocommerce 3.x设置为仅链接到类别存档页面上的完整尺寸图像,请使用:

add_action ('woocommerce_before_shop_loop_item', 'custom_loop_product_link_open', 1);
function custom_loop_product_link_open(){
    // For product category archives pages only
    if(is_product_category()){
        // Remove default image link
        remove_action ('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10);
        // Add custom image link function
        add_action ('woocommerce_before_shop_loop_item', 'change_loop_product_link_open', 10);
    }
}

// Custom image link function
function change_loop_product_link_open(){
    global $product; // Get the WC_Product object

    echo '<a href="' . get_the_post_thumbnail_url( $product->get_id(), 'full' )  . '" class="woocommerce-LoopProduct-link">';
}

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

经过测试和工作......

相关问题