Nick DeMayo
Nick DeMayo

Reputation: 1086

Override Function In WordPress Plugin Widget

I need to override a setting in a widget included in a WordPress plugin (the plugin is woocommerce). I've found in the plugin's widget code where I need to make the change (for the product_categories widget, I want to add a $cat_args['depth'] = 1; so that I only see the parent categories) and everything works fine, but I want to be able to do it in a way so that if the plugin ever updates, it doesn't wipe out the change. I have a custom theme that I have developed...is there any way to make the change in that theme so that I can still update woocommerce safely?

Upvotes: 0

Views: 1073

Answers (1)

scibuff
scibuff

Reputation: 13755

The only way to do that would be to ask the Widget developer to do something like this:

$cat_args_depth = 1;
$cat_args_depth =  apply_filters('woocommerce_cat_args_depth', $cat_args_depth );
$cat_args['depth'] = $cat_args_depth;

and then you could just use

add_filter( 'woocommerce_cat_args_depth', function( $cat_args_depth ) { 
    $cat_args_depth = 2; // your value
    return $cat_args_depth ;
});

Upvotes: 1

Related Questions