2017-09-21 98 views
1

我正在尋找一些woocommerce幫助。我正在建立一個視頻下載網站。而且客戶非常特別,他在店裏想要的東西。默認情況下,SKU位於底部,價格位於頂部。如何在woocommerce wordpress網站上移動SKU?

enter image description here

我能找到的代碼移動爲了使價格

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10); 
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 45); 

現在我有這樣的:

enter image description here

所以,我是試圖找到類似的SKU,我認爲它應該看起來像。

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_SKU', 45); 
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_SKU', 10); 

我是超新的修改woocommerce和任何幫助將非常感激。

+0

你是直接編輯Woocommerce文件嗎?正確的做法是重寫主題中的woocommerce模板.. https://www.skyverge.com/blog/how-to-override-woocommerce-template-files/ –

+0

SKU顯示在模板[單一產品/ meta.php](https://github.com/woocommerce/woocommerce/blob/release/3.1/templates/single-product/meta.php)與其他數據,如類別,標籤... 所以你應該刪除它[通過您的主題覆蓋此woocommerce模板](https://docs.woocommerce.com/document/template-structure/)。然後將其添加回到您方便的掛鉤功能中。 – LoicTheAztec

+0

不,我不直接編輯Woocommerce文件。我只是將代碼添加到我的主題文件夾中的functions.php文件中。一旦我得到它的工作,我讀了一個插件,我可以使用它將跟蹤我所有的代碼,甚至在一個Woocomerce /主題更新。 – Michael

回答

0

的SKU顯示在模板single-product/meta.php與像分類,標籤等數據...

步驟1 - 你應該從這個模板中刪除。

這可以通過將其複製到yourtheme/woocommerce/single-product/meta.php來完成overriding this woocommerce template via your theme

一旦刪除SKU的一部分,模板代碼如下:

<?php 
/** 
* Single Product Meta 
* 
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/meta.php. 
* 
* HOWEVER, on occasion WooCommerce will need to update template files and you 
* (the theme developer) will need to copy the new files to your theme to 
* maintain compatibility. We try to do this as little as possible, but it does 
* happen. When this occurs the version of the template file will be bumped and 
* the readme will list any important changes. 
* 
* @see   https://docs.woocommerce.com/document/template-structure/ 
* @author  WooThemes 
* @package  WooCommerce/Templates 
* @version  3.0.0 
*/ 

if (! defined('ABSPATH')) { 
    exit; 
} 

global $product; 

?> 
<div class="product_meta"> 
    <?php do_action('woocommerce_product_meta_start'); ?> 

    <?php echo wc_get_product_category_list($product->get_id(), ', ', '<span class="posted_in">' . _n('Category:', 'Categories:', count($product->get_category_ids()), 'woocommerce') . ' ', '</span>'); ?> 

    <?php echo wc_get_product_tag_list($product->get_id(), ', ', '<span class="tagged_as">' . _n('Tag:', 'Tags:', count($product->get_tag_ids()), 'woocommerce') . ' ', '</span>'); ?> 

    <?php do_action('woocommerce_product_meta_end'); ?> 
</div> 

步驟2 - 將重新排序的價格,把SKU早在其他位置的代碼。

您需要首先刪除現有的代碼(因爲它包含在這裏)。

下面是代碼:

add_action('woocommerce_single_product_summary', 'custom_single_product_summary_actions', 1); 
function custom_single_product_summary_actions(){ 

    // Reordering the price (done by you) 
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10); 
    add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 45); 

    // Put back the SKU: 
    add_action('woocommerce_single_product_summary', 'woocommerce_single_custom_sku', 9); 
    function woocommerce_single_custom_sku(){ 
     global $product; 

     if (wc_product_sku_enabled() && ($product->get_sku() || $product->is_type('variable'))) : 
     ?> 
      <p><span class="sku_wrapper"><?php esc_html_e('SKU:', 'woocommerce'); ?> <span class="sku"><?php echo ($sku = $product->get_sku()) ? $sku : esc_html__('N/A', 'woocommerce'); ?></span></span></p> 
     <?php 
     endif; 
    } 
} 

此功能發生在您的活動子主題(或主題)的function.php文件或也以任何插件文件。

所有代碼都在Woocommerce 3+上測試過並且可以正常工作。

+0

感謝您幫助LoicTheAztec,看起來這是正確的方向。但我現在有兩個問題。 SKU位於頂部,但底部也有一個。也因爲這是一個可變的產品。你可以有數字下載或運送DVD。每個人都有一個SKU。當我切換到其他產品時,我要保留的產品不會改變。但最底層的是。任何想法可能是什麼問題? – Michael

+0

謝謝! – Michael