Support » Plugin: WooCommerce » Attribute link removed product and image link

  • Resolved unknownsouls

    (@unknownsouls)


    Hi, I have a custom attribute named ‘ State’ that is being called by the code below from your webpage.

    I have two issues:
    1. The product image and product title links have been removed and now linked to ‘State’ which is confusing for customers. Is there a way to move the link back to the product title /product image?

    2. The result from the input of the state (e.g California) is linked which is a great way to filter but the term itself ‘State’ appears.

    For example, it shows State: California, I would like it to just show California while hiding State and keeping the link on California for filtering purposes.

    Thanks for your time.

    /**
    * Display product attribute archive links
    */
    add_action( ‘woocommerce_before_shop_loop_item_title’, ‘wc_show_attribute_links’,5);

    // if you’d like to show it on archive page, replace “woocommerce_product_meta_end” with “woocommerce_shop_loop_item_title”

    function wc_show_attribute_links() {
    global $post;
    $attribute_names = array( ‘pa_state’ ); // Add attribute names here and remember to add the pa_ prefix to the attribute name

    foreach ( $attribute_names as $attribute_name ) {
    $taxonomy = get_taxonomy( $attribute_name );

    if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
    $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 = ‘‘. $term->name . ‘‘;
    array_push( $terms_array, $full_line );
    }
    echo $taxonomy->labels->name . ‘ ‘ . implode( $terms_array, ‘, ‘ );
    }
    }
    }
    }

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Hi there,

    This code is supposed to add new elements to the page, not to remove anything, if that’s the case, then maybe your theme is modifying the way the hooks are used.

    What if you test this snippet with a WP default theme?

    Thanks for your reply.

    I have checked with TwentyTwenty Theme without success. The attribute name ‘State’ is linked to product title and image while they have no link.

    Thanks

    Plugin Support Mike S

    (@mikestraw)

    Hi @unknownsouls ,

    I just searched through the current WooCommerce code and I don’t see that code you listed inside the plugin, or any references to wc_show_attribute_links. Could that be coming from another plugin?

    Plugin Support Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.