-1

I'm trying to make a custom plugin, which will work with woocommerce. that is why i included woocommerce in my plugin with the help of this line of code

include(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php');

But I can not active my custom plugin. in the time of activating it says Fatal error: Cannot redeclare wc_get_container() (previously declared in /home/eteasnzs/mshopbd.com/wp-content/plugins/woocommerce/woocommerce.php:58) in /home/eteasnzs/mshopbd.com/wp-content/plugins/woocommerce/woocommerce.php on line 58

I did a little google and show there are several fatal errors like this function already declared..

Now my question is how can I solve this type of problem.. thanks and this my first question here... hope I will get a helpful solution....

Joshim
  • 11
  • 4

1 Answers1

1

It sounds like that file is being included multiple times, in which case you just need to change

include(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php');

to

include_once(WP_PLUGIN_DIR.'/woocommerce/woocommerce.php');

The include_once statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include statement, with the only difference being that if the code from a file has already been included, it will not be included again, and include_once returns true. As the name suggests, the file will be included just once.

dave
  • 62,300
  • 5
  • 72
  • 93