Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //variaton wasn't selected but user managed to submit a form
- if (empty($_POST['variation_id']) || !is_numeric($_POST['variation_id'])) {
- /* Link on product pages */
- jigoshop::add_error(__('Please choose product options…', 'jigoshop'));
- wp_redirect(get_permalink($_GET['product']));
- exit;
- } else {
- $product_id = apply_filters('jigoshop_product_id_add_to_cart_filter', (int) $_POST['product_id']);
- $variation_id = (int) $_POST['variation_id'];
- $customer_design = $_POST['customer_design'];
- $quantity = 1;
- if (isset($_POST['quantity'])) {
- $quantity = (int) $_POST['quantity'];
- }
- if ( get_post_meta( $product_id , 'customizable', true ) == 'yes' ) {
- // session personalization initially set to parent product until variation selected
- $custom_products = (array) jigoshop_session::instance()->customized_products;
- // transfer it to the variation
- $custom_products[$variation_id] = $custom_products[$product_id];
- unset( $custom_products[$product_id] );
- jigoshop_session::instance()->customized_products = $custom_products;
- }
- $attributes = (array) maybe_unserialize(get_post_meta($product_id, 'product_attributes', true));
- $variations = array();
- $all_variations_set = true;
- foreach ($attributes as $attribute) {
- if ( ! $attribute['variation']) {
- continue;
- }
- $attr_name = 'tax_' . sanitize_title($attribute['name']);
- if (!empty($_POST[$attr_name])) {
- $variations[$attr_name] = $_POST[$attr_name];
- } else {
- $all_variations_set = false;
- }
- }
- if ($all_variations_set && $variation_id > 0) { //all variation options are set
- jigoshop_cart::add_to_cart($product_id, $quantity, $variation_id, $variations, $customer_design);
- $product_added = true;
- } else {
- /* Link on product pages */
- jigoshop::add_error(__('Please choose product options…', 'jigoshop'));
- wp_redirect(apply_filters('jigoshop_product_id_add_to_cart_filter', get_permalink($_GET['product'])));
- exit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement