De-activation of plugin dependant on another - wordpress

I am writing a Woocommerce extension plugin and have managed to set it so Woocommerce must be installed and activated under the Wordpress admin pages.
If both Woocommerce and my extension plugin are activated and Woocommerce is de-activated, my plugin stays active.
How do I de-activate my plugin when Woocommerce is also de-activated?
Edit 1.
I have tried this, and other similar attempts. The hook is correct, but for some reason deactivate_plugins() does not deactivate the plugin that I am writing.
function custom_plugin() {
if (is_plugin_active('custom_plugin/custom_plugin.php')){
deactivate_plugins('custom_plugin/custom_plugin.php');
}
}
register_deactivation_hook( 'woocommerce/woocommerce.php', 'custom_plugin');

Try this below code your active theme OR custom plugin.
function custom_plugin_deactivation( $plugin, $data_value ) {
if ($plugin=="custom/custom.php")
{
deactivate_plugins('woocommerce/woocommerce.php');
}
}
add_action( 'deactivated_plugin', 'custom_plugin_deactivation', 10, 2 );

Related

Change the paypal item name in the PayPal Express Checkout plugin

I have a WordPress site using the PayPal Checkout plugin for woocommerce.
https://wordpress.org/plugins/woocommerce-gateway-paypal-express-checkout/
I need to change the PayPal item name and I'm using this code in the functions.php, it worked with the normal PayPal plugin but does not work with PayPal Express checkout.
add_filter( 'woocommerce_paypal_get_order_item_name', 'change_paypal_item_name', 10, 3 );
function change_paypal_item_name( $item_name, $order, $item ) {
return 'test';
}
Anyone know the function to change the item name with the PayPal Express checkout plugin?
From a quick look at the code, it seems woocommerce_paypal_express_checkout_get_details is a filter you can try implementing to modify the whole $details array

how to use a wp plugin as a theme part not as a plugin?

I am developing a word press theme and I have a free plugin which helps me to add new features to my theme. I want to use this plugin in this theme but I don't want to use it as a plugin and have to activate in plugins section. I want to use it as a theme part and disable activating or deactivating it. It will be activate automatically when theme set up.
If your theme uploaded somewhere then refer -> https://wordimpress.com/how-to-easily-require-plugins-for-your-wordpress-themes/
Or
add_action( 'admin_notices', 'my_theme_dependencies' );
function my_theme_dependencies() {
if( ! function_exists('plugin_function') )
echo '<div class="error"><p>' . __( 'Warning: The theme needs Plugin X to function', 'my-theme' ) . '</p></div>';
}
OR
if your theme is in local setup then you can use must-up plugin, for that refer -> https://codex.wordpress.org/Must_Use_Plugins
So if I understand correctly you want your plugin to be in Wordpress but you don't want it to be shown to anyone else or be able to deactivate it?
Try using this plugin, which will hide your plugin('s) from everyone - WP Hide Plugins.
Or add this to your functions.php file:
function hide_plugin_trickspanda() {
global $wp_list_table;
$hidearr = array('plugin-directory/plugin-file.php');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr)) {
unset($wp_list_table->items[$key]);
}
}
}
add_action('pre_current_active_plugins', 'hide_plugin_trickspanda');
Info to go with this code: rename the plugin name in the first line, also change the "plugin-directory/plugin-file.php" to the plugin file of your plugin and in the last line change the plugin name too.

Deactivate plugin on specific page

How I deactivate "WooCommerce Product Sort and Display LITE" plugin on search results page.Because it conflicts with search results.Can you please help me?
Thanks.
add_action( 'wp_print_scripts', 'my_deregister_javascript');
function my_deregister_javascript() {
if ( !is_page('Contact') ) {//pagename
wp_deregister_script( 'WooCommerce ' );//pluginname
}
}
it detect wooommerce script except contact page.

Wordpress Add_filter Priority Issue On 2 Different Custom Plugins (Metaboxes)

I recently developed 2 seperate wordpress plugins for one of my projects
Partners
Resource Library
Both plugins create custom post types fsb_partners and fsb_resource_library. And in both plugins I have created different metaboxes (partners plugin metabox contains one file field i.e. Logo and resource library plugin creates metabox with two file fields i.e. Audio and PDF).
I used following code to create metabox in each plugin:
add_filter( 'cmb_meta_boxes', array($this, "fsb_partners_metaboxes"), 999); ---> Partners Plugin
add_filter( 'cmb_meta_boxes', array($this, "fsb_resource_library_metaboxes"), 999); ---> Resource Library Plugin
Now only metabox at resource library plugin is visible and other is not. If I change the priority of partner plugin metabox to 9999 then it shows up but at the same time resource library plugins goes off.
I know it's wordpress's add_filter hook's priority issue, but am unable to get hands on it. Any help?
Fixed it myself. Just created a separate (common) function in my theme's functions.php as follows:
add_filter('cmb_meta_boxes', function( array $metaboxes = array() ) {
global $fsb_resource_library, $fsb_partner;
if( class_exists('fsb_resource_library') && is_object($fsb_resource_library) ) {
$metaboxes += $fsb_resource_library->fsb_resource_library_metaboxes();
}
if( class_exists('fsb_partners') && is_object($fsb_partner) ) {
$metaboxes += $fsb_partner->fsb_partners_metaboxes();
}
return $metaboxes;
});

Woocommerce clear cart after payment

I'm having trouble clearing my cart after payment but I'm using Woocommerce.
I used codes and plugin from an older site (before the major update in the beginning of the year) and that doesn't seem to work now on the new updated site.
This is the functions.php
// check for clear-cart get param to clear the cart
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
if ( isset( $_GET['clear-cart'] ) ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
}
In the thankyou.php that appears after succesfull payment this code is in there.
<!-- clear cart after successfull payment -->
jQuery(function($) {
$.post("http://ihavetakenoutmydomain.org?clear-cart",{},function(response){
var NewCart = $(response).find('#header-cart-inner');
$('#header-cart').html(NewCart);
var NewCartItems = $(response).find('.cart-items-inner');
$('.cart-items').html(NewCartItems);
});
});
I'm using the same theme as in the older version so the header-cart-inner and header-cart are the same.
But for some reason this doesn't work with the updated Wordpress and Woocommerce.
Does anyone know what the problem might be or have another solution for clearing the cart after succesfull payment? The thankyou page should only appear after successfull payment.
I forgot one thing
If I load the link "xxx://ihavetakenoutmydomain.org?clear-cart" on my browser the cart empties. So I guess the problem would be how to activate the link on the thankyou page without redirecting away from the thankyou page.
Best regards

Resources