【问题标题】:Disable a plugin function in Wordpress / Woocommerce在 Wordpress / Woocommerce 中禁用插件功能
【发布时间】:2019-10-04 10:44:56
【问题描述】:

我在禁用 Woocommerce Force Sells 扩展程序中的功能时遇到问题。该函数在前端产品页面的购买按钮下添加了一些我想删除的文本。

我想我在 woocommerce-force-sells.php 文件中找到了有问题的函数:

/**
     * Displays information of what linked products that will get added when current
     * product is added to cart.
     */
    public function show_force_sell_products() {
        global $post;

        $product_ids = $this->get_force_sell_ids( $post->ID, array( 'normal', 'synced' ) );
        $titles      = array();

        // Make sure the products still exist and don't display duplicates.
        foreach( array_values( array_unique( $product_ids ) ) as $key => $product_id ) {
            $product = wc_get_product( $product_id );

            if ( $product && $product->exists() && 'trash' !== $product->get_status() ) {
                $titles[] = version_compare( WC_VERSION, '3.0', '>=' ) ? $product->get_title() : get_the_title( $product_id );
            }
        }

        if ( ! empty( $titles ) ) {
            echo '<div class="clear"></div>';
            echo '<div class="wc-force-sells">';
            echo '<p>' . __( 'This will also add the following products to your cart:', 'woocommerce-force-sells' ) . '</p>';
            echo '<ul>';

            foreach ( $titles as $title ) {
                echo '<li>' . $title . '</li>';
            }

            echo '</ul></div>';
        }
    }

我查看了https://codex.wordpress.org/Function_Reference/remove_action,但我真的不知道如何在上面的代码中使用它。

提前非常感谢!

【问题讨论】:

  • remove_action 只会在调用此方法本身时为您提供帮助,因为它首先被添加为作为一个动作/过滤器。
  • 您不能使用删除操作,因为没有添加/使用任何操作。我相信做你想做的事情的唯一方法就是破解那个文件,代价是你永远不能自动更新它。

标签: php wordpress woocommerce


【解决方案1】:

执行此操作的简单方法是从页面中隐藏内容。查找类并添加 显示:无; 到css中的那个类。

您可以在 woocommerce 模板文件中对其进行编辑。很难找到它来自哪个页面(查看模板中所有可能的页面)。一旦你发现它记得将该模板复制到子主题。(在子主题中创建一个名为 woocommerce 的文件夹---如果实际位置有文件夹路径,请添加文件夹路径)。否则,当 woocommerce 更新时,您将丢失所有编辑。

简单的方法就是将它隐藏在 css 中

【讨论】:

  • 感谢您的意见!我在模板文件中四处寻找,实际上找到了有问题的文件并将它们复制到子主题中以防止更新。
【解决方案2】:

你不能删除一个函数,你只能阻止它被执行。但是,这与删除操作不同。但是,如果要从按钮中删除文本,最好更改将按钮添加到页面的模板文件。

以下是有关更改模板的更多信息:https://docs.woocommerce.com/document/template-structure/

【讨论】:

  • 如果它是一个可插拔的函数,你可以让它什么都不做——基本上和移除它一样。
  • if( !function_exists('show_force_sell_products')){ function show_force_sell_products(){return true;}} 或类似的东西
猜你喜欢
  • 1970-01-01
  • 2013-10-07
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 2016-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多