Advertisement
sparkweb

FoxyShop: Subscription as a Variation Setup

Jan 17th, 2012
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. //This is a way to allow your customers to select their subscription frequency
  2. //Create a dropdown variation called "Delivery Frequency" and then create a hidden input as seen below for each of the entries
  3. //This code goes in foxyshop-single-product.php before the end of the form
  4.  
  5. //CUSTOM SUBSCRIPTION CODE HERE
  6. echo '<input type="hidden" name="x:sub_frequency1" id="frequency_holder1_' . $product['id'] . '" value="sub_frequency' . foxyshop_get_verification("sub_frequency", "1m") . '" />'."\n";
  7. echo '<input type="hidden" name="x:sub_frequency2" id="frequency_holder2_' . $product['id'] . '" value="sub_frequency' . foxyshop_get_verification("sub_frequency", "2m") . '" />'."\n";
  8. echo '<input type="hidden" name="x:sub_frequency3" id="frequency_holder3_' . $product['id'] . '" value="sub_frequency' . foxyshop_get_verification("sub_frequency", "3m") . '" />'."\n";
  9.  
  10. //Writes Javascript
  11. ?>
  12. <script type="text/javascript">
  13. jQuery(document).ready(function($) {
  14.     $("select.variation-delivery-frequency").bind("change ready", function() {
  15.         var currentval = $(this).prop("selectedIndex");
  16.         var product_id = $(this).parents("form").attr("id");
  17.         product_id = product_id.replace("foxyshop_product_form_","");
  18.         setFrequency(currentval, product_id);
  19.     });
  20.     function setFrequency(fr, product_id) {
  21.         fr++;
  22.         $("#fs_sub_frequency_" + product_id).val(fr+"m").attr("name",$("#frequency_holder" + fr + "_" + product_id).val());
  23.     }
  24.     //Run on Initialization
  25.     $("select.variation-delivery-frequency").each(function() {
  26.         var currentval = $(this).prop("selectedIndex");
  27.         var product_id = $(this).parents("form").attr("id");
  28.         product_id = product_id.replace("foxyshop_product_form_","");
  29.         setFrequency(currentval, product_id);
  30.     });
  31. });
  32. </script>
  33. <?php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement