Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Link to chosen variable product from category page

$
0
0

Replies: 0

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)


Viewing all articles
Browse latest Browse all 59525

Trending Articles