• Posted by mceades 5 months ago.
  • There are 5 posts. The latest reply is from leewillis77
  • resolved
  • WordPress version: 2.7
  • WP e-Commerce version: 3.6.*

No tags yet.

The free community support forum is a place where WP e-Commerce users can work with other WP e-Commerce users to help one another get their shops up and running. There is no gaurantee that an Instinct staff member will respond to your topic within the free forum.

Acting out, swearing and threats are not tolerated, please play nice, we are all doing the best we can with the resources available.

 

  1. mceades
    New Member

    Hello,

    I'm looking for some help as to how to get started in using radio buttons to select products variations. Where do I start?

    Thanks

    Matt

    Posted 5 months ago #

  2. gonafr
    New Member

    I am also trying to do this, i will be thankful for some help...

    Posted 4 months ago #

  3. gonafr
    New Member

    With a little of javascript code we can do it.

    <script type="text/javascript" charset="utf-8">
    
    	$(document).ready(function(){
    
    		$('.wpsc_select_variation').each(function(i, select){
    		    var $select = $(select);
    		    $select.find('option').each(function(j, option){
    		        var $option = $(option);
    		        // Create a radio:
    		        var $radio = $('<input type="radio" />');
    		        // Set name and value:
    		        $radio.attr('name', $select.attr('name')).attr('value', $option.val());
    		        // Set checked if the option was selected
    		        if ($option.attr('selected')) $radio.attr('checked', 'checked');
    		        // Insert radio before select box:
    		        $select.before($radio);
    		        // Insert a label:
    		        $select.before(
    		          $("<label />").attr('for', $select.attr('name')).text(' '+$option.text())
    		        );
    		        // Insert a <br />:
    		        $select.before(" | ");
    		    });
    		    $select.remove();
    		});
    	});
    
    </script>
    Posted 4 months ago #
  4. Trusted
    leewillis77
    Resident Expert

    You can do this "properly" by amending the code in your WPEC theme. Look in single_product.php in your chosen theme. This block of code generates the drop-downs, and you should be able to re-write it as radio buttons pretty easily - saves all the messing around changing after the page has loaded

    <?php /** the variation group HTML and loop */?>
    					<div class="wpsc_variation_forms">
    						<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
    							<p>
    								<label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label>
    								<?php /** the variation HTML and loop */?>
    								<select class='wpsc_select_variation' name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
    								<?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
    									<option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
    								<?php endwhile; ?>
    								</select>
    							</p>
    						<?php endwhile; ?>
    					</div>
    					<?php /** the variation group HTML and loop ends here */?>
    Posted 4 months ago #
  5. Trusted
    leewillis77
    Resident Expert

    PS. Nice bit of jQuery though ;)

    Posted 4 months ago #

RSS feed for this topic

Reply

You must log in to post.