脚本宝典收集整理的这篇文章主要介绍了php – Woocommerce:在购物车页面上显示产品变化描述,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
if ( $_PRoduct->is_tyPE( 'VARiation' ) ) {echo $_product->get_variation_description();}
按照此文档https://docs.woocommerce.com/document/template-structure/
但它仍然没有出现.
任何人都可以帮忙吗?
谢谢
由于WooCommerce 3,get_variation_description()
现已弃用,并被WC_Product方法get_description()
取代.
>使用woocommerce_cart_ITem_name钩子显示变体描述,无需编辑任何模板.
>使用cart.PHP模板显示变体描述.
案例1 – 使用woocommerce_cart_item_name钩子:
add_filter( 'woocommerce_cart_item_name','cart_variation_description',20,3); function cart_variation_description( $name,$cart_item,$cart_item_key ) { // Get the corresponding WC_Product $product_item = $cart_item['data']; if(!empty($product_item) && $product_item->is_type( 'variation' ) ) { // WC 3+ compatibility $descrition = version_compare( WC_VERSION,'3.0','<' ) ? $product_item->get_variation_description() : $product_item->get_description(); $result = __( 'Description: ','woocommerce' ) . $descrition; return $name . '<br>' . $result; } else return $name; }
此代码位于活动子主题(或主题)的function.PHP文件中,或者也可以放在任何插件文件中.
案例2 – 使用cart / cart.PHP模板(根据您的评论更新).
您可以选择要显示此说明的位置(2个选项):
因此,您将根据您的选择在第86行或第90行的cart.PHP模板上插入此代码:
// Get the WC_Product $product_item = $cart_item['data']; if( ! empty( $product_item ) && $product_item->is_type( 'variation' ) ) { // WC 3+ compatibility $description = version_compare( WC_VERSION,'<' ) ? $product_item->get_variation_description() : $product_item->get_description(); if( ! empty( $description ) ) { // '<br>'. Could be added optionally if needed echo __( 'Description: ','woocommerce' ) . $description;; } }
以上是脚本宝典为你收集整理的php – Woocommerce:在购物车页面上显示产品变化描述全部内容,希望文章能够帮你解决php – Woocommerce:在购物车页面上显示产品变化描述所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。