Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 购物车项目标题为';t连接到WooCommerce中的HTML表中_Php_Html_Wordpress_Woocommerce_Cart - Fatal编程技术网

Php 购物车项目标题为';t连接到WooCommerce中的HTML表中

Php 购物车项目标题为';t连接到WooCommerce中的HTML表中,php,html,wordpress,woocommerce,cart,Php,Html,Wordpress,Woocommerce,Cart,我创建了一个简短的代码来列出所有项目名称,如下所示 add_shortcode( 'show_cart_items', 'tcf_show_cart_items' ); function tcf_show_cart_items() { $cart = '<table>'; foreach( WC()->cart->get_cart() as $cart_item ) {

我创建了一个简短的代码来列出所有项目名称,如下所示

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;
}
add_shortcode('show_cart_items'、'tcf_show_cart_items');
函数tcf_show_cart_items()
{
$cart='';
foreach(WC()->cart->get_cart()作为$cart_项目)
{
$cart.=''.$cart_项目['data']->获取标题();
}
$cart.='';
返回$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;
    }
    
    add_shortcode('show_cart_items'、'tcf_show_cart_items');
    函数tcf_show_cart_items()
    {
    $cart_item='';
    foreach(WC()->cart->get_cart()作为$cart_项目)
    {
    $cart_item.='.$cart_item['data']->获取标题();
    }
    $cart='.$cart_item'.';
    返回$cart;
    }
    
    尝试下面的代码,可能是串联跳过的代码

    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;
    }
    
    add_shortcode('show_cart_items'、'tcf_show_cart_items');
    函数tcf_show_cart_items()
    {
    $cart_item='';
    foreach(WC()->cart->get_cart()作为$cart_项目)
    {
    $cart_item.='.$cart_item['data']->获取标题();
    }
    $cart='.$cart_item'.';
    返回$cart;
    }
    
    您刚刚忘记在标题周围添加
    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;
    }
    
    add_shortcode('show_cart_items'、'tcf_show_cart_items');
    函数tcf_show_cart_items()
    {
    $cart='';
    foreach(WC()->cart->get_cart()作为$cart_项目)
    $cart.=''.$cart_项目['data']->获取标题();
    $cart.='';
    返回$cart;
    }
    
    或者也可以这样:

    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;
    }
    
    add_shortcode('show_cart_items'、'tcf_show_cart_items');
    函数tcf_show_cart_items()
    {
    $cart='';
    foreach(WC()->cart->get_cart()作为$cart_项目)
    $cart.=''.$cart_项目['data']->获取标题();
    $cart.='';
    返回$cart;
    }
    
    代码位于活动子主题(或主题)的function.php文件或任何插件文件中


    已经过测试,现在可以正常工作。

    您刚刚忘记在标题周围添加
    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;
    }
    
    add_shortcode('show_cart_items'、'tcf_show_cart_items');
    函数tcf_show_cart_items()
    {
    $cart='';
    foreach(WC()->cart->get_cart()作为$cart_项目)
    $cart.=''.$cart_项目['data']->获取标题();
    $cart.='';
    返回$cart;
    }
    
    或者也可以这样:

    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;
    }
    
    add_shortcode('show_cart_items'、'tcf_show_cart_items');
    函数tcf_show_cart_items()
    {
    $cart='';
    foreach(WC()->cart->get_cart()作为$cart_项目)
    $cart.=''.$cart_项目['data']->获取标题();
    $cart.='';
    返回$cart;
    }
    
    代码位于活动子主题(或主题)的function.php文件或任何插件文件中


    已测试,现在可以正常工作。

    它提供相同的输出,但没有LuckKit提供相同的输出,但没有Luckt这听起来像是
    get_title
    方法实际上是输出标题(echo,print),而不是返回它。。。但根据docs的说法,应该是后者(至少在WC 3中,您使用的是哪个版本?)我使用的是最新的WC 3。这听起来像
    get_title
    方法实际上是输出标题(echo,print),而不是返回它。。。但根据文档,它应该做后者(至少在WC3中,您使用的是哪个版本?)我使用的是最新的WC3。