Posted on Leave a comment

Groups Codes

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: http://www.eggemplo.com
Description: Groups Codes
Author: Antonio Blanco
Version: 1.0
Author URI: http://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;

$output = "";
$options = shortcode_atts(
array(
‘redirect_to’ => null
),
$atts
);
if ( $user_id = get_current_user_id() ) {

if ( isset( $_REQUEST[‘submit’] ) ) {
if ( isset( $_REQUEST[‘groups_codes_code’] ) && wp_verify_nonce( $_REQUEST[‘groups_codes_code’], ‘groups_codes_form’ ) ) {
if ( isset( $_REQUEST[‘code’] ) && ( strlen( trim( $_REQUEST[‘code’] ) ) > 0 ) ) {
if ( isset( $codes_table[ trim( $_REQUEST[‘code’] ) ] ) ) {
$group_id = $codes_table[ trim( $_REQUEST[‘code’] ) ];
if ( Groups_User_Group::create( array( "user_id"=>$user_id, "group_id"=>$group_id ) ) ) {
$group = Groups_Group::read( $group_id );
$output .= ‘<p>’ . __( ‘You have been added to the "’ . $group->name . ‘" group.’ ) . ‘</p>’;
} else {
$output .= ‘<p>’ . __( ‘Invalid code.’ ) . ‘</p>’;
}
} else {
$output .= ‘<p>’ . __( ‘Invalid code.’ ) . ‘</p>’;
}
} else {
$output .= ‘<p>’ . __( ‘Invalid code.’ ) . ‘</p>’;
}
}
}

$output .= ‘<div class="groups-codes-container">’;
$output .= ‘<form action="">’;
$output .= ‘<input type="text" name="code" placeholder="’ . __( ‘Enter your code’ ) . ‘" />’;
$output .= ‘<input type="submit" name="submit" value="’ . __( ‘Submit’ ) . ‘" />’;
$output .= wp_nonce_field( ‘groups_codes_form’, ‘groups_codes_code’ );
$output .= ‘</form>’;
$output .= ‘</div>’;

} else {
$output .= __( ‘You need to be logged in before giving us a download code.’ );
}

return $output;
}
}

Groups_Codes_Plugin::init();
[/php]

You only need to change the $codes_table array with the codes and groups ids that you want.

You can download the plugin from Github.

Posted on Leave a comment

Using groups_can and groups_can_not with Visual Composer

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:

[php]
<?php
if ( ! defined( ‘ABSPATH’ ) ) {
die( ‘-1’ );
}

/**
* Shortcode attributes
* @var $atts
* @var $el_class
* @var $full_width
* @var $full_height
* @var $equal_height
* @var $columns_placement
* @var $content_placement
* @var $parallax
* @var $parallax_image
* @var $css
* @var $el_id
* @var $video_bg
* @var $video_bg_url
* @var $video_bg_parallax
* @var $parallax_speed_bg
* @var $parallax_speed_video
* @var $content – shortcode content
* @var $css_animation
* Shortcode class
* @var $this WPBakeryShortCode_VC_Row
*/
$el_class = $full_height = $parallax_speed_bg = $parallax_speed_video = $full_width = $equal_height = $flex_row = $columns_placement = $content_placement = $parallax = $parallax_image = $css = $el_id = $video_bg = $video_bg_url = $video_bg_parallax = $css_animation = ”;
$disable_element = ”;
$output = $after_output = ”;
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
extract( $atts );

wp_enqueue_script( ‘wpb_composer_front_js’ );

$el_class = $this->getExtraClass( $el_class ) . $this->getCSSAnimation( $css_animation );

$css_classes = array(
‘vc_row’,
‘wpb_row’,
//deprecated
‘vc_row-fluid’,
$el_class,
vc_shortcode_custom_css_class( $css ),
);

if ( ‘yes’ === $disable_element ) {
if ( vc_is_page_editable() ) {
$css_classes[] = ‘vc_hidden-lg vc_hidden-xs vc_hidden-sm vc_hidden-md’;
} else {
return ”;
}
}

if ( vc_shortcode_custom_css_has_property( $css, array(
‘border’,
‘background’,
) ) || $video_bg || $parallax
) {
$css_classes[] = ‘vc_row-has-fill’;
}

if ( ! empty( $atts[‘gap’] ) ) {
$css_classes[] = ‘vc_column-gap-‘ . $atts[‘gap’];
}

$wrapper_attributes = array();
// build attributes for wrapper
if ( ! empty( $el_id ) ) {
$wrapper_attributes[] = ‘id="’ . esc_attr( $el_id ) . ‘"’;
}
if ( ! empty( $full_width ) ) {
$wrapper_attributes[] = ‘data-vc-full-width="true"’;
$wrapper_attributes[] = ‘data-vc-full-width-init="false"’;
if ( ‘stretch_row_content’ === $full_width ) {
$wrapper_attributes[] = ‘data-vc-stretch-content="true"’;
} elseif ( ‘stretch_row_content_no_spaces’ === $full_width ) {
$wrapper_attributes[] = ‘data-vc-stretch-content="true"’;
$css_classes[] = ‘vc_row-no-padding’;
}
$after_output .= ‘<div class="vc_row-full-width vc_clearfix"></div>’;
}

if ( ! empty( $full_height ) ) {
$css_classes[] = ‘vc_row-o-full-height’;
if ( ! empty( $columns_placement ) ) {
$flex_row = true;
$css_classes[] = ‘vc_row-o-columns-‘ . $columns_placement;
if ( ‘stretch’ === $columns_placement ) {
$css_classes[] = ‘vc_row-o-equal-height’;
}
}
}

