向 WooCommerce 单一产品页面添加多个选项卡

2024-04-18

我正在尝试向 WooCommerce 添加三个自定义选项卡。我有下面的代码,其中两个显示,但由于某种原因,属性描述选项卡没有显示在页面上。不仅“数量定价”选项卡不显示其描述。我尝试将代码的不同部分移动到不同的位置,并且检查了代码是否有错误或丢失的部分。这是我所能得到的最接近的结果。

我的过程是基本上删除我不想要的现有选项卡,然后按照我希望它们出现的顺序添加新选项卡。

我有一种感觉,我错过了一些东西。

您可以在这里查看该网站:http://demo.bergdahl.com/product/6-oz-catridge/ http://demo.bergdahl.com/product/6-oz-catridge/

这是我正在使用的代码:

// WooCommerce Tabs



// REMOVE EXISTING TABS

add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );


function woo_remove_product_tabs( $tabs ) {

    unset( $tabs['description'] );          // Remove the description tab

    // unset( $tabs['reviews'] );           // Remove the reviews tab

    unset( $tabs['additional_information'] );   // Remove the additional information tab

    return $tabs;
}




// ADD ATTRIBUTE DESCRIPTION TAB

add_filter( 'woocommerce_product_tabs', 'woo_attrib_desc_tab' );

function woo_attrib_desc_tab( $tabs ) {

    // Adds the Attribute Description tab

    $tabs['attrib_desc_tab'] = array(

        'title'     => __( 'Desc', 'woocommerce' ),

        'priority'  => 100,

        'callback'  => 'woo_attrib_desc_tab_content'

    );

    return $tabs;

}


// ADD QUANTITY PRICING TAB

add_filter( 'woocommerce_product_tabs', 'woo_qty_pricing_tab' );

function woo_qty_pricing_tab( $tabs ) {

    // Adds the qty pricing  tab

    $tabs['qty_pricing_tab'] = array(

        'title'     => __( 'Quantity Pricing', 'woocommerce' ),

        'priority'  => 110,

        'callback'  => 'woo_qty_pricing_tab_content'

    );
    return $tabs;
}

// ADD OTHER PRODUCTS TAB

add_filter( 'woocommerce_product_tabs', 'woo_other_products_tab' );

function woo_other_products_tab( $tabs ) {

    // Adds the other products tab

    $tabs['other_products_tab'] = array(

        'title'     => __( 'Other Products', 'woocommerce' ),

        'priority'  => 120,

        'callback'  => 'woo_other_products_tab_content'

    );

    return $tabs;

}

// ADD CUSTOM TAB DESCRIPTIONS

function woo_attrib_desc_tab_content() {

    // The attribute description tab content

    echo '<h2>Description</h2>';

    echo '<p>Custom description tab.</p>';

}

function woo_qty_pricing_tab_content() {

    // The qty pricing tab content

    echo '<h2>Quantity Pricing</h2>';

    echo '<p>Here\'s your quantity pricing tab.</p>';   

}

function woo_other_products_tab_content() {

    // The other products tab content

    echo '<h2>Other Products</h2>';

    echo '<p>Here\'s your other products tab.</p>';

}

编辑下面 LoicTheAztec 的回复,这是我的整个functions.php 文件。我尝试过有和没有?>在底部:

<?php
add_theme_support( 'builder-3.0' );

add_theme_support( 'builder-responsive' );



function register_my_fonts() {

    wp_register_style('googleFonts-OpenSans', '//fonts.googleapis.com/css?family=Open+Sans:400,300,700');

    wp_enqueue_style( 'googleFonts-OpenSans');

}



add_action('wp_enqueue_scripts', 'register_my_fonts');





function sc_replacecolon( $content ){ return str_replace( '[sc:', '[sc name=', $content ); }

add_filter( 'the_content', 'sc_replacecolon', 5 );



/* WOOCOMMERCE */

add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs', 100, 1 );
function woo_custom_product_tabs( $tabs ) {

    // 1) Removing tabs

    unset( $tabs['description'] );              // Remove the description tab
    // unset( $tabs['reviews'] );               // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab


    // 2 Adding new tabs

    //Attribute Description tab
    $tabs['attrib_desc_tab'] = array(
        'title'     => __( 'Desc', 'woocommerce' ),
        'priority'  => 100,
        'callback'  => 'woo_attrib_desc_tab_content'
    );

    // Adds the qty pricing  tab
    $tabs['qty_pricing_tab'] = array(
        'title'     => __( 'Quantity Pricing', 'woocommerce' ),
        'priority'  => 110,
        'callback'  => 'woo_qty_pricing_tab_content'
    );

    // Adds the other products tab
    $tabs['other_products_tab'] = array(
        'title'     => __( 'Other Products', 'woocommerce' ),
        'priority'  => 120,
        'callback'  => 'woo_other_products_tab_content'
    );

    return $tabs;

}

