【问题标题】:product_categories shortcode loop add extra link to category pageproduct_categories 短代码循环添加到类别页面的额外链接
【发布时间】:2016-05-25 09:27:27
【问题描述】:

使用 woocommerce 短代码:

[product_categories number="3" ids="69, 70, 71"]

这将返回我列出的三个类别。我希望为每个返回的类别的类别页面添加一个附加链接:

<?php 
add_action('woocommerce_after_subcategory', 'add_meta_to_cat', 1);

function add_meta_to_cat() { 
?>

    <a class = "cta" href="<?php the_category(); ?>">SHOP NOW</a>

<?php
}

这会添加带有指向当前页面链接的按钮。

我是否需要专门挂钩短代码循环?
这可能吗?

【问题讨论】:

    标签: php wordpress woocommerce categories product


    【解决方案1】:

    您需要使用 the_category(); 代替:

    add_action('woocommerce_after_subcategory', 'add_meta_to_cat', 1);
    function add_meta_to_cat() { 
        $prod_cat_args = array(
            'taxonomy'     => 'product_cat',
            'orderby'      => 'name',
            'empty'        => 0
        );
    
        $terms = get_categories( $prod_cat_args );
        foreach ( $terms as $term ) {
            $term_link = get_term_link( $term );
            echo '<a class="cta" href="' . esc_url( $term_link ) . '">' . __( "SHOP NOW", "your_theme_slug" ) . '</a>';
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 2017-01-25
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      相关资源
      最近更新 更多