简体   繁体   English

从子主题中的父主题中删除钩子 function

[英]Remove hook function from parent theme in child theme

I've read several guides and posts here on stackoverflow, but I can't see why on my case it isn't working.我已经在 stackoverflow 上阅读了几篇指南和帖子,但我不明白为什么在我的情况下它不起作用。

In my parent Porto theme there in the file: themes/porto/woocommerce/loop/loop-start.php在我的父波尔图主题中,文件中有: themes/porto/woocommerce/loop/loop-start.php

there is this piece of code:有这段代码:

if ( 'list' == $view_mode || ( isset( $porto_settings['product-desc'] ) && $porto_settings['product-desc'] ) ) {
    if ( ! has_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt' ) ) {
        add_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt', 9 );
    }
} elseif ( has_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt' ) ) {
    remove_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt', 9 );
}

So in my child theme's functions.php I have tried:所以在我的孩子主题的functions.php我试过了:

add_action('after_setup_theme', 'remove_my_parent_theme_function');

function remove_my_parent_theme_function() {
    remove_action('woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt', 9);
}

I have also tried:我也试过:

add_action('init', 'remove_my_parent_theme_function');

function remove_my_parent_theme_function() {
    remove_action('woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt', 9);
}

I have also tried other stuff that I've lost track of them, but I don't get why it is not working.我也尝试过其他我忘记的东西,但我不明白为什么它不起作用。

You can override this themes/porto/woocommerce/loop/loop-start.php file your child theme.您可以覆盖此themes/porto/woocommerce/loop/loop-start.php文件您的子主题。

1) Create woocommerce folder in the child theme. 1) 在子主题中创建woocommerce文件夹。

2) Create loop folder inside woocommerce 2) 在 woocommerce 中创建loop文件夹

3) Now copy loop-start.php from the parent theme and copy to the child theme woocommerce > loop folder. 3)现在从父主题复制loop-start.php并复制到子主题woocommerce > loop文件夹。

4) Now comment out code that you want to remove by action. 4) 现在注释掉要通过操作删除的代码。

if ( 'list' == $view_mode || ( isset( $porto_settings['product-desc'] ) && $porto_settings['product-desc'] ) ) {
    if ( ! has_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt' ) ) {
        //add_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt', 9 );
    }
} elseif ( has_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt' ) ) {
    remove_action( 'woocommerce_after_shop_loop_item_title', 'porto_woocommerce_single_excerpt', 9 );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM