如何覆盖主题类功能中定义的工具提示标题?

时间:2020-08-20 18:18:17

标签: wordpress overriding themes

我真的希望有人能帮助我。我已经联系了ThemeIsle支持,他们不提供对自定义代码的支持,所以我遇到了麻烦。

我有一个Wordpress网站,使用的是ThemeIsle的Neve主题,该主题目前正在开发中。我想更改当用户将鼠标悬停在demo site

的页面商店页面上产品的心脏图标上时显示的工具提示文本

当前它显示“添加到愿望清单”,我希望声明“添加到收藏夹” 。我可以看到有一个名为 \ plugins \ neve-pro-addon \ includes \ modules \ woocommerce_booster \ views \ wish_list.php 的php文件,其中包含我要覆盖的功能:

<?php
/**
 * Class that add wish list functionality
 *
 * @package Neve_Pro\Modules\Woocommerce_Booster\Views
 */

namespace Neve_Pro\Modules\Woocommerce_Booster\Views;

use HFG\Core\Components\Nav;

/**
 * Class Wish_List
 *
 * @package Neve_Pro\Modules\Woocommerce_Booster\Views
 */
class Wish_List extends Abstract_Shop_Product {
    ...
    ...

    /**
     * Wish List button markup.
     */
    public function add_wish_list_button() {
        global $product;

        $position        = get_theme_mod( 'neve_wish_list', 'none' );
        $icon_class      = 'add-to-wl';
        $product_id      = $product->get_id();
        $wish_list_label = apply_filters( 'neve_wish_list_label', __( 'Add to wishlist', 'neve' ) );
        /* translators: %s - product title */
        $title_sr = apply_filters( 'neve_sr_title', sprintf( __( 'Add %s to wishlist', 'neve' ), get_the_title() ) );

        if ( $this->is_product_in_wishlist( $product_id ) ) {
            $icon_class .= ' item-added';
        }

        echo '<div class="nv-wl-wrap ' . esc_attr( $position ) . '">';
        echo '<a href="#" class="' . esc_attr( $icon_class ) . '" data-pid="' . esc_attr( $product_id ) . '" aria-label="' . esc_html( $title_sr ) . '">';
        echo '<svg width="18" height="18" viewBox="0 0 512 512"><path xmlns="http://www.w3.org/2000/svg" fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"/></svg>';
        echo '<span class="tooltip tooltip-left">' . esc_html( $wish_list_label ) . '</span>';
        echo '</a>';
        echo '</div>';
    }

    ...
    ...
}

我已经创建了一个子主题,但我不知道如何甚至是否可以覆盖它。子主题当前反映了主题本身的布局,而NevePro插件具有woocommerce_booster文件夹,该文件夹似乎添加了所有其他功能。我曾尝试在孩子的各个位置创建替代文件,但无济于事。

我是WP的新手,任何指针都将非常有帮助。

谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用“ neve_wish_list_label”过滤器并更改标签。检查我下面的代码。您可以添加子主题function.php文件

function change_neve_wish_list_label( $wish_list_label ){
    $wish_list_label = __( 'Add to favourites', 'neve' );
    return $wish_list_label;
}
add_filter( 'neve_wish_list_label', 'change_neve_wish_list_label', 10, 1 );