Link to chosen variable product from category page
-
Hi
I am trying to add a “View product” button to the category page in WooCommerce. For variable products I would like the chosen variable (users can choose it in dropdown) to follow along, so when you click the link, you go to the chosen variant.
I have this to show the button:
function mycode_add_more_details_button_to_single() { add_action( 'woocommerce_after_shop_loop_item', 'mycode_display_more_details_button_to_single' ); } add_action( 'init', 'mycode_add_more_details_button_to_single' ); function mycode_display_more_details_button_to_single() { global $product; $url = $product->get_permalink(); $text = __( 'Se varen', 'mycode' ); $title = sprintf( __( 'Se mere om %s', 'mycode' ), $product->get_name() ); $class = sprintf( 'button add_to_cart_button product_type_%s', $product->get_type() ); $format = '<a href="%1$s" title="%2$s" class="single_add_to_cart_button button alt">%4$s</a>'; printf( $format, esc_url( $url ), esc_attr( $title ), esc_attr( $class ), esc_html( $text ) ); }
How can I add the chosen variable id?
I hope you can help. :o)
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Link to chosen variable product from category page’ is closed to new replies.