Skip to content

Instantly share code, notes, and snippets.

@roykho
Created June 5, 2014 21:02
Show Gist options
  • Save roykho/ec36afdf004f5efcf7a9 to your computer and use it in GitHub Desktop.
Save roykho/ec36afdf004f5efcf7a9 to your computer and use it in GitHub Desktop.
WooCommerce: Link external products to detail product page from product category list
add_filter( 'woocommerce_loop_add_to_cart_link', 'product_cat_external', 10, 2 );
function product_cat_external( $html, $product ) {
if ( $product->product_type === 'external' ) {
return '<a href="' . get_post_permalink( $product->id ) . '" rel="nofollow" data-product_id="' . esc_attr( $product->id ) . '" data-product_sku="' . esc_attr( $product->get_sku() ) . '" class="button add_to_cart_button product_type_variable">View Detail</a>';
} else {
return $html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment