• I’m trying to call a woocommerce hook via add_action. This code works like a charm if inserted directly into functions.php. However, it doesn’t execute if used within XYZ PHP.

    Any recommendations for a pretty unexpirienced PHP beginner as why this is the case? Do I have to put the shortcode calling this at a particular part of the frontend in order for it to work? Does add_action not work at all with XYZ? Thank you!

    add_action(‘woocommerce_after_shop_loop_item_title’, ‘display_artist_link_grid’, 9 );

    function display_artist_link_grid() {
    $artist_link = get_field(‘artist_link’);
    if ($artist_link) {
    $title = $artist_link[‘title’];
    $url = $artist_link[‘url’];
    echo ‘‘ . esc_html($title) . ‘‘;
    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The code snippets were executed only during the rendering of a page.

    Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. So add_action can’t be used in snippet code.

    You can write this code into functions.php of your activated theme.

    I don’t understand this. Surely the whole point of WordPress add_action is that the action can be added anywhere in code? For example, the hook may be specific to a user and so you can’t just generically add it in the functions.php file.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add_action hook-call not working’ is closed to new replies.