// New Tab contents

function woo_attrib_desc_tab_content() {
    // The attribute description tab content
    echo '<h2>Description</h2>';
    echo '<p>Custom description tab.</p>';
}
function woo_qty_pricing_tab_content() {
    // The qty pricing tab content
    echo '<h2>Quantity Pricing</h2>';
    echo '<p>Here\'s your quantity pricing tab.</p>';
}
function woo_other_products_tab_content() {
    // The other products tab content
    echo '<h2>Other Products</h2>';
    echo '<p>Here\'s your other products tab.</p>';
}
?>

因为你使用了 4 次同一个钩子woocommerce_product_tabs,您的问题来自第一个问题的最高优先级。相反,您应该只使用它一次,将 4 个挂钩函数合并为一个。

这是您的功能测试代码,稍作更改:

add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
function woo_custom_product_tabs( $tabs ) {

    // 1) Removing tabs

    unset( $tabs['description'] );              // Remove the description tab
    // unset( $tabs['reviews'] );               // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab


    // 2 Adding new tabs and set the right order

    //Attribute Description tab
    $tabs['attrib_desc_tab'] = array(
        'title'     => __( 'Desc', 'woocommerce' ),
        'priority'  => 100,
        'callback'  => 'woo_attrib_desc_tab_content'
    );

    // Adds the qty pricing  tab
    $tabs['qty_pricing_tab'] = array(
        'title'     => __( 'Quantity Pricing', 'woocommerce' ),
        'priority'  => 110,
        'callback'  => 'woo_qty_pricing_tab_content'
    );

    // Adds the other products tab
    $tabs['other_products_tab'] = array(
        'title'     => __( 'Other Products', 'woocommerce' ),
        'priority'  => 120,
        'callback'  => 'woo_other_products_tab_content'
    );

    return $tabs;

}

// New Tab contents

function woo_attrib_desc_tab_content() {
    // The attribute description tab content
    echo '<h2>Description</h2>';
    echo '<p>Custom description tab.</p>';
}
function woo_qty_pricing_tab_content() {
    // The qty pricing tab content
    echo '<h2>Quantity Pricing</h2>';
    echo '<p>Here\'s your quantity pricing tab.</p>';
}
function woo_other_products_tab_content() {
    // The other products tab content
    echo '<h2>Other Products</h2>';
    echo '<p>Here\'s your other products tab.</p>';
}

此代码位于活动子主题(或主题)的 function.php 文件中或任何插件文件中。

经过测试并有效。


在同一个钩子中,您可以:

  • 删除标签
  • Add tabs
  • 重新排序选项卡

相关官方文档:编辑产品数据选项卡 https://docs.woocommerce.com/document/editing-product-data-tabs/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

