-
-
Save perezfigueroa/3359533 to your computer and use it in GitHub Desktop.
Display WooCommerce product attribute archive links on product page, right below the add to cart button.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WooCommerce Attribute Links | |
Description: Display product attribute archive links on product page, right below the add to cart button. | |
Version: 1.0 | |
Author: Coen Jacobs | |
Author URI: http://coenjacobs.me | |
*/ | |
add_action( 'woocommerce_after_add_to_cart_button', 'cj_show_attribute_links' ); | |
function cj_show_attribute_links() { | |
global $post; | |
$attribute_name = '<ATTRIBUTE_NAME>'; // Insert attribute name here | |
$terms = wp_get_post_terms( $post->ID, $attribute_name ); | |
$terms_array = array(); | |
if ( ! empty( $terms ) ) { | |
foreach ( $terms as $term ) { | |
$archive_link = get_term_link( $term->slug, $attribute_name ); | |
$full_line = '<a href="' . $archive_link . '">'. $term->name . '</a>'; | |
array_push( $terms_array, $full_line ); | |
} | |
echo implode( $terms_array, ', ' ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment