WooCommerce以编程方式将多个产品添加到购物车

时间:2017-09-08 13:29:43

标签: php wordpress woocommerce

我正在为WooCommerce写一个插件。我想在WooCommerce购物车中添加多个产品。 这是我的代码。

    global $woocommerce;

    $woocommerce->cart->add_to_cart( $_REQUEST['Intel'], $_REQUEST['Intel_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['AMD'], $_REQUEST['AMD_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Desktops_cpu'], $_REQUEST['Desktops_cpu_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Workstation_server_cpu'], $_REQUEST['Workstation_server_cpu_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['intel_Xeon_phi_PCI_Express'], $_REQUEST['intel_Xeon_phi_PCI_Express_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Memory_Ram_non_Ecc'], $_REQUEST['Memory_Ram_non_Ecc_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Memory_Ram_Ecc'], $_REQUEST['Memory_Ram_Ecc_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Desktop_graphics_card'], $_REQUEST['Desktop_graphics_card_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Workstation_graphics_card'], $_REQUEST['Workstation_graphics_card_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Multi_display_video_card'], $_REQUEST['Multi_display_video_card_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Server_graphics_card'], $_REQUEST['Server_graphics_card_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Capture_card'], $_REQUEST['Capture_card_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Cooling'], $_REQUEST['Cooling_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['Sound_Card'], $_REQUEST['Sound_Card_num'] );
    $woocommerce->cart->add_to_cart( $_REQUEST['SSD'], $_REQUEST['SSD_num'] );

产品已添加到购物车中,但后来我有错误!

Notice: woocommerce_items_in_cart cookie cannot be set - headers already sent by /var/www/wordpress/wp-includes/formatting.php on line 5405 in /var/www/wordpress/wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 742 ...

0 个答案:

没有答案