Add Group WC Completed Customer to functions.php?

Posted in

Hello!

I am using your awesome Group WC Completed Customer plugin (https://github.com/itthinx/groups-wc-completed-customer).

I’m trying to reduce the number of plugins I use on my site (I have 44 – eesh!) Is it possible to add the code for this plugin to my functions.php file? I tried to add this code, but it caused a 500 error on my site:


/** GROUPS WOOCOMMERCE COMPLETED CUSTOMER */

/**
* Plugin class.
*/
class Groups_WC_Completed_Customer {

/**
* Adds our action on plugins_loaded.
*/
public static function boot() {
add_action( ‘plugins_loaded’, array(__CLASS__, ‘plugins_loaded’ ) );
}

/**
* Adds our action on completed order status if WooCommerce and Groups are present.
*/
public static function plugins_loaded() {
if ( function_exists( ‘wc_get_order’ ) && class_exists( ‘Groups_User_Group’ ) ) {
add_action( ‘woocommerce_order_status_completed’, array( __CLASS__, ‘woocommerce_order_status_completed’ ) );
}
}

/**
* Adds the customer to the ‘Customer’ group (or another group as requested by the groups_wc_completed_customer_group_name filter).
* The group is created on the fly.
*
* @param int $order_id
*/
public static function woocommerce_order_status_completed( $order_id ) {
if ( $order = wc_get_order( $order_id ) ) {
if ( $user_id = $order->get_customer_id() ) {
$name = apply_filters( ‘groups_wc_completed_customer_group_name’, ‘Customer’ );
if ( $group = Groups_Group::read_by_name( $name ) ) {
$group_id = $group->group_id;
} else {
$group_id = Groups_Group::create( array( ‘name’ => $name ) );
}
if ( $group_id ) {
if ( !Groups_User_Group::read( $user_id, $group_id ) ) {
Groups_User_Group::create( array( ‘group_id’ => $group_id, ‘user_id’ => $user_id ) );
}
}
}
}
}
}
Groups_WC_Completed_Customer::boot();

Any help is appreciated!

Thank you,

Michelle

2 Responses to Add Group WC Completed Customer to functions.php?

  1. Michelle August 27, 2018 at 4:03 pm #

    Thank you so much, George! This is very helpful!

  2. George August 14, 2018 at 1:14 pm #

    Hi Michelle,

    It would need some modifications in order to be added to functions.php, but even if you add this and remove the plugin, it would still count as a plugin.
    In terms of performance, you won’t notice any difference.
    Furthermore, badly written plugins( and themes ) affect the performance more than the total number of plugins does. Actually the total number of plugins shouldn’t affect the performance at all IMO.

    I would recommend you to update your PHP version to 7.x.x, if your plugins are compatible, which gives a proven performance boost. A search for “php 5.6 vs 7 performance WordPress” will give you enough info on that. Also update your plugins regularly. Last but not least, if possible create a staging copy of your site and enable WP debugging in case there are issues to be taken care of.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share