📌  相关文章
📜  ajax 单品加入购物车 woocommerce stackoverflow - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:22.745000             🧑  作者: Mango

代码示例2
add_action( 'template_redirect', 'quadlayers_add_to_cart_function' );

function quadlayers_add_to_cart_function () {

    $product_id = 1326;

    if ( WC()->cart->get_cart_contents_count() == 0 ) {

        WC()->cart->add_to_cart( $product_id );

    }

}