如何在woocommerce wordpress网站上移动SKU?
问题描述:
我正在寻找一些woocommerce帮助。我正在建立一个视频下载网站。而且客户非常特别,他在店里想要的东西。默认情况下,SKU位于底部,价格位于顶部。如何在woocommerce wordpress网站上移动SKU?
我能找到的代码移动为了使价格
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 45);
现在我有这样的:
所以,我是试图找到类似的SKU,我认为它应该看起来像。
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_SKU', 45);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_SKU', 10);
我是超新的修改woocommerce和任何帮助将非常感激。
答
的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+上测试过并且可以正常工作。
你是直接编辑Woocommerce文件吗?正确的做法是重写主题中的woocommerce模板.. https://www.skyverge.com/blog/how-to-override-woocommerce-template-files/ –
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
不,我不直接编辑Woocommerce文件。我只是将代码添加到我的主题文件夹中的functions.php文件中。一旦我得到它的工作,我读了一个插件,我可以使用它将跟踪我所有的代码,甚至在一个Woocomerce /主题更新。 – Michael