【发布时间】:2019-11-10 20:52:48
【问题描述】:
我有一个出租度假屋的商业网站,其中 WordPress 主题有自己的预订系统,仅用于预订房屋,非常棒!
我也可以预订旅游/服务(不是房屋),但对于这些我使用 WooCommerce/WooCommerce 预订插件,而不是房屋预订系统。
一切都很棒!
但最近主题更新为家庭预订系统引入了 WooCommerce 结帐选项,该选项在更新之前从未存在过。虽然我关闭了主题 WooCommerce 结帐选项,但代码仍在主题的核心插件中执行。几周来,我一直在与主题提供商提供开放支持票证,以便他们在用户关闭选项时放置条件语句以不运行新代码,但我不知道何时或是否它将永远完成。现在发生的事情是,主题的核心插件正在操纵 WooCommerce 结帐,并且在下订单的最后一步之后,我以前一直单独使用 WooCommerce 的任何旅游/服务现在在下订单后超时并产生超过 1,000 个额外后端的“幻影”结帐页面。
底线: 当从主题的核心插件文件中注释掉 3 行(第 27-29 行)时,一切正常。但我不想在每次插件更新后都注释掉这 3 行。
//add_action( 'woocommerce_thankyou', array($this,'order_attach') );
//add_filter( 'woocommerce_checkout_fields', array($this,'custom_override_checkout_fields') );
//add_filter('woocommerce_create_account_default_checked', '__return_true');
这里是完整的代码(第 27-29 行被注释掉了):https://pastebin.com/jqtBpCpA
我已尝试以下两个页面上的说明,但均未成功: https://mekshq.com/remove-wordpress-action-filter-class https://github.com/herewithme/wp-filters-extras
我在functions.php文件中插入了以下内容
方法一:
global $Wpestate_Global_Payments; //get access to the class object instance
remove_action( 'woocommerce_thankyou', array($Wpestate_Global_Payments,'order_attach') );
remove_filter( 'woocommerce_checkout_fields', array($Wpestate_Global_Payments,'custom_override_checkout_fields') );
remove_filter('woocommerce_create_account_default_checked', '__return_true');
然后使用插件,这里:https://github.com/herewithme/wp-filters-extras 两种方法我都试过了:
方法 2:
remove_filters_with_method_name( 'woocommerce_thankyou', 'order_attach' );
remove_filters_with_method_name( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
remove_filters_with_method_name( 'woocommerce_create_account_default_checked', '__return_true' );
方法 3:
remove_filters_for_anonymous_class( 'woocommerce_thankyou', 'Wpestate_Global_Payments', 'order_attach' );
remove_filters_for_anonymous_class( 'woocommerce_checkout_fields', 'Wpestate_Global_Payments', 'custom_override_checkout_fields' );
remove_filters_for_anonymous_class( 'woocommerce_create_account_default_checked', 'Wpestate_Global_Payments', '__return_true' );
class Wpestate_Global_Payments {
public $stripe_payments;
public $is_woo;
public $userID;
public $user_email;
function __construct() {
$this->is_woo = wprentals_get_option('wp_estate_enable_woo','') ;
$current_user = wp_get_current_user();
$this->userID = $current_user->ID;
$this->user_email = $current_user->user_email;
add_filter( 'woocommerce_cart_item_permalink','__return_false');
add_action( 'wp_ajax_wpestate_woo_pay', array( $this, 'wpestate_woo_pay') );
add_action( 'wp_ajax_mopriv_wpestate_woo_pay', array( $this, 'wpestate_woo_pay') );
add_filter( 'woocommerce_thankyou_order_received_text', array($this, 'wpestate_woocommerce_thankyou_order_received_text'),10,2 );
add_action( 'woocommerce_before_single_product', array($this, 'wpestate_product_redirect') );
add_action( 'woocommerce_product_query', array($this, 'wpestate_custom_pre_get_posts_query' ));
add_action( 'woocommerce_order_status_completed', array($this, 'wpestate_payment_complete') );
add_action( 'woocommerce_order_status_processing', array($this, 'wpestate_payment_complete') );
//EVERYTHING WORKS ONLY WHEN THE 3 LINES BELOW ARE COMMENTED OUT
//add_action( 'woocommerce_thankyou', array($this,'order_attach') );
//add_filter( 'woocommerce_checkout_fields', array($this,'custom_override_checkout_fields') );
//add_filter('woocommerce_create_account_default_checked', '__return_true');
任何人都可以提供有关如何在functions.php 中为每个操作插入remove_action 和remove_filter 以删除/取消挂钩我目前在插件文件中注释掉的3 个操作/过滤器的任何见解吗?
【问题讨论】:
标签: wordpress woocommerce