[英]Add product short description in cart Woocommerce
我想在購物車中添加簡短的產品說明:我確實將它添加到購物車中,但由於我的購物車位於標題頁中,因此在結帳頁面上沒有顯示它很奇怪。 任何想法或其他解決方案都提前感謝非常有用
function excerpt_in_cart() {
$excerpt = get_the_excerpt();
$excerpt = substr($excerpt, 0, 80);
return '<br><p class="shortDescription">' . $excerpt .'...' . '</p>';
}
add_action( 'woocommerce_cart_item_name', 'excerpt_in_cart', 40 );
在結帳頁面上,它不會從代碼中顯示此部分。 $ excerpt。' p出現在課堂上就好了。
function excerpt_in_cart($cart_item_html, $product_data) {
global $_product;
$excerpt = get_the_excerpt($product_data['product_id']);
$excerpt = substr($excerpt, 0, 80);
echo $cart_item_html . '<br><p class="shortDescription">' . $excerpt . '...' . '</p>';
}
add_filter('woocommerce_cart_item_name', 'excerpt_in_cart', 40, 2);
首先, woocommerce_cart_item_name
鈎子是過濾器鈎子而不是動作鈎子。
你正確做的大多數事情都是很少的問題
woocommerce_cart_item_name
鈎子。 附加信息:
這是來自wordpress核心文件plugin.php
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
function add_action
只是add_filter
的包裝函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.