2013-03-29 59 views
0

我需要更改用於外部產品的鏈接代碼以便進行woo commerce。對WooCommerce for WordPress的修改特色圖片鏈接

這是生成產品形象代碼:

<?php 
/** 
* Single Product Image 
* 
* @author  WooThemes 
* @package  WooCommerce/Templates 
* @version  2.0.3 
*/ 

if (! defined('ABSPATH')) exit; // Exit if accessed directly 

global $post, $woocommerce; 

?> 
<div class="images"> 

    <?php 
     if (has_post_thumbnail()) { 

      $image    = get_the_post_thumbnail($post->ID, apply_filters('single_product_large_thumbnail_size', 'shop_single')); 
     $image_title  = esc_attr(get_the_title(get_post_thumbnail_id())); 
     $image_link   = wp_get_attachment_url(get_post_thumbnail_id()); 
     $attachment_count = count(get_children(array('post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_type' => 'attachment'))); 

     if ($attachment_count != 1) { 
      $gallery = '[product-gallery]'; 
     } else { 
      $gallery = ''; 
     } 

     echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image), $post->ID); 

    } else { 

     echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src()), $post->ID); 

    } 
?> 

<?php do_action('woocommerce_product_thumbnails'); ?> 

所以我只想因此,如果有人點擊圖片更換了圖像鏈接到外部鏈接網址,就會前往外部鏈接而不是圖像

代碼這樣做的爆破是添加到購物車代碼中,但我不知道如何將它應用到圖像:

<?php 
/** 
* Loop Add to Cart 
* 
* @author  WooThemes 
* @package  WooCommerce/Templates 
* @version  1.6.4 
*/ 

if (! defined('ABSPATH')) exit; // Exit if accessed directly 

global $product; 
?> 

<?php if (! $product->is_in_stock()) : ?> 

    <a href="<?php echo apply_filters('out_of_stock_add_to_cart_url', get_permalink($product->id)); ?>" class="button"><?php echo apply_filters('out_of_stock_add_to_cart_text', __('Read More', 'woocommerce')); ?></a> 

<?php else : ?> 

<?php 
    $link = array(
     'url' => '', 
     'label' => '', 
     'class' => '' 
    ); 

    $handler = apply_filters('woocommerce_add_to_cart_handler', $product->product_type, $product); 

    switch ($handler) { 
     case "variable" : 
      $link['url'] = apply_filters('variable_add_to_cart_url', get_permalink($product->id)); 
      $link['label'] = apply_filters('variable_add_to_cart_text', __('Select options', 'woocommerce')); 
     break; 
     case "grouped" : 
      $link['url'] = apply_filters('grouped_add_to_cart_url', get_permalink($product->id)); 
      $link['label'] = apply_filters('grouped_add_to_cart_text', __('View options', 'woocommerce')); 
     break; 
     case "external" : 
      $link['url'] = apply_filters('external_add_to_cart_url', get_permalink($product->id)); 
      $link['label'] = apply_filters('external_add_to_cart_text', __('Read More', 'woocommerce')); 
     break; 
     default : 
      if ($product->is_purchasable()) { 
       $link['url'] = apply_filters('add_to_cart_url', esc_url($product->add_to_cart_url())); 
       $link['label'] = apply_filters('add_to_cart_text', __('Add to cart', 'woocommerce')); 
       $link['class'] = apply_filters('add_to_cart_class', 'add_to_cart_button'); 
      } else { 
       $link['url'] = apply_filters('not_purchasable_url', get_permalink($product->id)); 
       $link['label'] = apply_filters('not_purchasable_text', __('Read More', 'woocommerce')); 
      } 
     break; 
    } 

    echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="%s button product_type_%s">%s</a>', esc_url($link['url']), esc_attr($product->id), esc_attr($product->get_sku()), esc_attr($link['class']), esc_attr($product->product_type), esc_html($link['label'])), $product, $link); 

?> 

對不起,我是這樣一個nube,但我不知道如何獲得鏈接代碼相同的'添加到購物車'的鏈接代碼,感謝您的幫助!

回答

0

何不產品image.php複製到你的主題或模板(這將覆蓋Woocommerce默認值),然後進行以下更改:

echo apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image), $post->ID); 

凡說

<a href="%s" 

更換%s與您的鏈接,或者您可以註冊一個自定義帖子字段,併爲您的每個產品有不同的鏈接。

如果這是您正在嘗試完成的所有操作,您可以忽略「添加到購物車」代碼。我可能會誤解 - 所以讓我知道如果它還不清楚。