我正在制作一个网站,似乎产品sku被隐藏在产品页面中。我已经找到了如何将其添加到目录(商店)页面,但我需要它显示在产品页面内。
到目前为止,通过改变单一产品。php,我设法将其添加到页面的末尾(我们不想要的东西)或页面左上角的标题之前(我们也不想要的东西)。
我没有办法把它加在价格之前和产品名称下面。
主题的单一产品代码。php:
<?php
/**
* Single Product title
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/title.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 http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}
?>
<?php echo \'<div class="sku">\' . $product->sku . \'</div>\'; ?>
我添加了最后一行。
然而,关于主题/woocommerce/单一产品/meta。php我可以看到应该显示sku,而不是:
<?php
/**
* Single Product Meta
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( \'ABSPATH\' ) ) exit; // Exit if accessed directly
global $post, $product;
?>
<div class="product_meta">
<?php if ( $product->is_type( array( \'simple\', \'variable\' ) ) && get_option(\'woocommerce_enable_sku\') == \'yes\' && $product->get_sku() ) : ?>
<span itemprop="productID" class="sku"><?php _e(\'SKU:\',\'qns\' ); ?> <?php echo $product->get_sku(); ?>.</span>
<?php endif; ?>
<?php echo $product->get_categories( \', \', \' <span class="posted_in">\'.__(\'Category:\',\'qns\' ).\' \', \'.</span>\'); ?>
<?php echo $product->get_tags( \', \', \' <span class="tagged_as">\'.__(\'Tags:\',\'qns\' ).\' \', \'.</span>\'); ?>
</div>
我可以在产品页面中显示产品SKU编号吗?
提前谢谢。
最合适的回答,由SO网友:Joe Dooley 整理而成
将此添加到您的函数中。php
add_action( \'woocommerce_single_product_summary\', \'dev_designs_show_sku\', 5 );
function dev_designs_show_sku(){
global $product;
echo \'SKU: \' . $product->get_sku();
}
这将在产品标题下方输出产品SKU。请参见下图。产品SKU为VERTEX-SLVR。