If you are using Groups plugin by @itthinx to restrict content, and you want your users to enter a code to give them access to groups, this is a possible solution.
[php]
/*
Plugin Name: Groups Codes
Plugin URI: https://www.eggemplo.com
Description: Groups Codes
Author: Antonio Blanco
Version: 1.0
Author URI: https://www.eggemplo.com
*/
class Groups_Codes_Plugin {
/**
* This array contains the pairs: code => group_id
* You need to change it with your own codes and groups id.
*/
public static $codes_table = array(
‘0001’ => 1,
‘0010’ => 2,
‘0011’ => 3
);
public static function init() {
add_action( ‘init’, array( __CLASS__, ‘wp_init’ ) );
}
public static function wp_init() {
add_shortcode( ‘groups_codes’, array( __CLASS__, ‘groups_codes_shortcode’ ) );
add_shortcode( ‘groups-codes’, array( __CLASS__, ‘groups_codes_shortcode’ ) );
}
public static function groups_codes_shortcode( $atts, $content = null ) {
$codes_table = self::$codes_table;
In this case, we are going to extend the ‘vc_row’ element to apply the ‘groups_can’ and ‘groups_can_not’ Groups shortcodes.
Adjusting the Theme
By adding the following lines to your themes functions.php, this new property will show in the admin row settings popup.
[php]
vc_add_param("vc_row", array(
"type" => "textfield",
"group" => "Groups",
"class" => "",
"heading" => "groups_can",
"param_name" => "groups_can",
‘description’ => ‘The capability attribute is required and is used to indicate one or more capabilities separated by comma.’
));
vc_add_param("vc_row", array(
"type" => "textfield",
"group" => "Groups",
"class" => "",
"heading" => "groups_can_not",
"param_name" => "groups_can_not",
‘description’ => ‘The capability attribute is required and is used to indicate one or more capabilities separated by comma.’
));
[/php]
Now the Row element has two new attributes on the ‘Groups’ tab:
Each element within Visual Composer has its own template and these templates can be overruled using your own theme templates. In this case vc_row.php.
1.- Create a new folder “vc_templates” in your theme or child-theme.
2.- Copy vc_row.php from /wp-content/plugins/js_composer/includes/templates/shortcodes/ to your newly created folder.
3.- Now we are going to change this vc_row.php, this is the code that I propose:
Backup your WordPress installation files and database.
Install and activate the Woocommerce Group Pricing plugin
Add the new plugin you have received and activate it:
Go to Plugins > Add New > Upload and click the Browse… button to select the plugin’s zip file, usually woogrouppricing-x.y.z.zip (x, y and z are the plugin’s current version numbers).
After that proceed to activate the plugin.
If you have errors, review the plugin’s page located here: https://www.eggemplo.com/plugins/groups2mailchimp for similar problems and the proposed solutions posted in the comments.
SETUP
Requirements
This plugin requires:
Woocommerce > 2.2.x
Group > 1.4.x
Setup Woocommerce Group Pricing
If you have not done so already, install and activate the plugin. See Installation section.
Check the settings on the Woocommerce > Group Pricing submenu and adjust them.
Product Discount Method:
You can select between rate or amount method.
Apply to:
You can apply the discount to regular price or to sale price if exists.
If in several groups:
If the user is in multiple groups, you can select a criterial to select the discount group.
Groups discount:
This discount is applied for each product.
Leave empty if no group discount should be applied (default setting).
Example with rate method: Indicate 0.1 for 10% discounts on every product.
More features:
If you need to apply custom discounts per categories and/or products, you can do it in the edit category/product page.
UPDATE
If you have received or downloaded an updated version of the Woocommerce Group Pricing plugin, follow these
instructions to update it:
Backup
Back up your WordPress installation files and database.
Upgrade to the new release
Upgrading requires to replace the plugin.
To update, the plugin must be deactivated, deleted and the new release uploaded and activated. These
are the steps involved:
Go to Plugins > Installed Plugins, click Deactivate on the Woocommerce Group Pricing plugin, then click Delete to remove it.
Go to Plugins > Add New > Upload and click the Browse… button to select the new release’s zip file, and click on the Install Now button. After it has been installed, activate the plugin.
BASIC USAGE
Once the plugin is installed, enabled and configured, it begins to run.
According to the group that belongs the visitor will see a store with discount prices or not, so you can set direct discounts to wholesales, Premium users, ….
An example according to the below settings:
DOCUMENTATION
The documentation and examples for the Woocommerce Group Pricing plugin and the others plugin are
available on the following pages:
If you are using Groups plugin by @itthinx and you need to set restrictions to posts (or another post type), you can use this code as reference:
function restricted_save_post($post_id, $post) {
if(!is_object($post) || !isset($post->post_type)) {
return;
}
switch($post->post_type) { // Do different things based on the post type
case "post":
// add your default capabilities
Groups_Post_Access::create( array( 'post_id'=>$post_id, 'capability'=>'Premium' ) );
break;
default:
// Do other stuff
}
}
add_action('save_post', 'restricted_save_post', 1, 2);
This code adds the ‘Premium’ capability to all new posts when they are created.
Groups Mailchimp Integration. Synchronizes Groups plugin with MailChimp. Select MailChimp list and a group and automatically new groups and users are added to this mailchimp group.
Documentation
See documentation page for more information about setup and basic usage.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.