0

I'm trying to get a product id value inside a add to cart button. The below code works getting the value in an alert.

<script type="text/javascript">
jQuery(document).ready(function(e) {
    jQuery('#getChkBoxValues').click(function(){
        var chkBoxArray = [];
    jQuery('.checkbox-id:checked').each(function() {
            chkBoxArray.push(jQuery(this).val());
        });
    alert(chkBoxArray);
    });
});
</script>
<input type="button" value="Get Values" id="getChkBoxValues" />

Is there any way to get the value inside this button (below) where the number 5 is without any additional span, div, or script tags?

 <button id="product-addtocart-button" class="button btn-cart" onclick="location.href='<?php echo Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL); ?>checkout/cart/add?product=5&qty=1'"><span><span><?php echo $this->__('Add All to Cart') ?></span></span></button>
1
  • Are you using this code in product list page or view page?
    – Manikandan
    Commented May 9, 2016 at 7:35

1 Answer 1

0

You ca get the product id by this code

<button id="product-addtocart-button" class="button btn-cart" onclick="location.href='<?php echo Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL); ?>checkout/cart/add?product=<?php echo $_product->getId() ?>&qty=1'"><span><span><?php echo $this->__('Add All to Cart') ?></span></span></button>
2
  • Yeah, but this is a little different. This is an also bought module that one can select more than one item to add to the cart. I think it has to be client side with javascript? I tried getting it to work using the related products feature but the real add to cart button and this new button (that's only for the also bought products) get the same values. So I'm wanting to use a new custom button.
    – Freejoy
    Commented May 9, 2016 at 7:53
  • In one cart button itself you need all the product which are selected . right?
    – Manikandan
    Commented May 9, 2016 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.