2013-06-25 139 views
0

目前,我正在爲會員產品使用Woocommerce插件。例如,我希望能夠點擊主頁上的縮略圖並直接轉到亞馬遜。目前它的設置是這樣的,一旦點擊它,我的網站上的產品詳細信息頁面。從那裏你可以到達亞馬遜頁面。然而,點擊次數越少越好。Woocommerce產品的自定義字段網址選項縮略圖

所以我在content-product.php頁面找到了鉤子。我所做的是將所有內容都包裝在一個URL中,並使用自定義字段添加到URL中。不按預期工作。會發生什麼情況是,只有在使用銷售閃存選項之一時,URL纔會轉到亞馬遜。關閉時,該URL不會轉到亞馬遜,而是轉到我網站上的產品頁面。我不知道放置URL包裝的地方。

所以我試圖尋找當前控制縮略圖的<a href="<?php the_permalink(); ?>">。我將函數追溯到woocommerce-template.php文件。那就是我陷入死衚衕的地方。我不確定當前縮略圖的位置。

這是我修改後的代碼,在內容product.php頁作品部分:

<div class="thumbnail-wrapper"> 
     <a href="<?php echo get_post_meta($post->ID, 'URLThumb', true); ?>"> 
     <?php 
      /** 
      * woocommerce_before_shop_loop_item_title hook 
      * 
      * @hooked woocommerce_show_product_loop_sale_flash - 10 
      * @hooked woocommerce_template_loop_product_thumbnail - 10 
      */ 
      do_action('woocommerce_before_shop_loop_item_title'); 
     ?> 
     </a> 
</div> 

這裏是縮略圖功能,我似乎無法進一步深入,找到現有<a href="<?php the_permalink(); ?>">改變。這是在woocommerce-template.php頁面上。

if (! function_exists('woocommerce_template_loop_product_thumbnail')) { 

/** 
* Get the product thumbnail for the loop. 
* 
* @access public 
* @subpackage Loop 
* @return void 
*/ 
function woocommerce_template_loop_product_thumbnail() { 
    echo woocommerce_get_product_thumbnail(); 
} 
} 

回答

0

想通了一個工作。由於SalesFlash圖像是被觸發的圖像,我只是使用空白的PNG圖像覆蓋產品圖像的頂部。把我所有的產品都變成了銷售物品,它很有效。不完美,但我不需要銷售圖標。

但是如果有人確實知道正確的編程解決方案,我會改變它。謝謝。

-1

本上的內容product.php爲我工作不求回報的元數據

<div class="thumbnail-wrapper"><a href="<?php echo $product->product_url; ?>"> 
    <?php 

      /** 
      * woocommerce_before_shop_loop_item_title hook 
      * 
      * @hooked woocommerce_show_product_loop_sale_flash - 10 
      * @hooked woocommerce_template_loop_product_thumbnail - 10 
      */ 
      do_action('woocommerce_before_shop_loop_item_title'); 
     ?> </a> 
    </div 

我也做了同樣的事情中環路/添加到cart.php的「添加更多」 和 「詳細信息」 中的線21 get_permalink()和57 $link分別替換它們像這樣的按鈕: LINE 27

$details = sprintf('<a href="%s" rel="nofollow" title="%s" class="details">%s</a>', get_permalink(), apply_filters('yit_details_button', __('Details', 'yit')), apply_filters('yit_details_button', __('Details', 'yit'))); 

替換$產品 - > product_url 和在管線57

$add_to_cart = sprintf('<a href="%s" rel="nofollow" class="view-options" title="%s">%s</a>', apply_filters('yit_external_add_to_cart_link_loop', $link, $product), $label, $label); 

get_permalink()更換再次$產品 - > product_url $鏈接。 我沒有問題,直到現在。我想知道你是否最終找到了一個明確的解決方案,所以我們可以爲thumnails和產品圖像做同樣的事情,而不在其上添加空白圖像。我沒有太多的代碼,所以如果有人知道如何將一個外部woocommerce.php

文件位置:可溼性粉劑內容/主題/「您的主題」 /主題/ woocommerce正面page.Thank你

1

文件名上的產品圖片鏈接。php

解決方案:通過查詢產品類型來定位外部產品,當外部產品在$ product_url中循環時,以及在簡單/變量時在get_permalink()中循環。此代碼還說明了在新選項卡中打開外部產品的情況。

