首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >搜索结果页面中来自wordpress插件的remove_action

搜索结果页面中来自wordpress插件的remove_action
EN

Stack Overflow用户
提问于 2015-10-02 09:57:13
回答 2查看 208关注 0票数 1

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

代码语言:javascript
复制
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个操作“为商店页”,仅搜索结果页。我该怎么做?

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

代码语言:javascript
复制
public function WC_PSAD() { 
        if(!isset($_GET["s"]) ){        
        $this->init();          } 
    }

谢谢你的回答!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-02 10:02:12

你可以直接用is_search()

代码语言:javascript
复制
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 );
}
票数 1
EN

Stack Overflow用户

发布于 2015-10-02 10:12:08

基于@vard的答案,但是有倒转的行为:(这两种方法都应该有效)

代码语言:javascript
复制
<?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 );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32904803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档