mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-03 12:12:25 +08:00
10 lines
413 B
Text
10 lines
413 B
Text
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'wc_image_link_external_url', 100, 2 );
|
|
|
|
function wc_image_link_external_url( $html, $post_thumbnail_id ) {
|
|
global $product;
|
|
if ( ! $product->is_type( 'external' ) ) return $html;
|
|
$url = $product->add_to_cart_url();
|
|
$pattern = "/(?<=href=(\"|'))[^\"']+(?=(\"|'))/";
|
|
$html = preg_replace( $pattern, $url, $html );
|
|
return $html;
|
|
}
|