我打算髮布代碼看起來像之前的版本的一個版本,然後再添加我的添加+修改。在我的主題中,我粘貼的第一行代碼存在於woocommerce.php的第374行(這取決於你的主題,並且有些主題可能沒有修改woocommerce.php文件,如果是這樣的話,只需拖動woocommerce .PHP到從插件主題目錄

碼添加/修改前:

function woocommerce_template_loop_product_thumbnail() { 

global $product, $woocommerce_loop; 


$i = 0; 
$attachments = array(); 

$attachments[] = get_post_thumbnail_id(); 
$attachments = array_merge($attachments, $product->get_gallery_attachment_ids()); 

$original_size = wc_get_image_size('shop_catalog'); 


if ($woocommerce_loop['view'] == 'masonry_item') { 
    $size = $original_size; 
    $size['height'] = 0; 
    YIT_Registry::get_instance()->image->set_size('shop_catalog', $size); 
} 

switch ($woocommerce_loop['products_layout']) { 

    case 'zoom': 
     if(isset($attachments[1])) { 

      echo '<a href="' . get_permalink() . '" class="thumb">' . woocommerce_get_product_thumbnail() . '</a>'; 
      echo '<div class="attachments-thumbnail">'; 
      while($i < 3){ 
       if(! isset($attachments[ $i ])) break; 
       $src = wp_get_attachment_image_src($attachments[ $i ], 'shop_catalog'); 
       $active = ($i == 0) ? 'active' : ''; 
       echo '<div class="single-attachment-thumbnail ' . $active . '" data-img="' . $src[0] . '">'; 
       yit_image("id=$attachments[$i]&size=shop_thumbnail&class=image-hover"); 
       echo '</div>'; 
       $i++; 
      } 
      echo '</div>'; 
     } 
     else { 
      echo '<a href="' . get_permalink() . '" class="thumb">' . woocommerce_get_product_thumbnail() . '</a>'; 
     } 
     break; 

    case 'flip': 
     if(isset($attachments[1])) { 
      echo '<a href="' . get_permalink() . '" class="thumb backface"><span class="face">' . woocommerce_get_product_thumbnail() . '</span></a>'; 
      echo '<span class="face back">'; 
      yit_image("id=$attachments[1]&size=shop_catalog&class=image-hover"); 
      echo '</span></a>'; 
     } 
     else { 
      echo '<a href="' . get_permalink() . '" class="thumb"><span class="face">' . woocommerce_get_product_thumbnail() . '</span></a>'; 
     } 
     break; 
} 

碼添加/修改後:

function woocommerce_template_loop_product_thumbnail() { 

global $product, $woocommerce_loop; 

if(!is_single()) { 
    if($product->is_type('external')){ 
    $product_url = $product->get_product_url() . '"target="_blank""'; 
     } else($producenter code heret_url = get_permalink()); 
} else ($product_url = get_permalink()); 

$i = 0; 
$attachments = array(); 

$attachments[] = get_post_thumbnail_id(); 
$attachments = array_merge($attachments, $product->get_gallery_attachment_ids()); 

$original_size = wc_get_image_size('shop_catalog'); 


if ($woocommerce_loop['view'] == 'masonry_item') { 
    $size = $original_size; 
    $size['height'] = 0; 
    YIT_Registry::get_instance()->image->set_size('shop_catalog', $size); 
} 

switch ($woocommerce_loop['products_layout']) { 

    case 'zoom': 
     if(isset($attachments[1])) { 

      echo '<a href="' . $product_url . '" class="thumb">' . woocommerce_get_product_thumbnail() . '</a>'; 
      echo '<div class="attachments-thumbnail">'; 
      while($i < 3){ 
       if(! isset($attachments[ $i ])) break; 
       $src = wp_get_attachment_image_src($attachments[ $i ], 'shop_catalog'); 
       $active = ($i == 0) ? 'active' : ''; 
       echo '<div class="single-attachment-thumbnail ' . $active . '" data-img="' . $src[0] . '">'; 
       yit_image("id=$attachments[$i]&size=shop_thumbnail&class=image-hover"); 
       echo '</div>'; 
       $i++; 
      } 
      echo '</div>'; 
     } 
     else { 
      echo '<a href="' . $product_url . '" class="thumb">' . woocommerce_get_product_thumbnail() . '</a>'; 
     } 
     break; 

    case 'flip': 
     if(isset($attachments[1])) { 
      echo '<a href="' . $product_url . '" class="thumb backface"><span class="face">' . woocommerce_get_product_thumbnail() . '</span></a>'; 
      echo '<span class="face back">'; 
      yit_image("id=$attachments[1]&size=shop_catalog&class=image-hover"); 
      echo '</span></a>'; 
     } 
     else { 
      echo '<a href="' . $product_url . '" class="thumb"><span class="face">' . woocommerce_get_product_thumbnail() . '</span></a>'; 
     } 
     break; 
} 

程式碼:

改性
if($product->is_type('external')){ 
    $product_url = $product->get_product_url() . '"target="_blank""'; 
     } else($product_url = get_permalink()); 
} else ($product_url = get_permalink()); 

代碼:

與已在上面添加的代碼外,替換()與$ product_url get_permalink的所有實例。

+0

請保持不相關的網址出現可能被視爲垃圾郵件的答案。謝謝。 – Drew

相關問題