if ( ! empty( $equal_height ) ) {
$flex_row = true;
$css_classes[] = ‘vc_row-o-equal-height’;
}

if ( ! empty( $content_placement ) ) {
$flex_row = true;
$css_classes[] = ‘vc_row-o-content-‘ . $content_placement;
}

if ( ! empty( $flex_row ) ) {
$css_classes[] = ‘vc_row-flex’;
}

$has_video_bg = ( ! empty( $video_bg ) && ! empty( $video_bg_url ) && vc_extract_youtube_id( $video_bg_url ) );

$parallax_speed = $parallax_speed_bg;
if ( $has_video_bg ) {
$parallax = $video_bg_parallax;
$parallax_speed = $parallax_speed_video;
$parallax_image = $video_bg_url;
$css_classes[] = ‘vc_video-bg-container’;
wp_enqueue_script( ‘vc_youtube_iframe_api_js’ );
}

if ( ! empty( $parallax ) ) {
wp_enqueue_script( ‘vc_jquery_skrollr_js’ );
$wrapper_attributes[] = ‘data-vc-parallax="’ . esc_attr( $parallax_speed ) . ‘"’; // parallax speed
$css_classes[] = ‘vc_general vc_parallax vc_parallax-‘ . $parallax;
if ( false !== strpos( $parallax, ‘fade’ ) ) {
$css_classes[] = ‘js-vc_parallax-o-fade’;
$wrapper_attributes[] = ‘data-vc-parallax-o-fade="on"’;
} elseif ( false !== strpos( $parallax, ‘fixed’ ) ) {
$css_classes[] = ‘js-vc_parallax-o-fixed’;
}
}

if ( ! empty( $parallax_image ) ) {
if ( $has_video_bg ) {
$parallax_image_src = $parallax_image;
} else {
$parallax_image_id = preg_replace( ‘/[^\d]/’, ”, $parallax_image );
$parallax_image_src = wp_get_attachment_image_src( $parallax_image_id, ‘full’ );
if ( ! empty( $parallax_image_src[0] ) ) {
$parallax_image_src = $parallax_image_src[0];
}
}
$wrapper_attributes[] = ‘data-vc-parallax-image="’ . esc_attr( $parallax_image_src ) . ‘"’;
}
if ( ! $parallax && $has_video_bg ) {
$wrapper_attributes[] = ‘data-vc-video-bg="’ . esc_attr( $video_bg_url ) . ‘"’;
}
$css_class = preg_replace( ‘/\s+/’, ‘ ‘, apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, implode( ‘ ‘, array_filter( array_unique( $css_classes ) ) ), $this->settings[‘base’], $atts ) );
$wrapper_attributes[] = ‘class="’ . esc_attr( trim( $css_class ) ) . ‘"’;

$output .= ‘<div ‘ . implode( ‘ ‘, $wrapper_attributes ) . ‘>’;

// @eggemplo changes
if ( isset ( $groups_can ) && ( strlen( trim( $groups_can ) ) > 0 ) ) {
$content = do_shortcode( ‘[groups_can capability="’ . $groups_can . ‘"]’ . ( $content ) . ‘[/groups_can]’ );
}
if ( isset ( $groups_can_not ) && ( strlen( trim( $groups_can_not ) ) > 0 ) ) {
$content = do_shortcode( ‘[groups_can_not capability="’ . $groups_can_not . ‘"]’ . ( $content ) . ‘[/groups_can_not]’ );
}
// end – @eggemplo changes

$output .= wpb_js_remove_wpautop ($content);
$output .= ‘</div>’;
$output .= $after_output;

echo $output;
[/php]

This is the part of the code that we have changed:
[php]
// @eggemplo changes
if ( isset ( $groups_can ) && ( strlen( trim( $groups_can ) ) > 0 ) ) {
$content = do_shortcode( ‘[groups_can capability="’ . $groups_can . ‘"]’ . ( $content ) . ‘[/groups_can]’ );
}
if ( isset ( $groups_can_not ) && ( strlen( trim( $groups_can_not ) ) > 0 ) ) {
$content = do_shortcode( ‘[groups_can_not capability="’ . $groups_can_not . ‘"]’ . ( $content ) . ‘[/groups_can_not]’ );
}
// end – @eggemplo changes
[/php]

I hope this can help you !!!!

Posted on 3 Comments

Woocommerce Groups Pricing Documentation

Woocommerce Group Pricing

INSTALLATION

Backup

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: http://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.

    wrp-view

    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.

    wgp-settings

    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:

    wrp-product

    DOCUMENTATION

    The documentation and examples for the Woocommerce Group Pricing plugin and the others plugin are
    available on the following pages:

    • Woocommerce Group Pricing: This page
    • Groups : http://wordpress.org/plugins/groups/
    • Woocommerce: http://wordpress.org/plugins/woocommerce/
Posted on Leave a comment

Default posts restriction

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.

Good luck!

Posted on 8 Comments

Affiliates Groups

Set different rates according to the affiliate’s group.

Requirements

Download

Changelog

2.0:
  • It is not a custom method.
  • Added custom rates by products
1.0:
  • Initial version is a Custom Method

Setup

Once you have configured Groups, Affiliates and the Woocommerce integration (with custom method product_rates)
affg-groups
affg-affiliates-woocommerce-integration
affg-affiliates-settings

Install and activate the Affiliates Groups plugin.
In Affiliates->Groups you can set the rates.
affgroups-setting

If you need a custom rate by product, you can do it in product page.
affg-product

Posted on 5 Comments

Groups2MailChimp

groups2mailchimp

Groups MailChimp Integration

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.

Video demo

[youtube_sc url=reJg4YJdUTg width=460]

Download

You can download this plugin here.

External Links