【发布时间】:2016-11-03 01:39:03
【问题描述】:
您好,我正在尝试从 wordpress 插件文件中删除一个操作。该插件称为 Woocommerce 积分和奖励。我在其中一个类文件中找到了要删除的操作。当我注释掉“add_action”时,它正是我想要的。但我试图从我孩子的functions.php中删除动作。我一直在阅读这个,我认为我的问题是我需要“全球化”动作所在的类变量;但我不确定那个类变量是什么……
这是添加动作的代码(文件的一部分):
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' ) );
}
我要删除的功能是这个:
add_action( 'woocommerce_before_cart', array( $this, 'render_redeem_points_message' ), 16 );
到目前为止还没有成功将其删除;这是我在functions.php中的内容:
global $woocommerce, $wc_points_rewards;
/*
global $this;
*/
remove_action( 'woocommerce_before_cart', array( $this, 'render_redeem_points_message' ), 16 );
所以 - 我确信这可以通过这种方式完成,至少我已经读过它可以完成,我想我只是在这方面有些问题......
我尝试将 $this 全球化,但这只是给了我一条错误消息...
如果您需要查看整个文件或其他内容,请告诉我...
所以我希望这里有人可以帮助我找出我做错了什么......
** 2018 年 8 月星期一更新 ******** 寻找类在哪里被实例化;我在“woo commerce-points-and-rewards.php”文件中找到了这个;看起来可能是这样,但不确定我在看什么;
这看起来像“WC_Points_Rewards_Cart_Checkout”的实例化位置吗?
-
如果是这样,我不确定如何使用它在 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(); }
非常感谢...
【问题讨论】:
-
请说明
WC_Points_Rewards_Cart_Checkout类是如何实例化的。 -
你好 Brasofilo,我想我可能已经找到了 - 我将它添加到我上面的问题中......谢谢,
-
Geesh...在另一个类中实例化...看看this solution,应该可以工作。