【问题标题】:remove_action from wordpress plugin in search result page从搜索结果页面中的 wordpress 插件中删除操作
【发布时间】:2015-10-02 09:57:13
【问题描述】:

这是我想在搜索结果页面中禁用的插件代码。 它会影响我的结果并以一种奇怪的方式显示它们。所以我想在这个页面中禁用它。在这里。

class WC_PSAD
{

 public function WC_PSAD() {
    $this->init();
}

public function init () {
    add_filter('loop_shop_per_page', array( $this, 'limit_posts_per_page'),99);

    //Fix Responsi Theme.
    add_action( 'a3rev_head', array( $this, 'remove_responsi_action'), 11 );
    add_action( 'woo_head', array( $this, 'remove_responsi_action'), 11 );
    add_action( 'wp_head', array( $this, 'remove_woocommerce_pagination'), 10 );
    add_action( 'woocommerce_after_shop_loop', array( $this, 'woocommerce_pagination') );

    //Check if shop page
    add_action( 'woocommerce_before_shop_loop', array( $this, 'check_shop_page'), 1 );

    // For Shop page
    add_action( 'woocommerce_before_shop_loop', array( $this, 'start_remove_orderby_shop'), 2 );
    add_action( 'woocommerce_before_shop_loop', array( $this, 'end_remove_orderby_shop'), 40 );
    add_action( 'woocommerce_before_shop_loop', array( $this, 'dont_show_product_on_shop'), 41 );
    add_action( 'woocommerce_after_shop_loop', array( $this, 'rewrite_shop_page'), 12 );

我只想为搜索结果页面删除这 4 个操作“FOR SHOP PAGE”。 请问我该怎么做?

编辑:编辑:我所要做的就是检查参数 url:

public function WC_PSAD() { 
        if(!isset($_GET["s"]) ){        
        $this->init();          } 
    }

感谢您的回答!

【问题讨论】:

    标签: php wordpress class


    【解决方案1】:

    你可以使用is_search():

    if(!is_search()) {
        // For Shop page
        add_action( 'woocommerce_before_shop_loop', array( $this, 'start_remove_orderby_shop'), 2 );
        add_action( 'woocommerce_before_shop_loop', array( $this, 'end_remove_orderby_shop'), 40 );
        add_action( 'woocommerce_before_shop_loop', array( $this, 'dont_show_product_on_shop'), 41 );
        add_action( 'woocommerce_after_shop_loop', array( $this, 'rewrite_shop_page'), 12 );
    }
    

    【讨论】:

    • 好主意!但什么也没有发生。我测试了包含所有的“add_action()”,它仍然在搜索结果页面中显示这个插件。
    【解决方案2】:

    基于@vard 的回答,但行为相反:(两种方法都应该有效)

    <?php
    if( is_search() ) {
        // Remove actions on search page
        remove_action( 'woocommerce_before_shop_loop', array( $this, 'start_remove_orderby_shop'), 2 );
        remove_action( 'woocommerce_before_shop_loop', array( $this, 'end_remove_orderby_shop'), 40 );
        remove_action( 'woocommerce_before_shop_loop', array( $this, 'dont_show_product_on_shop'), 41 );
        remove_action( 'woocommerce_after_shop_loop', array( $this, 'rewrite_shop_page'), 12 );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-26
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-31
      相关资源
      最近更新 更多