Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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 如何在Wordpress/WooCommerce中显示购物车信息_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 如何在Wordpress/WooCommerce中显示购物车信息

Php 如何在Wordpress/WooCommerce中显示购物车信息,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在使用woocommerce和wordpress作为电子商务网站。我希望能够在页面的任何位置显示用户购物车中的商品数量和总价 通常情况下,如果您使用其中一个woo主题,它会显示在菜单导航栏中。然而,我使用的是一个几乎完全空白的主题,我不知道如何获得商品/价格的总信息并以html显示它。他们的文档给出了这样一个片段: ` 但我不明白我将使用什么HTML标记或类来进行显示。我需要使用哪种类型的元素和类id来显示该主题?请确保为主题的functions.php文件包含以下代码 而且,这也将aj

我正在使用woocommerce和wordpress作为电子商务网站。我希望能够在页面的任何位置显示用户购物车中的商品数量和总价

通常情况下,如果您使用其中一个woo主题,它会显示在菜单导航栏中。然而,我使用的是一个几乎完全空白的主题,我不知道如何获得商品/价格的总信息并以html显示它。他们的文档给出了这样一个片段:


`

但我不明白我将使用什么HTML标记或类来进行显示。我需要使用哪种类型的元素和类id来显示该主题?

请确保为主题的functions.php文件包含以下代码

而且,这也将ajaxify您的购物车自动更新,而无需重新加载页面

// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');

function woocommerce_header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;

    ob_start();

    ?>
    <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
    <?php

    $fragments['a.cart-contents'] = ob_get_clean();

    return $fragments;

}
//通过AJAX将产品添加到购物车时,确保购物车内容更新(将以下内容放在functions.php中)
添加过滤器('add_to_cart_fragments'、'woocommerce_header_add_to_cart_fragments');
函数标题添加到购物车片段($fragments){
全球商业;
ob_start();
?>
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');

function woocommerce_header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;

    ob_start();

    ?>
    <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
    <?php

    $fragments['a.cart-contents'] = ob_get_clean();

    return $fragments;

}