Using only jQuery and CiviCRM to create Members Only Pricing

Published
Mon, 02/13/2012 - 19:44
Written by

Comments

Mon, 02/13/2012 - 23:31

In reply to by anonymous_stub (not verified)

For me, it's easy D7 support... I have yet to find something I can use as a non-coder. All the options I've seen are for D6.

I'd use the code above, but I don't have the chops to convert the above code D7 compatible... maybe someone would perform that small act of kindness for me and others?

 

 

 

Very true while using wordpress platform MIH module will be better option even its good for Joomla.

Bayside lounge

Tue, 06/05/2012 - 12:23

In reply to by anonymous_stub (not verified)

Modified code for Drupal 6 and CiviCRM 4.1.2. The above code did not work for some reason. Note, it only works right now with radio and checkbox fields.

 

Block 1 has visibility for anonymous users. It removes all pricing options with word 'Member' in them. In effect, anonymous people don't get member pricing.

 

<script>
cj(document).ready(function() {
       //Find all labels containing the text 'Member' that are descendants of the element with id 'priceset'
     cj("#priceset").find("label:contains('Member')").each(function() {
               //Get the value of this labels for attribute. 
               var id = cj(this).attr('for');
               //If it has a value, this is one we want to remove
               if (id) {
                       //Remove the previous element which we know is an input
                   cj(this).prev().remove();        
                   //Remove this element as well
                   cj(this).remove();
       }
       });
});
 
</script>
 
Block 2 has visibility for Members (Members Role, sycned to Drupal user from CiviCRM). It hides all options that don't have word "Member" present. This in effect shows only Member-pricing for Members. The opposite of Block 1.
 
<script>
 
cj(document).ready(function() {
       //Find all labels containing the text 'Member' that are descendants of the element with id 'priceset'
      cj("#priceset").find("label:not(:contains('Member'))").each(function() {
               //Get the value of this labels for attribute. 
               var id = cj(this).attr('for');
               //If it has a value, this is one we want to remove
               if (id) {
                       //Remove the previous element which we know is an input
                   cj(this).prev().remove();        
                   //Remove this element as well
                   cj(this).remove();
       }
       });
});
 
</script>
 
Also, for those new to CiviCRM and jQuery, cj is a renamed jQuery object so it does not conflict with Drupal's jQuery. 
 
This code was developed by Corey Sunwold, http://coreysunwold.com/

 

Here's the code for the anonymous block modifided for Drupal 7. I added in a bit to remind users to login to get their member price

<script type="text/javascript">

    (function($) {

    $(document).ready(function() {


//This is our custom jQuery code

   

$("#priceset").find("label:contains('Members')").each(function(){

            var id = $(this).attr('for');

            if (id) {

                $(this).prev().remove();

                $(this).remove();

                    }

            });

    $("#priceset").prepend("<h3>If you are a member, log in for member prices</h3>");

//This is the end of our custom jQuery code

  }); 

  }) (jQuery);

</script>