向 WooCommerce 单一产品页面添加多个选项卡 的相关文章

  • WordPress 网站上出现数据库错误“一个或多个数据库表不可用”

    Error One or more database tables are unavailable The database may need to be repaired 我怎么解决这个问题 wp config php 是正确的 我使用
  • 使用 md5 加密的 PHP 和 Mysql 查询出现问题

    我使用普通的 php mysql 插入查询并使用 md5 加密密码 这是插入查询 sql mysql query INSERT INTO user username password role approved values usernam
  • 压缩 zend Framework 2 的 html 输出

    我目前正在 PHP 5 4 4 上使用 Zend Framework 2 beta 开发个人 web 应用程序以用于自学目的 我想知道是否可以在 html 输出发送到浏览器之前拦截它 以便通过删除所有不必要的空格来缩小它 我怎样才能在ZF2
  • Magento - 将特定父类别的子类别列为链接

    我是 php 的初学者 并且一直试图将一个父类别的子类别作为链接调用 我得到了这个 它调出了 getName 但 getUrl 根本没有返回任何 URL 输出代码只是 li a href name of sub a li
  • php表格:每行显示3个单元格[重复]

    这个问题在这里已经有答案了 我看这里 数组放入每行 5 个单元格的表格中 https stackoverflow com questions 9099568 array into a table with 5 cells in each r
  • 覆盖供应商自动加载编辑器

    有没有办法让您创建的自动加载文件在调用供应商自动加载之前运行 我们似乎遇到了 SimpleSAML 的自动加载覆盖我们创建的自动加载文件之一的问题 我是 Composer 的新手 似乎无法在网上找到任何解决方案 我尝试将我们的自动加载文件包
  • Magento补丁安装失败

    从以下位置下载并运行 Magento PHP 5 4 支持补丁 Magento CE v1 7 0 0 1 7 0 2 时http www magentocommerce com download http www magentocomme
  • 如何以编程方式获取 WooCommerce 中的所有产品?

    我想获取 WooCommerce 中的所有产品数据 产品 sku 名称 价格 库存数量 可用性等 我可以使用 wp query 来做到这一点吗 这样你就可以通过 wp query 获取所有产品 global wpdb all product
  • PHP 中的 Preg_replace

    我想替换 中包含的字符串中的内容content 它是多行等 preg replace 函数应该删除整个 com 没有垫子 蒙特 尝试这个 result preg replace s replacement content subject
  • 如何将 mysql 转换为 mysqli? [复制]

    这个问题在这里已经有答案了 我厌倦了将 mysql 转换为 mysqli 但似乎收到了很多错误和警告 连接到数据库没有问题 但其余代码似乎错误 我做错了什么 sql
  • CakePHP Xml 实用程序库触发 DOMDocument 警告

    我正在使用 CakePHP 在视图中生成 XMLXML核心库 http book cakephp org 2 0 en core utility libraries xml html xml Xml build data array ret
  • PHP7构造函数类名

    我有一个 Laravel 4 2 应用程序 它可以与 PHP5 一起使用 没有任何问题 由于我安装了一个运行 PHP7 的新 vagrant box 一旦我运行一个模型 其中函数名称与类名称 关系函数 相同 就会出现错误 如下所示
  • 使用PHP套接字发送和接收数据

    我正在尝试通过 PHP 套接字发送和接收数据 一切正常 但是当我尝试发送数据时 PHP 不发送任何内容 Wireshark 告诉我发送的数据长度为 0 我正在使用这段代码
  • PHP中如何识别服务器IP地址

    PHP中如何识别服务器IP地址 对于服务器 ip 来说是这样的 SERVER SERVER ADDR 这是港口的 SERVER SERVER PORT
  • 使用 DOJO 自动完成文本框

    我正在寻找一种使用 DOJO 进行文本框自动建议的简单方法 我将查询的数据库表 使用 PHP 脚本 以 JSON 形式返回 有超过 100 000 条记录 因此这确实不应该采用 FilteringSelect 或 ComboBox 的形式
  • Zend Framework Zend_Form 装饰器: 位于按钮元素内部?

    我有一个像这样创建的按钮元素 submit new Zend Form Element Button submit submit gt setLabel My Button submit gt setDecorators array Vie
  • php下拉菜单人口

    我正在尝试编写一个 php 脚本 该脚本将根据主下拉菜单的选择填充第二个下拉菜单 我想使用 jquery 来完成所有非页面刷新的事情 但我发现现有的所有东西都很难理解和修改 你知道有什么写得很好且易于理解的东西吗 或者可能是现有的教程 下面
  • 如何在 codeigniter 查询中使用 FIND_IN_SET?

    array array classesID gt 6 this gt db gt select gt from this gt table name gt where array gt order by this gt order by q
  • mysqli bind_param 中的 NULL 是什么类型?

    我正在尝试将参数绑定到 INSERT INTO MySQLi 准备好的语句 如果该变量存在 否则插入 null 然后我知道 type variable i corresponding variable has type integer d
  • PHP 和 NLP:嵌套括号(解析器输出)到数组?

    想要将带有嵌套括号的文本转换为嵌套数组 以下是 NLP 解析器的输出示例 TOP S NP PRP I VP VBP love NP NP DT a JJ big NN bed PP IN of NP NNS roses 原文 我喜欢一大床

