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

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 Leave a comment

affiliates_is_affiliate_by_id

If you are using Affiliates by itthinx, and you need to display different content per affiliates, then you are in correct place 😉
This shortcode can help you:
add_shortcode ( 'affiliates_is_affiliate_by_id', 'affiliates_is_affiliate_by_id' );
function affiliates_is_affiliate_by_id($atts, $content = null) {
extract ( shortcode_atts ( array (
'id' => '0'
), $atts ) );
remove_shortcode ( 'affiliates_is_affiliate_by_id' );
$content = do_shortcode ( $content );
add_shortcode ( 'affiliates_is_affiliate_by_id', 'affiliates_is_affiliate_by_id' );
$output = "";
if (affiliates_user_is_affiliate ( get_current_user_id () )) {
if (affiliates_get_user_affiliate ( get_current_user_id () )[0] == $id) {
$output .= $content;
}
}
return $output;
}

Add this code in your functions.php theme file.
Example of use:
[affiliates_is_affiliate_by_id id="42"]
Only affiliate with id 42 can see this text.
[/affiliates_is_affiliate_by_id]
[affiliates_is_affiliate_by_id id="47"]
Only affiliate with id 47 can see this text.
[/affiliates_is_affiliate_by_id]

Posted on Leave a comment

[affiliates_username] shortcode

If you are using Affiliates by @itthinx and you need to display the referrer username, now you can use this shortcode:
add_shortcode( 'affiliates_username', 'affiliates_username_shortcode' );
function affiliates_username_shortcode( $atts ) {
  if ( !class_exists( "Affiliates_Service" ) ) {
    include_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
  }
  $output = "";
  $affiliate_id = Affiliates_Service::get_referrer_id();
  if ( $affiliate_id ) {
    if ( $affiliate_id !== affiliates_get_direct_id() ) {
      if ( $user_id = affiliates_get_affiliate_user( $affiliate_id ) ) {
        if ( $user = get_user_by( 'id', $user_id ) ) {
          $output .= $user->user_login;
        }
      }
    }
  }
  return $output;
}

Posted on Leave a comment

[aff_permanent_count] shortcode

If you are using Affiliates Pro / Enterprise with Affiliates Permanent by @itthinx, and you need to count how many customers are linked to an affiliate, this shortcode can help you:

add_shortcode( 'aff_permanent_count', 'aff_permanent_count' );
function aff_permanent_count( $atts ) {
global $wpdb;
$affiilate_id = Affiliates_Affiliate_WordPress::get_user_affiliate_id();
$meta_key = Affiliates_Permanent::REFERRER;
$meta_value = $affiilate_id;
$user_meta_query = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key=%s AND meta_value=%s", $meta_key, $meta_value ) );
return number_format_i18n($user_meta_query);
}