需要帮助从插件文件中删除操作 [英] need help removing action from plugin file

查看:25
本文介绍了需要帮助从插件文件中删除操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试从 wordpress 插件文件中删除一个操作.该插件称为 Woocommerce 积分和奖励.我在其中一个类文件中找到了要删除的操作.当我注释掉add_action"时,它完全符合我的要求.但我试图从我的孩子的functions.php 中删除操作.我一直在阅读这个,我认为我的问题是我需要全球化"动作所在的类变量;但我不确定那个类变量是什么......

Hello I am trying to remove an action from a wordpress plugin file. The plugin is called Woocommerce Points and Rewards. I have found the action I want to remove in one of the class files. When I comment out the "add_action" it does exactly what I want. But I am trying to remove the action from functions.php in my child them. I have been reading on this and I think my problem is I need to "globalize" the class variable that the action is in; but I am not sure what that class variable is…

这是添加操作(文件的一部分)的代码:

here is the code where it adds the action (part of a file):

class WC_Points_Rewards_Cart_Checkout {


/**
 * Add cart/checkout related hooks / filters
 *
 * @since 1.0
 */
public function __construct() {

    // Coupon display
    add_filter( 'woocommerce_cart_totals_coupon_label', array( $this, 'coupon_label' )      );
    // Coupon loading
    add_action( 'woocommerce_cart_loaded_from_session', array( $this, 'points_last' ) );
    add_action( 'woocommerce_applied_coupon', array( $this, 'points_last' ) );

    // add earn points/redeem points message above cart / checkout
    add_action( 'woocommerce_before_cart', array( $this, 'render_earn_points_message' ), 15 );

    add_action( 'woocommerce_before_cart', array( $this, 'render_redeem_points_message' ), 16 );

    add_action( 'woocommerce_before_checkout_form', array( $this, 'render_earn_points_message' ), 5 );
    add_action( 'woocommerce_before_checkout_form', array( $this, 'render_redeem_points_message' ), 6 );

    // handle the apply discount submit on the cart page
    add_action( 'wp', array( $this, 'maybe_apply_discount' ) );

    // handle the apply discount AJAX submit on the checkout page
    add_action( 'wp_ajax_wc_points_rewards_apply_discount', array( $this, 'ajax_maybe_apply_discount' ) );
}

我要删除的功能是这个:

The function I want to remove is this one:

add_action( 'woocommerce_before_cart', array( $this, 'render_redeem_points_message' ), 16 );

到目前为止没有成功将其删除;这是我在functions.php中的内容:

so far no luck in getting it removed; here is what I have in functions.php:

global $woocommerce, $wc_points_rewards;

/*
global $this;
*/

remove_action( 'woocommerce_before_cart', array( $this, 'render_redeem_points_message' ), 16 );

所以 - 我相信这可以通过这种方式完成,至少我已经读过它可以完成,我想我只是在这方面有一些问题......

so - I am sure this can be done in this way at least I have read that it can be done, I think I just have some thing wrong on this…

我尝试将 $this 全球化,但这只是给了我一条错误消息...

I tried globalizing $this, but that just gave me an error message...

如果您需要查看整个文件或其他内容,请告诉我...

if you need to see the entire file or something else please just let me know…

所以我希望这里有人可以帮助我确定我做错了什么......

So I am hoping someone on here can help me identify what I am doing wrong…

** 更新星期一 8/18 ********寻找类在哪里被实例化;我在woo commerce-points-and-rewards.php"文件中找到了这个;看起来可能就是这样,但不确定我在看什么;

** UPDATE Monday 8/18 ******** Looking for where class is instantiated; I have found this in the "woo commerce-points-and-rewards.php" file; this looks like this may be it but not sure what I am looking at;

  1. 这看起来像WC_Points_Rewards_Cart_Checkout"被实例化的地方吗?

  1. does this look like where the "WC_Points_Rewards_Cart_Checkout" is instantiated?

如果是这样,我不确定如何使用它在functions.php 中编写我的删除操作"...

And if so I am not sure how i use this to write my "remove action" in functions.php...

私有函数包括() {

// product class
require( 'classes/class-wc-points-rewards-product.php' );
$this->product = new WC_Points_Rewards_Product();

// cart / checkout class
require( 'classes/class-wc-points-rewards-cart-checkout.php' );
$this->cart = new WC_Points_Rewards_Cart_Checkout();

// order class
require( 'classes/class-wc-points-rewards-order.php' );
$this->order = new WC_Points_Rewards_Order();

// discount class
require( 'classes/class-wc-points-rewards-discount.php' );
$this->discount = new WC_Points_Rewards_Discount();

// actions class
require( 'classes/class-wc-points-rewards-actions.php' );
$this->actions = new WC_Points_Rewards_Actions();

// manager class
require( 'classes/class-wc-points-rewards-manager.php' );

// points log access class
require( 'classes/class-wc-points-rewards-points-log.php' );

if ( is_admin() )
    $this->admin_includes();
}

非常感谢...

推荐答案

试试这个:

// Use the class name instead of a globalized $this
remove_action( 'woocommerce_before_cart', array( 'WC_Points_Rewards_Cart_Checkout', 'render_redeem_points_message' ), 16 );

由于 $this 是它所在类的内部引用,因此将其全球化可能不是一件好事.

As $this is an internal referrer to the class it is used in, globalizing it may not be a good thing.

该插件是否允许您使用自己的类来扩展类并改为使用它?

Does the plugin allow you to extend the class with your own and use it instead?

这篇关于需要帮助从插件文件中删除操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