• Hello,

    I like to dis/enable a buy button depending if product X is in the shopping cart.
    At the moment i have all buy buttons disabled expect for product X, for this i edit wpsc-product_page and add disabled=”disabled” expect for product X.

    Now in functions.php i like to add a function which checks if shopping cart has product X, if so enable all buy buttons.

    Any ideas?

    http://wordpress.org/plugins/wp-e-commerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter DDT

    (@ddt)

    how do i get the product id of a product in shopping cart? This would help

    How are your javascript and css skills? It would be pretty easy with the current version of wp-e-commerce.

    This is how I would do it:

      Write a quick little AJAX function that checks to see if the product is in the cart.
      Add a little javascript that calls the AJAX function and gets the result.
      Select the button class you want to enable or disable.
      Set the enable or disable button using the selector from above.
    Thread Starter DDT

    (@ddt)

    hi jeff, thanks for thinking along.

    Your ajax approach sounds good, could you give me start for the ajax part?

    But as with the approach i am trying to use at this moment, do you know how to get the product id’s in the cart?

    Now i am using the wpsc_cart_item_name

    while(wpsc_have_cart_items()): wpsc_the_cart_item();
    		if( wpsc_cart_item_name() == "tickets 2014"){
    			echo "test tickets jquery to enabled other buttons";
    		}
    	endwhile;

    but if i put this code in a function in my theme/functions.php i can’t get wpsc_have_cart_items() to work. Am i missing a global wpsc variable or something? (already tried global $wpsc).

    thanks in advance,

    Thread Starter DDT

    (@ddt)

    hi jeff,

    I am testing with

    <?php
    
    function disable_btns() {
        global $wpsc;
        echo "Test trigger";
        while (wpsc_have_cart_items()): wpsc_the_cart_item();
            if (wpsc_cart_item_name() == "tickets 2014") {
                echo "test tickets jquery to enabled other buttons";
                ob_start();
                ?>
                <script>
                    jQuery(document).ready(function($) {
                        $('input[type="submit"]').removeAttr('disabled');
                    });
                </script>
                <?php
    
            }
        endwhile;
        return ob_get_contents();
    }
    
    add_action('wp_footer', 'disable_btns');

    but the hook isn’t right. Which hook should i use?

    what’s showing up in your page source?

    Thread Starter DDT

    (@ddt)

    FYI and for others, i am using the following “workable” code

    <?php while (wpsc_have_cart_items()): wpsc_the_cart_item();
            if (wpsc_cart_item_name() == "Tickets 2014") {
                    echo "tesst Tickets 2014";
                }
    
            $js ='
            <script>
            jQuery(document).ready(function($) {
                    //alert("Just do it");
                    $(\'input:submit\').removeAttr("disabled");
            });
            </script>';
            echo $js;
                 ?>

    regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to enable the buy button only if product X is in the shopping cart?’ is closed to new replies.