从 WooCommerce 中的面包屑中删除“商店”

问题描述 投票:0回答:5

如何删除 woo commerce 中面包屑中的 Shop 文本?[主页-->商店-->粉红喜马拉雅盐] 我想按照我的 WordPress 站点中的导航菜单设置面包屑。[主页-->产品-->盐-->粉红喜马拉雅盐] 我在我的主菜单中使用了一些页面、自定义链接、类别和产品。

见截图。

Bredcrumb -


菜单-

php wordpress woocommerce breadcrumbs
5个回答
2
投票

您可以通过主题覆盖 WooCommerce 模板(阅读以下官方文档)

模板结构+通过主题覆盖模板

plugins/woocommerce/templates/global/breadcrumb.php

复制文件后 至:
themes/yourtheme/woocommerce/global/breadcrumb.php
,您将能够通过将其替换为以下内容来更改代码:

<?php
/**
 * Shop breadcrumb
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.0
 * @see         woocommerce_breadcrumb()
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! empty( $breadcrumb ) ) {

    $breadcrumb0 = $breadcrumb[0];
    $shop_txt = __( 'Shop', 'woocommerce' );
    $products_txt = __( 'Products', 'woocommerce' );
    $products_url = home_url( '/products/' );
    $breadcrumb10 = array( $products_txt );
    $breadcrumb11 = array( $products_txt, $products_url );
    if(is_product() || is_shop() || is_product_category() || is_product_tag() ){
        if( $breadcrumb[1][0] == $shop_txt ){
            if( ! empty( $breadcrumb[1][1] ) )
                $breadcrumb[1] = $breadcrumb11;
            else
                $breadcrumb[1] = $breadcrumb10;
        } else {
            unset($breadcrumb[0]);
            array_unshift($breadcrumb, $breadcrumb0, $breadcrumb11);
        }
    }

    echo $wrap_before;

    foreach ( $breadcrumb as $key => $crumb ) {

        echo $before;

        if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
            echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
        } else {
            echo esc_html( $crumb[0] );
        }

        echo $after;

        if ( sizeof( $breadcrumb ) !== $key + 1 ) {
            echo $delimiter;
        }
    }

    echo $wrap_after;

}

这将:

  1. 将“商店”替换为“产品”
  2. 当“商店”不存在时,在“首页”后面添加“产品”。

所以你的面包屑总是以:

Home > Products
在商店、档案和单一产品页面开始......


0
投票

这可以通过 CSS 解决,但除非您发布指向您商店的链接,否则无济于事。 尝试这样:

将此行添加到您的自定义 CSS

ul.breadcrumbs li:nth-of-type(2) {display:none}

如果不起作用,可能还需要!重要

ul.breadcrumbs li:nth-of-type(2) {display:none!important}

我无法发表评论,这就是我必须回答的原因。请提供您网站的链接。我将用精确的 CSS 更新我的答案。


0
投票

受 LoicTheAztec 的启发,这里有一个类似但略有不同的需求的解决方案。假设您只是想完全删除商店链接:

复制文件:plugins/woocommerce/templates/global/breadcrumb.php

到:主题/yourtheme/woocommerce/global/breadcrumb.php

在新文件中,查找行

foreach ( $breadcrumb as $key => $crumb ) {

在那行之后,添加这一行:

if (trim(strip_tags($crumb[0])) == 'Shop') { continue; }

所以最终的代码将如下所示:

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! empty( $breadcrumb ) ) {

    echo $wrap_before;

    foreach ( $breadcrumb as $key => $crumb ) {

if (trim(strip_tags($crumb[0])) == 'Shop') { continue; }

        echo $before;

        if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
            echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
        } else {
            echo esc_html( $crumb[0] );
        }

        echo $after;

        if ( sizeof( $breadcrumb ) !== $key + 1 ) {
            echo $delimiter;
        }
    }

    echo $wrap_after;

}

0
投票

这可以在仪表板上完成,无需代码。

  • 转到 > 页面。
  • 在页面上选择快速编辑,标题后面为“- 商店页面” (所以在本例中是“商店 - 商店页面”)
  • 在快速编辑中,将页面标题从“商店”更改为“产品”。

这必定意味着 woocommerce 使用页面标题来填充面包屑菜单。

其他有用的提示

如果您需要,面包屑菜单设置位于 Woocommerce > 设置下,然后是“产品”选项卡,然后是商店页面(下拉选择页面),这就是分配“-商店页面”的方式。

然后,为了更好地控制面包屑菜单中显示的内容,“产品永久链接”下有更多设置


-1
投票

我通过对functions.php进行更改得到了答案 https://www.screencast.com/t/U42lqPduY707

if (get_post_type() ==  'product')
{
echo sprintf($link, '#', esc_html__('Products', 'thegem'));
//echo sprintf($link, get_permalink(get_option ('woocommerce_shop_page_id' , 0 )), esc_html__('Product', 'thegem'));
$taxonomy = 'product_cat';
$terms = get_the_terms( $post->ID, $taxonomy );
foreach ( $terms as $c ) {
$c->term_id;
//  echo '<a href="' . get_term_link($c, 'product_cat') . '">' . ($c->name ) . '</a>';
if($c->term_id=='36') {
echo $delimiter;
echo sprintf($link, get_permalink( 106 ), esc_html__($c->name, 'thegem'));
}
}
}
else {
$slug = $post_type->rewrite;
printf($link, $home_link . '/' . $slug['slug'] . '/', $post_type->labels->singular_name);
}
© www.soinside.com 2019 - 2024. All rights reserved.