Conditional Purchase Order Option

fc_joshfc_josh FoxyCart Team
in Help edited August 2010
I am needing the PO option to only show for certain products or product category. Can someone help me with some javascript or coding that can pull this off?

Thanks in advance!
Comments
  • lukeluke FoxyCart Team
    Hey ministrypixel. Something like this should work for you:
    jQuery(document).ready(function(){
    var showPO = false;
    for(var i=0;i<fc_json.products.length;i++) {
        if (fc_json.products[i].code == 'sku1234') {
            showPO = true;
        }
    }
    if (!showPO) {
      jQuery("#fc_payment_method_purchase_order_container").hide();
    }
    });
    

    You could also check against the category or the product name or whatever. If you have firebug, take a look at the fc_json object to get some ideas.

    Hope that helps.
  • fc_joshfc_josh FoxyCart Team
    Luke,
    I modified the code to only show PO option for a certain category, but it doesn't seem to work. Maybe I didn't make the correct changes:
    <script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function(){
    var showPO = false;
    for(var i=0;i<fc_json.category.length;i++) {
    if (fc_json.category.code == 'Client Stores') {
    showPO = true;
    }
    }
    if (!showPO) {
    jQuery("#fc_payment_method_purchase_order_container").hide();
    }
    });
    </script>
    

    Thank you so much for your help!
  • lukeluke FoxyCart Team
    Hey pixel. Do you have FireBug? If so, run this in the console on the checkout page: fc_json

    Then click on that object to get a view for how things are organized in the JSON. The code as you have it assumes there are an array of categories but there is only an array or products.

    Also, I think my original post got eaten a bit (vanilla does that some times so you have to put spaces in between [ and ])

    Try this for your for loop:
    for(var i=0;i<fc_json.products.length;i++) {
    if (fc_json.products[ i ].category == 'Client Stores') {
    showPO = true;
    }
    }
    

    Also, is "Client Stores" the category code or the category name? You'll want to use the category code when you add it to the cart and check for it in the json.

    Hope that helps.
Sign In or Register to comment.