0

I can Create Additional Custom Button on single product page with following feature. 1st- my button work with product Attribute. if attribute id is "custom_button" value is "yes" then show custom button on signal product page and if value is "no" button hidden on product page. 2nd- custom button name is attribute id "custom_button_name" value = Button Text. 3rd- custom button url is attribute id "custom_button_url" value = "http://www.websiteurl.com"when click on button open new tab

i have create custom button on magento site with following code. this code work with product attributes how to use this code in woocommerce

<?php if($_product->getCustom_button()){ //yes or no button?>

<button type="button" title="<?php echo $_product>getCustom_button_name() ;?>"

class="action primary tocart"

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 } ?>

1 Answer 1

2

To achieve something like this you should change the woocommerce_after_shop_loop_item hook, which is where the add to cart button is added.

To replace it with custom behavior, first, you remove the button, then add your custom button in its place.

add_action( 'init', 'remove_add_to_cart_button' );
function remove_add_to_cart_button() {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}

add_action( 'woocommerce_after_shop_loop_item', 'new_add_to_cart_button' );
function new_add_to_cart_button() {
    // Your button code.
}

You can find more about WooCommerce hooks here: https://docs.woocommerce.com/wc-apidocs/hook-docs.html.

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.