我需要覆盖WordPress插件中包含的小部件中的设置(该插件是wooccommerce)。我在插件的小部件代码中发现了我需要进行更改的地方(对于product_categories小部件,我想添加$cat_args['depth']=1;这样我只能看到父类别),一切都很好,但我希望能够以这样的方式来做,即如果插件更新,它不会消除更改。我开发了一个自定义主题。。。有什么方法可以改变这个主题,这样我仍然可以安全地更新wooccommerce吗?
唯一的方法是让Widget开发人员做这样的事情:
$cat_args_depth = 1;
$cat_args_depth = apply_filters('woocommerce_cat_args_depth', $cat_args_depth );
$cat_args['depth'] = $cat_args_depth;
然后你就可以使用
add_filter( 'woocommerce_cat_args_depth', function( $cat_args_depth ) {
$cat_args_depth = 2; // your value
return $cat_args_depth ;
});