Skip to content

Commit

Permalink
Woocommerce: Shortcode for displaying a link to account
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomollet committed Aug 7, 2017
1 parent 8e25ca9 commit d7d7605
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions inc/plugins/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ function woocommerce_cart_count_shortcode( $atts ) {
if(is_admin()) return '';

$defaults = array(
'icon_class' => 'glyphicon glyphicon-shopping-cart',
'icon_class' => 'glyphicon glyphicon-shopping-cart',
'empty_cart_text' => '',
'items_in_cart_text' => '',
'show_count' => true,
'show_amount' => true,
'link_class' => 'link-cart'
'show_amount' => true,
'link_class' => 'link-cart',
);
$atts = shortcode_atts( $defaults, $atts );

Expand Down Expand Up @@ -481,6 +481,40 @@ function woocommerce_cart_count_shortcode( $atts ) {
}
add_shortcode( 'woocommerce_cart_link', 'woocommerce_cart_count_shortcode' );

/**
* Shortcode for displaying a link to account
*
* @param $atts
*
* @return string
*/
function woocommerce_account_link_shortcode( $atts ) {
if(is_admin()) return '';

$defaults = array(
'icon_class' => 'glyphicon glyphicon-user',
'link_class' => 'link-account',
);
$atts = shortcode_atts( $defaults, $atts );

$icon_html = '<span class="'.$atts['icon_class'] . '"></span>';

$link_class = $atts['link_class'];
$link_url = "";

if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

$woocommerce_account_page_id = get_option( 'woocommerce_myaccount_page_id' );
$link_url = get_permalink( $woocommerce_account_page_id );
}

$html = '<a href="' . $link_url .'" class="'.$link_class.'">';
$html .= $icon_html . __('Account', 'woocommerce');
$html .= '</a>';
return $html;
}
add_shortcode( 'woocommerce_account_link', 'woocommerce_account_link_shortcode' );

/**
* Woocommerce: Related products number
*
Expand Down

0 comments on commit d7d7605

Please sign in to comment.