在 Woocommerce 的购物车页面上显示产品摘录
Display product excerpt on cart page in Woocommerce
我正在努力修改 woocommerce 中的购物车页面。我的主题文件夹中有 cart.php
文件,我想在该页面中添加一些有关产品的信息。
我想添加两个挂钩:
woocommerce_template_single_excerpt
woocommerce_template_single_meta
但我不确定该怎么做。我正在尝试在下一个基本代码的某些版本中添加这些挂钩:
add_action( 'woocommerce_before_cart_contents','matusevitch_cart_page_info' );
function matusevitch_cart_page_info(){
// Your code
}
现在在函数中,我尝试只是回显钩子,或者像这样添加它:
do_action( 'woocommerce_before_cart_contents','woocommerce_template_single_meta' );
我在之前检查过的其他线程中也尝试了一些解决方案,但没有一个有效。
如何在购物车页面上显示项目的产品摘录?
这可以简单地通过以下方式完成,例如:
add_filter( 'woocommerce_cart_item_name', 'add_excerpt_in_cart_item_name', 10, 3 );
function add_excerpt_in_cart_item_name( $item_name, $cart_item, $cart_item_key ){
$excerpt = wp_strip_all_tags( get_the_excerpt($cart_item['product_id']), true );
$style = ' style="font-size:14px; line-height:normal;"';
$excerpt_html = '<br>
<p name="short-description"'.$style.'>'.$excerpt.'</p>';
return $item_name . $excerpt_html;
}
此代码位于您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
已测试并有效
试试这个,
覆盖以下woocommerce页面模板,
woocommerce/cart/cart.php in your theme
你会在里面找到一个tableHTML/code。
<th class="product-short-description"><?php _e('Short Description', 'woocommerce'); ?></th>
//add this code in to <thead>..</thead>
<td class="product-short-description" data-title="<?php esc_attr_e('Product Excerpt', 'woocommerce'); ?>">
<?php
echo get_the_excerpt($product_id);
?>
</td>
//add this code in to <tbody>..</tbody>
希望对您有所帮助。
我正在努力修改 woocommerce 中的购物车页面。我的主题文件夹中有 cart.php
文件,我想在该页面中添加一些有关产品的信息。
我想添加两个挂钩:
woocommerce_template_single_excerpt
woocommerce_template_single_meta
但我不确定该怎么做。我正在尝试在下一个基本代码的某些版本中添加这些挂钩:
add_action( 'woocommerce_before_cart_contents','matusevitch_cart_page_info' );
function matusevitch_cart_page_info(){
// Your code
}
现在在函数中,我尝试只是回显钩子,或者像这样添加它:
do_action( 'woocommerce_before_cart_contents','woocommerce_template_single_meta' );
我在之前检查过的其他线程中也尝试了一些解决方案,但没有一个有效。
如何在购物车页面上显示项目的产品摘录?
这可以简单地通过以下方式完成,例如:
add_filter( 'woocommerce_cart_item_name', 'add_excerpt_in_cart_item_name', 10, 3 );
function add_excerpt_in_cart_item_name( $item_name, $cart_item, $cart_item_key ){
$excerpt = wp_strip_all_tags( get_the_excerpt($cart_item['product_id']), true );
$style = ' style="font-size:14px; line-height:normal;"';
$excerpt_html = '<br>
<p name="short-description"'.$style.'>'.$excerpt.'</p>';
return $item_name . $excerpt_html;
}
此代码位于您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
已测试并有效
试试这个,
覆盖以下woocommerce页面模板,
woocommerce/cart/cart.php in your theme
你会在里面找到一个tableHTML/code。
<th class="product-short-description"><?php _e('Short Description', 'woocommerce'); ?></th>
//add this code in to <thead>..</thead>
<td class="product-short-description" data-title="<?php esc_attr_e('Product Excerpt', 'woocommerce'); ?>">
<?php
echo get_the_excerpt($product_id);
?>
</td>
//add this code in to <tbody>..</tbody>
希望对您有所帮助。