{"id":15785,"date":"2025-05-22T20:03:42","date_gmt":"2025-05-23T03:03:42","guid":{"rendered":"https:\/\/codedcommerce.com\/?page_id=15785"},"modified":"2025-05-23T10:45:02","modified_gmt":"2025-05-23T17:45:02","slug":"woo-quick-order-shortcode","status":"publish","type":"woo-code","link":"https:\/\/codedcommerce.com\/woo\/woo-quick-order-shortcode\/","title":{"rendered":"Woo Quick Order shortcode"},"content":{"rendered":"\n<pre class=\"wp-block-code language-php\"><code>wp_register_style( 'ccom-wqo', false );\n\nadd_shortcode( 'ccom-wqo', function( $atts, $text ) {\n\n\twp_enqueue_style( 'ccom-wqo' );\n\twp_add_inline_style( 'ccom-wqo', '\n\t\tform#ccom_wqo {\n\t\t\tdisplay: inline;\n\t\t}\n\t\tform#ccom_wqo > div {\n\t\t\tdisplay: table;\n\t\t}\n\t\tform#ccom_wqo > div > div {\n\t\t\tdisplay: table-row;\n\t\t}\n\t\tform#ccom_wqo > div > div > span {\n\t\t\tdisplay: table-cell;\n\t\t}\n\t\tform#ccom_wqo > div > div > span:last-child {\n\t\t\ttext-wrap: nowrap;\n\t\t}\n\t\tform#ccom_wqo img {\n\t\t\twidth: 2em;\n\t\t}\n\t\tform#ccom_wqo input&#91;type=number] {\n\t\t\twidth: 3em;\n\t\t\tdisplay: inline-block;\n\t\t}\n\t' );\n\n\treturn sprintf(\n\t\t'\n\t\t\t&lt;form id=\"ccom_wqo\" action=\"\/cart\/\" method=\"POST\">\n\t\t\t\t&lt;div>\n\t\t\t\t\t%s\n\t\t\t\t\t&lt;div>\n\t\t\t\t\t\t&lt;span>&amp;nbsp;&lt;\/span>\n\t\t\t\t\t\t&lt;span>&amp;nbsp;&lt;\/span>\n\t\t\t\t\t\t&lt;span>\n\t\t\t\t\t\t\t&lt;input type=\"submit\" value=\"Add to Cart\" class=\"button\">\n\t\t\t\t\t\t&lt;\/span>\n\t\t\t\t\t&lt;\/div>\n\t\t\t\t&lt;\/div>\n\t\t\t&lt;\/form>\n\t\t',\n\t\tdo_shortcode( $text )\n\t);\n\n} );\n\nadd_shortcode( 'ccom-wqo-item', function( $atts ) {\n\n\tif( empty( $atts&#91;'id'] ) ) {\n\t\treturn;\n\t}\n\n\t$product = wc_get_product( intval( $atts&#91;'id'] ) );\n\tif( ! $product ) {\n\t\treturn;\n\t}\n\n\treturn sprintf(\n\t\t'\n\t\t\t&lt;div>\n\t\t\t\t&lt;span>%s&lt;\/span>\n\t\t\t\t&lt;span>\n\t\t\t\t\t&lt;a href=\"%s\">%s&lt;\/a>\n\t\t\t\t&lt;\/span>\n\t\t\t\t&lt;span>\n\t\t\t\t\t&lt;input type=\"number\" size=\"3\" name=\"ccom-a2c&#91;%d]\" value=\"0\">\n\t\t\t\t\tat %s \/ each\n\t\t\t\t&lt;\/span>\n\t\t\t&lt;\/div>\n\t\t',\n\t\t$product->get_image( 'thumbnail' ),\n\t\t$product->get_permalink(),\n\t\t$product->get_title(),\n\t\t$product->get_id(),\n\t\t$product->get_price_html()\n\t);\n\n} );\n\nadd_action( 'template_redirect', function() {\n\n\tif( empty( $_POST&#91;'ccom-a2c'] ) || ! is_array( $_POST&#91;'ccom-a2c'] ) ) {\n\t\treturn;\n\t}\n\n\tif( ! class_exists( 'WooCommerce' ) || empty( WC()->cart ) ) {\n\t\treturn;\n\t}\n\n\tforeach( $_POST&#91;'ccom-a2c'] as $product_id => $quantity ) {\n\n\t\tif( intval( $quantity ) &lt; 1 ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tWC()->cart->add_to_cart( intval( $product_id ), intval( $quantity ) );\n\n\t}\n\n} );<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-15785","woo-code","type-woo-code","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/woo-code\/15785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/woo-code"}],"about":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/types\/woo-code"}],"wp:attachment":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/media?parent=15785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}