商店-->粉红喜马拉雅盐]我想根据我在 WordPress 网站中的导航菜单设置面包屑。[主页-->产品-->盐-->粉红喜-6ren">
gpt4 book ai didi

php - 从 WooCommerce 中的面包屑中删除 "Shop"

转载 作者:可可西里 更新时间:2023-10-31 23:27:34 25 4
gpt4 key购买 nike

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

查看截图。

Bredcrumb - enter image description here


菜单 - https://www.screencast.com/t/To2xchRWJo

最佳答案

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

Template Structure + Overriding Templates via a Theme

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. 当“Shop”不存在时,在“Home”后面添加“Products”。

So your breadcrumps will always start with: Home > Products on shop, archives and single product pages…

关于php - 从 WooCommerce 中的面包屑中删除 "Shop",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46034021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com