public function get_cart_item_from_session($cart_item, $values) { //no need to check is_nyp b/c this has already been validated by validate_add_cart_item() if (isset($values['nyp'])) { $cart_item['nyp'] = $values['nyp']; // add the subscription billing period if (WC_Name_Your_Price_Helpers::is_subscription($values['product_id']) && isset($values['nyp_period']) && in_array($values['nyp_period'], WC_Name_Your_Price_Helpers::get_subscription_period_strings())) { $cart_item['nyp_period'] = $values['nyp_period']; } $cart_item = $this->add_cart_item($cart_item); } return $cart_item; }
public static function save_product_meta($post_id, $post) { $product_type = empty($_POST['product-type']) ? 'simple' : sanitize_title(stripslashes($_POST['product-type'])); $suggested = ''; if (isset($_POST['_nyp']) && in_array($product_type, self::$simple_supported_types)) { update_post_meta($post_id, '_nyp', 'yes'); // removing the sale price removes NYP items from Sale shortcodes update_post_meta($post_id, '_sale_price', ''); delete_post_meta($post_id, '_has_nyp'); } else { update_post_meta($post_id, '_nyp', 'no'); } if (isset($_POST['_suggested_price'])) { $suggested = trim($_POST['_suggested_price']) === '' ? '' : wc_format_decimal($_POST['_suggested_price']); update_post_meta($post_id, '_suggested_price', $suggested); } if (isset($_POST['_min_price'])) { $minimum = trim($_POST['_min_price']) === '' ? '' : wc_format_decimal($_POST['_min_price']); update_post_meta($post_id, '_min_price', $minimum); } // Variable Billing Periods // save whether subscription is variable billing or not (only for regular subscriptions) if (isset($_POST['_variable_billing']) && 'subscription' == $product_type) { update_post_meta($post_id, '_variable_billing', 'yes'); } else { update_post_meta($post_id, '_variable_billing', 'no'); } // suggested period - don't save if no suggested price if (class_exists('WC_Subscriptions_Manager') && $suggested && isset($_POST['_suggested_billing_period']) && in_array($_POST['_suggested_billing_period'], WC_Name_Your_Price_Helpers::get_subscription_period_strings())) { $suggested_period = wc_clean($_POST['_suggested_billing_period']); update_post_meta($post_id, '_suggested_billing_period', $suggested_period); } // minimum period - don't save if no minimum price if (class_exists('WC_Subscriptions_Manager') && isset($_POST['_min_price']) && isset($_POST['_minimum_billing_period']) && in_array($_POST['_minimum_billing_period'], WC_Name_Your_Price_Helpers::get_subscription_period_strings())) { $minimum_period = wc_clean($_POST['_minimum_billing_period']); update_post_meta($post_id, '_minimum_billing_period', $minimum_period); } }