在 WooCommerce WC_Product get_description() 方法中启用简码使用
Enable Shortcode usage in WooCommerce WC_Product get_description() method
我正在使用 Add product description to cart items in Woocommerce answer and added it to my function.php file to display the product description in the WooCommerce cart. It works great but within my product description is a shortcode from this plugin https://wordpress.org/plugins/simple-divi-shortcode/ 中的第二个代码片段,但它没有正确显示在购物车中。改为显示简码 [showmodule id="261"]。
您只需将产品描述嵌入 WordPress do_shortcode()
函数中,例如:
add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data( $item_name, $cart_item, $cart_item_key ) {
// The label
$label = __( 'Description', 'woocommerce' );
// Get the product description
$description = $cart_item['data']->get_description();
// For product variations when description is empty
if( $cart_item['data']->is_type('variation') && empty( $description ) ){
// Get the parent variable product object
$product = wc_get_product( $cart_item['data']->get_parent_id() );
// Get the variable product description
$description = $product->get_description();
}
if( ! empty( $description ) ){
$item_name .= '<p class="item-description" style="margin:12px 0 0;">
<strong>'.$label.'</strong>: <br>' . do_shortcode( $description ) . '
</p>';
}
return $item_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
我正在使用 Add product description to cart items in Woocommerce answer and added it to my function.php file to display the product description in the WooCommerce cart. It works great but within my product description is a shortcode from this plugin https://wordpress.org/plugins/simple-divi-shortcode/ 中的第二个代码片段,但它没有正确显示在购物车中。改为显示简码 [showmodule id="261"]。
您只需将产品描述嵌入 WordPress do_shortcode()
函数中,例如:
add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_data', 10, 3);
function customizing_cart_item_data( $item_name, $cart_item, $cart_item_key ) {
// The label
$label = __( 'Description', 'woocommerce' );
// Get the product description
$description = $cart_item['data']->get_description();
// For product variations when description is empty
if( $cart_item['data']->is_type('variation') && empty( $description ) ){
// Get the parent variable product object
$product = wc_get_product( $cart_item['data']->get_parent_id() );
// Get the variable product description
$description = $product->get_description();
}
if( ! empty( $description ) ){
$item_name .= '<p class="item-description" style="margin:12px 0 0;">
<strong>'.$label.'</strong>: <br>' . do_shortcode( $description ) . '
</p>';
}
return $item_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。