Hello I am writing my little plugin for WordPress.

And I have a function (filter), which I call in the function.php file and it works fine. (hides the selected payment method, if the basket contains goods from a certain category)

add_filter('woocommerce_available_payment_gateways','filter_gateways'); function filter_gateways($gateways){ $payment_NAME = 'paypal'; // <-- some payment method $category_ID_1 = '6'; // <-- some category of products global $woocommerce; foreach ($woocommerce->cart->cart_contents as $key => $values ) { $terms = get_the_terms( $values['product_id'], 'product_cat' ); foreach ($terms as $term) { if($term->term_id == $category_ID_1){ unset($gateways[$payment_NAME]); break; } break; } } return $gateways;} 

Next question - how can I use this filter in my plugin? For I want to transfer some values ​​from the base there. If I just place it in my function file, then nothing works.

I ask for advice, and do not cook for ignorance, I'm just a beginner.

  • I will clarify - this function works in the functions.php file in the theme folder and I want to run in my plugin folder - Taras Bezdushnuy

1 answer 1

Everything is simple - you need to put this code entirely at the end of the main file of your plugin. To the file where the title is written

 `/* Plugin Name: ....... ......... */`