我以前使用過這裏描述的解決方案:remove_action From PHP Class用於刪除WooCommerce成員資格插件中的操作。remove_action來自WooCommerce會員中的PHP類
但是,該解決方案不再有效,因爲WooComemerce已更改成員資格插件背後的代碼。
所以這是新的代碼。
主營woocommerce-memberships.php
public function includes() {
// load post types
require_once($this->get_plugin_path() . '/includes/class-wc-memberships-post-types.php');
// load user messages helper
require_once($this->get_plugin_path() . '/includes/class-wc-memberships-user-messages.php');
// load helper functions
require_once($this->get_plugin_path() . '/includes/functions/wc-memberships-functions.php');
// init general classes
$this->rules = $this->load_class('/includes/class-wc-memberships-rules.php', 'WC_Memberships_Rules');
$this->plans = $this->load_class('/includes/class-wc-memberships-membership-plans.php', 'WC_Memberships_Membership_Plans');
$this->emails = $this->load_class('/includes/class-wc-memberships-emails.php', 'WC_Memberships_Emails');
$this->user_memberships = $this->load_class('/includes/class-wc-memberships-user-memberships.php', 'WC_Memberships_User_Memberships');
$this->capabilities = $this->load_class('/includes/class-wc-memberships-capabilities.php', 'WC_Memberships_Capabilities');
$this->member_discounts = $this->load_class('/includes/class-wc-memberships-member-discounts.php', 'WC_Memberships_Member_Discounts');
$this->restrictions = $this->load_class('/includes/class-wc-memberships-restrictions.php', 'WC_Memberships_Restrictions');
主要實例
function wc_memberships() {
return WC_Memberships::instance();
}
從包括類-WC-成員-restrictions.php文件
/**
* Returns the general content restrictions handler.
*
* @since 1.9.0
*
* @return null|\WC_Memberships_Posts_Restrictions
*/
public function get_posts_restrictions_instance() {
if (! $this->posts_restrictions instanceof WC_Memberships_Posts_Restrictions) {
$this->posts_restrictions = wc_memberships()->load_class('/includes/frontend/class-wc-memberships-posts-restrictions.php', 'WC_Memberships_Posts_Restrictions');
}
return $this->posts_restrictions;
}
然後,在類-WC-成員短柱-restrictions.php
public function __construct() {
// decide whether attempting to access restricted content has to be redirected
add_action('wp', array($this, 'handle_restriction_modes'));
// restrict the post by filtering the post object and replacing the content with a message and maybe excerpt
add_action('the_post', array($this, 'restrict_post'), 0);
如何刪除了 'the_post' 行動?
到目前爲止,我已經在functions.php的主題文件如下:
function weteach_remove_actions(){
if(is_singular('post')) {
if(function_exists('wc_memberships')){
remove_action('the_post', array(wc_memberships()->restrictions, 'restrict_post'));
}
}
return;
}
add_action('the_post', 'weteach_remove_actions', 1);
,給了我一個「空白頁」誤差。
空白頁面意味着您的網站出現錯誤,請在wp-config中打開WP_DEBUG以查看您遇到的錯誤並首先解決該錯誤。 – davey
嗨,謝謝你的安澤。我剛剛打開了WP_DEBUG,但仍然出現空白屏幕。我也嘗試過「add_action('wp','weteach_remove_actions',1);」而不是og「add_action('the_post','weteach_remove_actions',1);」 –
也嘗試打開'WP_DEBUG_LOG'以將錯誤記錄到'wp-content/debug.log'。雖然我想我發現這段代碼在主要的'woocommerce-memberships.php'文件中缺少'get_restrictions_instance()',所以我沒有正確訪問'post_restrictions'。請檢查我的編輯。 – helgatheviking