是否可以向 woocommerce 产品 WordPress 小部件中的产品列表添加简短描述? 我该怎么做?
我不是专业人士,请简单回答!
谢谢
最佳答案
您应该需要通过事件主题覆盖 WooCommerce content-widget-product.php
模板。这是相关文档:Template structure & Overriding templates via a theme
因此,您需要在事件子主题(或事件主题)中创建一个名为 woocommerce 的文件夹(如果尚未完成),您将在其中复制位于以下位置的文件:
wp-content/plugins/woocommerce/templates/content-widget-product.php
至:
wp-content/themes/your-child-theme/woocommerce/content-widget-product.php
完成后,您将在 34
行后添加以下内容:
<div class="produc-excerpt"><?php echo $product->get_short_description(); ?></div>
这将为小部件产品输出列表中的每个产品添加产品简短描述。
In upcoming WooCommerce version 3.3, you will be able to replace that using a custom function hooked in dedicated
woocommerce_widget_product_item_end
action hook:
add_action( 'woocommerce_widget_product_item_end', 'add_excerpt_to_widget_products', 10, 1 );
function add_excerpt_to_widget_products( $args ) {
global $product;
echo '<div class="produc-excerpt">Bla: '. $product->get_short_description(). '</div>';
}
代码位于事件子主题(或事件主题)的 function.php 文件中。
经过测试,仅适用于 WooCommerce 版本 3.3+。
关于php - 向 WooCommerce 中的小部件产品添加简短的产品描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48188591/