Site logo

Archived topic

Elements + WC Hooks

3 replies · Started by mamin on December 19, 2021

Viewing posts 1–4 of 4

Hi,
I'm trying to add some buttons in the single product page to another url but I can't get the code to work in Elements (It works if placed in Code Snippets)

Getting 'There has been a critical error on this website. Learn more about troubleshooting WordPress.' after I enter the code.

Code was taken from another forum post here:

add_action( 'woocommerce_after_add_to_cart_button', function() {
    $url = get_post_meta( get_the_ID(), 'demourl1', true );

    if ( $url ) :
    ?>
        <a class="button" href="<?php echo $url; ?>">Your button text</a>
    <?php
    endif;
} );

Settings:
Location > Product > All Products
https://freeimage.host/i/7iPym

Appreciate if someone can highlight what I'm doing wrong.

Hi there,

Are you pertaining to placing this exact code to the Hook element?

If so, Hook element isn't meant to be used as an alternative to Code Snippets or Child theme's functions.php.

Hook elements are mainly for presentation purposes, meaning, they're meant only to insert simple HTML and PHPs to the theme's hook locations.

If you wish this code on Hook Element, you'll have to do it without the add_action function like this - https://share.getcloudapp.com/04uLG40w

Thanks. Got it.

Sorry to sidetrack, but:
1. How I do add some spacing between the Add To Cart/New Button 1/New Button 2
2. How fix the buttons' width to be the same as the -+Qty & Add to cart button

Can you open 2 new topics for each of your new questions?

I'll mark this one resolved.

Thanks.

This archived topic is closed to new replies.