【问题标题】:Changing header cart text in Storefront更改店面中的标题购物车文本
【发布时间】:2016-02-16 21:29:55
【问题描述】:

我想在 Storefront 主题中编辑标题迷你购物车中的文本: 'X 项' 只是: 'X' http://demo.woothemes.com/storefront/

我在哪里可以访问这个?在店面或 woocommerce 文件中的任何地方都找不到它。我可以在 header.php 中看到钩子: storefront_header_cart 但在其他文件中找不到任何功能?

当您将鼠标悬停在下拉菜单上时,我也想删除它。我在哪里可以更改?

【问题讨论】:

  • 迷你购物车基于 Ajax JQuery JS,开始查看主题或 Woocommerce JS 文件。您需要打开调试模式才能加载非缩小版本的 JS 文件。
  • 迷你购物车是 ajax,但它最终仍会加载常规模板。

标签: wordpress woocommerce storefront


【解决方案1】:

该功能由storefront_cart_link 函数处理...

你可以覆盖函数...打开functions.php...查找require get_template_directory() . '/inc/init.php';

在它上面,粘贴这段代码...

if ( ! function_exists( 'storefront_cart_link' ) ) {
    function storefront_cart_link() {
        ?>
            <a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
                <?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo wp_kses_data( sprintf( '%d', WC()->cart->get_cart_contents_count() ) );?></span>
            </a>
        <?php
    }
}

storefront_cart_link 加载了这个调用require get_template_directory() . '/inc/init.php';。所以上面将首先加载,使其不再通过调用require get_template_directory() . '/inc/init.php'; 创建该函数。

这可以解决问题.. 但最好使用子主题... 您可以直接将上面的函数粘贴到子主题的functions.php 上。子主题上的functions.php将比父主题先加载,因此让您的函数首先存在。

【讨论】:

  • 感谢您的详细回复。我已将此功能添加到我的子主题 functions.php 中,但它根本没有效果。我在 span 元素中添加了测试类,它也没有出现在前端。放置函数的位置有区别吗?我也尝试过不使用 if 条件,但无济于事(想知道为什么会有 'if 不存在?)
  • @yennefer,你在父主题上试过了吗?只是为了测试......理想情况下,我们需要在 require get_template_directory() . '/inc/init.php'; 之前使用该功能
  • 谢谢,由于某种原因,我对子主题所做的更改和我的测试在几天后出现了。我猜是一些缓存问题,你的第一个答案是正确的。
  • 截至今天,storefront 的当前版本甚至在functions.php 中都没有init.php 调用,我还是将您的代码粘贴到其中,但什么也没发生。有什么线索吗?
猜你喜欢
  • 2019-01-31
  • 1970-01-01
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多