<\/span><\/h3>\n\n\n\n<script type=\"text\/javascript\">\n\n\tfunction jwc_add_to_cart( product_id ) {\n\t\tif ( 'undefined' === typeof wc_add_to_cart_params ) {\n\t\t\t\/\/ The add to cart params are not present.\n\t\t\treturn false;\n\t\t}\n\n\t\tvar data = {\n\t\t\tproduct_id: product_id,\n\t\t\tquantity: 1,\n\t\t};\n\n\t\tjQuery.post( wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ), data, function( response ) {\n\t\t\tif ( ! response ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t\/\/ This redirects the user to the product url if for example options are needed ( in a variable product ).\n\t\t\t\/\/ You can remove this if it's not the case.\n\t\t\tif ( response.error && response.product_url ) {\n\t\t\t\twindow.location = response.product_url;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t\/\/ Remove this if you never want this action redirect.\n\t\t\tif ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {\n\t\t\t\twindow.location = wc_add_to_cart_params.cart_url;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t\/\/ This is important so your theme gets a chance to update the cart quantity for example, but can be removed if not needed.\n\t\t\tjQuery( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash ] );\n\t\t});\n\t}\n\n<\/script><\/code><\/pre>\n\n\n\n<\/span>PHP<\/span><\/h3>\n\n\n\nWC()->cart->add_to_cart( $product_id, $quantity );\n<\/code><\/pre>\n\n\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"
\u524d\u7bc7\u8001\u5b63\u5199\u4e86WordPress \u5546\u57ce\u5f00\u53d1 WooCommerce \u63d2\u4ef6\u521b\u5efa\u81ea\u5b9a\u4e49\u4ea7\u54c1\u7c7b\u578bProduct_typ […]<\/p>\n","protected":false},"author":1,"featured_media":43051,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[341,33],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/47773"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=47773"}],"version-history":[{"count":0,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/47773\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/43051"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=47773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=47773"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=47773"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}