2

I have created Custom Button using following Code at themes/package/woocommerce/single-product/add-to-cart/simple.php

<?php 
    if($_product->getCustom_button()){ //yes or no button
?>
    <button type="button" title="<?php echo $_product->getCustom_button_name() ;?>" class="btn btn-default" onclick="window.open('<?php echo $_product->getCustom_button_url() ;?>')"><span><span><i class="icon-desktop"></i><?php echo $_product->getCustom_button_name() ;?></span></span></button>
<?php } ?>

but this code is not work properly. i want custom button work with product attributes. enter image description here

4
  • Please explain yourself little-bit more, share what is your intention to do and what issue you are facing right now.
    – mlimon
    Oct 12, 2017 at 10:48
  • when i have add above mention code simple.php show my page is blank and product image, footer and addtocard button and custom not showing an Oct 12, 2017 at 10:53
  • What is $_product, what does getCustom_button() do? Oct 12, 2017 at 11:58
  • i have use same code in magento site this code work perfectly and custom_button is attribute id Oct 13, 2017 at 17:14

2 Answers 2

1
add_action('woocommerce_after_add_to_cart_button','cmk_additional_button');
function cmk_additional_button() {
    echo '<button type="submit" class="button alt">Change me please</button>';
}

add this code in your Child theme functions.php

Try this code

0
0

You can use this code to add anything like button, text using this below code

function my_custom_content(){
    // get_the_ID() is product ID
    // echo anything you want
}
add_action( 'woocommerce_after_add_to_cart_button', 'my_custom_content' );
3
  • this code is not work Oct 12, 2017 at 11:24
  • May be you did not use it in correct way, this is the best solution to add custom content like button on the section you are looking for Oct 12, 2017 at 14:54
  • i want custom button in singal product page and i have past your code at themes/package/woocommerce/single-product/add-to-cart/simple.php Oct 13, 2017 at 17:11

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.