随机推荐

  • 更改所有 Woocommerce 电子邮件通知中的“回复”电子邮件地址

    在 Woocommerce 中 我想更改应始终用作的电子邮件地址回复地址对于所有电子邮件通知 Woocommerce 如何做到这一点 以下操作将更改所有电子邮件通知中的 回复 电子邮件地址 和姓名 add filter woocommerc
  • kendo-numerictextbox' 不是已知元素

    我在尝试在 Angular 7 应用程序中实现 kendo numerictextbox 时遇到错误 我目前正在使用 kendo dropdownlist 和文本框控件 没有任何问题 我不确定缺少哪个包 我是否缺少一些依赖
  • 如何获取接受的入站套接字的 IP 地址?

    我的问题是 服务器将创建一个套接字 绑定到给定端口并使用地址 INADDR ANY 监听 和接受 新连接 然后 我们可以获取客户端的ip地址 来自接受 现在 我想知道服务器的IP地址 因为服务器的主机有 上面有多个网卡 如何知道接受的入站套
  • 使用 mongoose 和 Fixie(Heroku 附加组件)连接到 mongodb

    我有一个托管在 Atlas MongoDB Cloud 集群上的 mongodb 数据库 我目前正在使用 mongoose 访问 Node js 应用程序中的数据库 mongoose connect mongodb user pw clus
  • R:格式化xtable中的数字

    我有数据 transaction lt c 1 2 3 date lt c 2010 01 31 2010 02 28 2010 03 31 type lt c debit debit credit amount lt c 500 1000
  • QML 不显示 svg 图像

    我编写了一个简单的 QML ui 它使用一些 svg 图像 当我在桌面上执行该应用程序时 一切都很好 显示了 UI 以及上面的 svg 图像 当我尝试在嵌入式设备 运行嵌入式 Windows 上执行应用程序时 会出现问题 在这种情况下 会显
  • IMemoryCache 保证唯一的新密钥 .NET-Core

    我正在尝试使用Microsoft Extensions Caching Memory IMemoryCache接口 类 我需要向缓存添加一个新项目 并确保不会覆盖已保存的任何其他内容 目前 所有密钥都是自动生成和随机的 不是顺序的 如何针对
  • 获取 PostgreSQL 中两个日期之间的结果

    我有下表 id user id start date end date integer integer date date Fields start date and end date持有日期值 例如YYYY MM DD 该表中的条目可能如
  • 标准吉他歌词/和弦包围的正则表达式

    我正在尝试在为吉他 歌词格式化的标准文本文档中的和弦周围添加方括号 以使它们与 OnSong 应用程序更兼容 我有规则 但不明白如何匹配所有可能的组合 规则是 和弦将以单个大写 A G 开头 如果大写 A G 后跟空格 换行符 b m su
  • java中的绿色线程和本机线程[重复]

    这个问题在这里已经有答案了 绿色线程和本机线程有什么区别 为什么叫绿色 本土呢 我是编程世界的新手 我喜欢学习java 在浏览 java 线程面试问题时 我发现了这一点 我听说过线程 但没有听说过这些绿色和原生的 我仔细研究了绿色线程和本机
  • stripe 登录 zsh:未找到命令:stripe

    我正在跟进条纹文档 https stripe com docs stripe cli install当我去stripe login在步骤 2 中 我收到以下错误 zsh 找不到命令 条带 我已经执行了步骤 1 安装 stripe CLI 为
  • WPF:如何让单选按钮显示为水平行的切换按钮

    我目前正在构建一个将在触摸面板中使用的用户界面 因此 我想将任何单选按钮组显示为切换按钮的水平行 我已经弄清楚如何显示 ToggleButtons 而不是标准项目符号项目
  • 禁用缓存 YouTube 视频

    当 YouTube 使 YouTube 视频与缓存一起使用时 YouTube 取得了相当大的成就 然而 这导致我的 ajax 网站出现问题 我想知道是否有办法禁用 YouTube 视频的缓存 特别是在 Internet Explorer 中
  • 解码 PKCS#12 文件

    我正在寻找在 NET 中解码 PKCS 12 文件的方法 我需要提取私钥和任何证书 以便我可以以编程方式访问以下内容 modulus 公共指数 私人指数 prime1 prime2 指数1 指数2 系数 我需要此信息 以便我可以成功使用 P
  • 从 Facelets 错误页面引用 CDI 托管 bean

    我很难尝试让通用错误页面在使用 JSF 2 Facelets 和 CDI 的 非常简单的 WAR 项目中工作 我的应用程序服务器是 WebLogic 12c 它应该支持所有这些开箱即用的功能 但它无法显示错误页面 当我将完全相同的 WAR
  • 监控 AppFabric 缓存

    我在 3 台服务器 AppFabric 1 1 上设置了高度可用的 AppFabric 缓存 我想监视每台服务器上的本地缓存 如果它因任何原因而关闭 则将其启动备份 Problem 问题是权限 我编写了一个 Powershell 脚本来执行
  • 从 php 中的日期时间获取年/月/日?

    I used date w timestamp and date w timestamp 要知道这一天 date n timestamp 几个月等 现在我正在使用日期时间 我想知道从日期时间获取一天 一个月等的等效函数是什么 PS 我知道我
  • ServiceBus RetryExponential 属性含义

    我很难理解与 QueueClients 结合使用的 RetryExponential 类 我也假设 SubscriptionClients 属性已列出here http msdn microsoft com en us library wi
  • Grails:当我向 message.properties 添加新属性时出现 Native2ascii 错误

    当我在运行时向 grails 应用程序中的 message properties 文件添加新属性时 出现了一个奇怪的错误 当我通过命令行重新启动应用程序或重新启动STS时 此错误消失 我使用的是 2 0 1 版本 直到一周前 我还能够在运行
  • 向 WooCommerce 单一产品页面添加多个选项卡

    我正在尝试向 WooCommerce 添加三个自定义选项卡 我有下面的代码 其中两个显示 但由于某种原因 属性描述选项卡没有显示在页面上 不仅 数量定价 选项卡不显示其描述 我尝试将代码的不同部分移动到不同的位置 并且检查了代码是否有错误或