简体   繁体   中英

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.

In my parent Porto theme there in the file: 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:

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.

1) Create woocommerce folder in the child theme.

2) Create loop folder inside woocommerce

3) Now copy loop-start.php from the parent theme and copy to the child theme woocommerce > loop folder.

4) Now comment out code that you want to remove by action.

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 );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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