Don't like ads? PRO users don't see any ads ;-)

FoxyShop Product Donation Code

By: sparkweb on Sep 15th, 2011  |  syntax: JavaScript  |  size: 2.33 KB  |  hits: 125  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <script type="text/javascript" charset="utf-8">
  2. jQuery(function($) {
  3.        
  4.         var product_id = <?php echo $product['id']; ?>; //Stores the product ID
  5.         var open_price_field_name = "Donation_Amount"; //This is the name of your open price field
  6.         var radio_button_selectors_class = "variation-donation"; //This is the class assigned to your radio buttons
  7.         var custom_selector_dkey = "custom-price"; //This is the dkey that will make your custom price field show up
  8.        
  9.         //Add a x: to the front of the open price field so it doesn't show up in cart as a product attribute
  10.         $("#foxyshop_product_form_" + product_id + " input[name^='" + open_price_field_name + "']").attr("name", "x:" + $("#foxyshop_product_form_" + product_id + " input[name^='" + open_price_field_name + "']").attr("name"))
  11.  
  12.         //Runs every time the radio buttons are changed
  13.         $("." + radio_button_selectors_class).click(function() {
  14.                
  15.                 //If the "other" selection is made
  16.                 if ($("." + radio_button_selectors_class + ":checked").attr("displaykey") == custom_selector_dkey) {
  17.                        
  18.                         //Hide the display price
  19.                         $("#foxyshop_product_form_" + product_id + " .foxyshop_price").hide();
  20.                        
  21.                         //Get the new price from the Price Entry Field
  22.                         new_price = $("#foxyshop_product_form_" + product_id + " input[name^='x:" + open_price_field_name + "']").val();
  23.                        
  24.                         //Set the #price field name to then --OPEN-- hash to allow an open entry and stick in the contents of the new price
  25.                         $("#fs_price_" + product_id + "").attr("name", "price<?php echo foxyshop_get_verification('price', '--OPEN--'); ?>").val(new_price);
  26.                
  27.                 //If a preset price is selected
  28.                 } else {
  29.                        
  30.                         //Set the #price field name to the default price and the value to the x:original price value
  31.                         $("#fs_price_" + product_id + "").attr("name", $("#fs_price_" + product_id).attr("name")).val($("#originalprice_" + product_id + "").val());
  32.                        
  33.                         //Show the Price
  34.                         $("#foxyshop_product_form_" + product_id + " .foxyshop_price").show();
  35.                 }
  36.         });
  37.  
  38.         //Runs every time a key is pressed in the open price field
  39.         $("#foxyshop_product_form_" + product_id + " input[name^='x:" + open_price_field_name + "']").keyup(function() {
  40.                
  41.                 //Set the new price in the hidden form field
  42.                 $("#fs_price_" + product_id + "").attr("name", "price<?php echo foxyshop_get_verification('price', '--OPEN--'); ?>").val($(this).val());
  43.         });
  44.  
  45. });
  46. </script>