Classic Commerce Github issue 131 discusses the problem where some WooCommerce extensions won’t activate unless they detect that WooCommerce is installed and active.
A filter was proposed to fool the extensions into thinking WC was active, but unfortunately it doesn’t work.
However, an empty placeholder plugin structured as woocommerce/woocommerce.php does work.
I created one and it enabled me to use the Wirecard payment gateway extension, which wouldn’t work when it didn’t believe WC was present and active. I had to set the version to a high number to stop ClassicPress trying to find updates for it on the WP repo. I set it to version 9999.0.
I can’t attach zips here but I attached it to a comment on the Github issue.
It is possible that a little plugin could be written to help people overcome this problem. If I get time, I’ll have a look at it myself. But here is the hint, if someone else wants to tackle the issue.
I wrote a little plugin that puts a note on the admin bar to show any active orders that have been made, so I found that the plugin needs a test as follows to check if Woocommerce exists.
/*
* Test to see if Woocommerce is active
*/
if ( is_plugin_active('woocommerce/woocommerce.php') ) {
add_action( 'admin_bar_menu', 'ocws_wcab_newmenu',20 );
} // end of testing for WooCommerce
I amended this as follows, so that it looks for either Woocommerce of Classic Commerce.
/*
* Test to see if either Woocommerce or Classic Commerce are active
*/
if ( (is_plugin_active('woocommerce/woocommerce.php')) || (is_plugin_active('classic-commerce/woocommerce.php')) ) {
add_action( 'admin_bar_menu', 'ocws_wcab_newmenu',1000 );
} // end of testing for WooCommerce or Classic Commerce
It should be possible to write a plugin that would force any other Woocommerce extension to accept Classic Commerce instead.
This would still require the user to have a dummy woocommerce in place for it to work. A compatibility plugin was discussed on Slack which led to this Gist that can be turned into a plugin named woocommerce/woocomerce.php
What do you mean about a “dummy woocommerce”? All this involves is adding it as a function within Classic Commerce, and then another function to remove it if CC is deactivated.
woocommerce/woocommerce.php Needs to exist in the plugin directory as CP will be looking for it when that function runs.
If the original WooCommerce is found then it will throw a fatal error so a dummy WooCommerce (A compatibility plugin so to speak) would need to be present in order for CP not to throw The plugin woocommerce/woocommerce.php has been deactivated due to an error: Plugin file does not exist. notice.
This is correct. A hook solution doesn’t work and this was noted in the Github issue linked above. All the file needs to contain is this:
<?php
/*
Plugin Name: WooCommerce Placeholder
Description: Makes WooCommerce extensions think WooCommerce is present and active.
Version: 9999.0
Requires at least: 4.9
Tested up to: 5.3
*/
And once this dummy plugin is installed, it must be activated of course.
Plugins can easily be renamed, and then your check for active_plugins doesn’t work.
The correct way to check for existence is using function_exists or class_exists.
But you don’t know what every piece of code out in the wild is using.
The ideal and preferred was is to check if a function or class exists but unfortunately some developers are still relying on the active_plugins check.
The issue we are trying to resolve is for those plugins that check on the active status - maybe @omukiguy and @james can throw more light on this on the best way forward.
Really is_plugin_active is not the best way to check, and also don’t work in the frontend (without including wp-admin/includes/plugin.php).
But we will face this problem for each plugin that have “extensions” plugins we are going to fork.
So… why not adding a filter before returning is_plugin_active?
Yes… it’s about changing CP core to help in those situations
I’ve made no much experiments but it seems to break nothing.
One of the main issues is that, as CC and WC both use the same woocommerce class, they cannot be installed and activated at the same time. For example, if CC is active and then you try to activate WC, you immediately get a fatal PHP error:
Fatal error: Cannot redeclare wc()
For those plugins looking for the existence of woocommerce/woocommerce.php, the WooCommerce Placeholder code mentioned by @anon95694377 should be all that’s required.
If CC is active, class_exists('woocommerce') will return true.
Good questions. I’m not really understanding the technical issues, but as an end user the idea of having to install a plugin to make another work is not ideal. Is this a temporary fix or do we see it as a permanent solution?