[英]Cart item title isn't concatenated into an HTML table in WooCommerce
我創建了一個簡碼來列出所有項目名稱,如下所示,
add_shortcode( 'show_cart_items', 'tcf_show_cart_items' );
function tcf_show_cart_items()
{
$cart = '<table>';
foreach( WC()->cart->get_cart() as $cart_item )
{
$cart .= '<tr>' . $cart_item['data']->get_title() . '</tr>';
}
$cart .= '</table>';
return $cart;
}
這工作正常,但我要面對的是桌子上打印的物品。 當我在網頁上檢查時,您可以看到輸出為屏幕截圖,並且未在HTML表格的側面打印的項目名稱以黃色突出顯示。
我的問題是
TIA。
嘗試下面的代碼,可能是串聯的跳過代碼
add_shortcode( 'show_cart_items', 'tcf_show_cart_items' );
function tcf_show_cart_items()
{
$cart_item = '';
foreach( WC()->cart->get_cart() as $cart_item )
{
$cart_item .= '<tr>' . $cart_item['data']->get_title() . '</tr>';
}
$cart = '<table>'.$cart_item.'</table>';
return $cart;
}
您只是忘了在標題周圍添加<td>
html標簽,方法如下:
add_shortcode( 'show_cart_items', 'tcf_show_cart_items' );
function tcf_show_cart_items()
{
$cart = '<table>';
foreach( WC()->cart->get_cart() as $cart_item )
$cart .= '<tr><td>' . $cart_item['data']->get_title() . '</td></tr>';
$cart .= '</table>';
return $cart;
}
或者也這樣:
add_shortcode( 'show_cart_items', 'tcf_show_cart_items' );
function tcf_show_cart_items()
{
$cart = '<table><tr>';
foreach( WC()->cart->get_cart() as $cart_item )
$cart .= '<td>' . $cart_item['data']->get_title() . '</td>';
$cart .= '</tr></table>';
return $cart;
}
代碼在您的活動子主題(或主題)的function.php文件中,或者在任何插件文件中。
經過測試,現在可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.