ttn_
ttn_

Reputation: 346

How to check if YITH Woocommerce Wishlist is activated in theme

I'm creating a theme with yith woocommerce wishlist which has the following:

if( ! function_exists( 'WooCommerce' ) ){ function check_yith_enable_or_disable(){ echo do_shortcode( "[yith_wcwl_add_to_wishlist]" ); } add_action( 'woocommerce_after_shop_loop_item', 'check_yith_enable_or_disable', 10 ); }

However this breaks the site if the yith woocommerce wishlist plugin is not activated. How can I check if the yith woocommerce wishlist plugin is activated?

Upvotes: 0

Views: 2662

Answers (4)

user10782719
user10782719

Reputation:

One of these should work fine;

For checking free version only:

if( class_exists( 'YITH_WCWL_Privacy' ) )
    {
        // YITH Woocommerce Wishlist plugin is active
    }

For checking premium version only:

if( class_exists( 'YITH_WCWL_Premium' ) )
    {
        // YITH Woocommerce Wishlist Premium plugin is active
    }

For checking any of them is active:

if( class_exists( 'YITH_WCWL' ) )
    {
        // YITH Woocommerce Wishlist (free or premium) plugin is active
    }

Upvotes: 1

Swapnali
Swapnali

Reputation: 1299

WordPress includes a function called <?php is_plugin_active() ?> that allows you to check if the specified plugin is active.

The is_plugin_active() can be used like this -

<?php
    if( is_plugin_active( 'plugin-folder/main-plugin-file.php' ) )
    {
        // Plugin is active
    }  ?>

To check yith woocommerce wishlist plugin is activation use this code -

<?php if(is_plugin_active('yith-woocommerce-wishlist/init.php'))
      {
           //plugin is activated 
            echo 'Plugin is Activated';
      }
      else
      {
          //plugin is not activated
            echo 'Plugin is not activated';
      } ?>

for reference check-

Function Reference/is plugin active

Checking dependent plugin is active

Upvotes: 1

Naveen
Naveen

Reputation: 198

For this use function

<?php include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); ?>
<?php is_plugin_active($plugin) ?>

or more detail check https://codex.wordpress.org/Function_Reference/is_plugin_active

Upvotes: 1

Ankur Bhadania
Ankur Bhadania

Reputation: 4158

Used is_plugin_active() to check plugin is active or not

Used Of is_plugin_active()

In the Admin Area:

<?php is_plugin_active($plugin) ?>

In the front end, in a theme, etc...

<?php include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); ?>
<?php $plugin='plugin-directory/plugin-file.php'; ?>
<?php is_plugin_active($plugin) ?>

Return Values

True if plugin is activated, else false.

For YITH WooCommerce Wishlist in front End

 <?php include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); ?>
 <?php $plugin='yith-woocommerce-wishlist/init.php'; ?>
 <?php if(is_plugin_active($plugin)){
          //plugin is activated
        }else{
          //plugin is not activated
        } ?>

Upvotes: 1

Related Questions