DrMTR
DrMTR

Reputation: 509

How to place content from function in My Account in Woocommerce?

Hi i have this function inserted into functions.php in my theme:

function woocommerce_after_account_navigation(){ 
$html = '<h3>Title</h3>'; 
$html.='<li><a href="link">Text1</a></li>'; 
$html.='<li><a href="link">Text2</a></li>'; 
echo $html; 
}

and have placed this hook into navigation.php file from WooCommerce templates

<?php do_action( 'woocommerce_after_account_navigation' ); ?>

but seems that dont show nothing from content that i placed into functions.php

Can someone help me what is wrong with this hook ?

Upvotes: 1

Views: 442

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254212

Youn don't need to change anything in the My account templates (as you are using an existing hook)… To get your custom content displayed, you should need to make it this way:

add_action( 'woocommerce_after_account_navigation', 'custom_content_after_account_navigation' );
function custom_content_after_account_navigation(){ 
    $html = '<h3>Title</h3>'; 
    $html.='<li><a href="link">Text1</a></li>'; 
    $html.='<li><a href="link">Text2</a></li>'; 
    echo $html; 
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested on WooCommerce 3 and works.

This custom content will be displayed below the My Account Menu

Upvotes: 1

Related Questions