public function callback_submit_options() { global $wpsc_shipping_modules; foreach ($wpsc_shipping_modules as $shipping) { if (is_object($shipping)) { $shipping->submit_form(); } } //This is for submitting shipping details to the shipping module if (!isset($_POST['update_gateways'])) { $_POST['update_gateways'] = ''; } if (!isset($_POST['custom_shipping_options'])) { $_POST['custom_shipping_options'] = array(); } update_option('custom_shipping_options', array_map('sanitize_text_field', $_POST['custom_shipping_options'])); $shipadd = 0; foreach ($wpsc_shipping_modules as $shipping) { foreach ((array) $_POST['custom_shipping_options'] as $shippingoption) { if ($shipping->getInternalName() == $shippingoption) { $shipadd++; } } } if (isset($_POST['wpsc_options']['shipping_discount_value'])) { update_option('shipping_discount_value', wpsc_string_to_float($_POST['wpsc_options']['shipping_discount_value'])); } if (!get_option('do_not_use_shipping') && !get_option('custom_shipping_options') && !(bool) get_option('shipwire')) { update_option('do_not_use_shipping', '1'); return array('shipping_disabled' => 1); } else { $_SERVER['REQUEST_URI'] = esc_url_raw(remove_query_arg('shipping_disabled')); } }
private function save_variation_meta($id, $data) { $product_meta = get_product_meta($id, 'product_metadata', true); if (!is_array($product_meta)) { $product_meta = array(); } $product_meta = $this->merge_meta_deep($product_meta, $data['product_metadata']); // convert to pound to maintain backward compat with shipping modules if (isset($data['product_metadata']['weight']) || isset($data['product_metadata']['weight_unit'])) { $product_meta['weight'] = wpsc_convert_weight($product_meta['weight'], $product_meta['weight_unit'], 'pound', true); } update_product_meta($id, 'product_metadata', $product_meta); if (isset($data['price'])) { update_product_meta($id, 'price', wpsc_string_to_float($data['price'])); } if (isset($data['sale_price'])) { $sale_price = wpsc_string_to_float($data['sale_price']); if (is_numeric($sale_price)) { update_product_meta($id, 'special_price', wpsc_string_to_float($data['sale_price'])); } else { update_product_meta($id, 'special_price', ''); } } if (isset($data['sku'])) { update_product_meta($id, 'sku', $data['sku']); } if (isset($data['stock'])) { if (is_numeric($data['stock'])) { update_product_meta($id, 'stock', (int) $data['stock']); } else { update_product_meta($id, 'stock', ''); } } }
/** * Adds product properties to analytics.track() when product is viewed. * * @since 1.0.0 * @access public * * @uses func_get_args() Because our abstract class doesn't know how many parameters are passed to each hook * for each different platform, we use func_get_args(). * * @return array Filtered array of name and properties for analytics.track(). */ public function viewed_product() { $args = func_get_args(); $track = $args[0]; if (is_singular('wpsc-product')) { $track = array('event' => __('Viewed Product', 'segment'), 'properties' => array('id' => get_the_ID(), 'sku' => wpsc_product_sku(), 'name' => wpsc_the_product_title(), 'price' => wpsc_string_to_float(wpsc_the_product_price()), 'category' => implode(', ', wp_list_pluck(wpsc_get_product_terms(get_the_ID(), 'wpsc_product_category'), 'name')))); } return $track; }
/** * wpsc_sanitise_product_forms function * * @return array - Sanitised product details */ function wpsc_sanitise_product_forms($post_data = null) { if (empty($post_data)) { $post_data =& $_POST; } $post_data = stripslashes_deep($post_data); $post_data['name'] = isset($post_data['post_title']) ? $post_data['post_title'] : ''; $post_data['title'] = $post_data['name']; $post_data['description'] = isset($post_data['content']) ? $post_data['content'] : ''; $post_data['additional_description'] = isset($post_data['additional_description']) ? $post_data['additional_description'] : ''; $post_data['post_status'] = 'draft'; if (isset($post_data['publish'])) { $post_data['post_status'] = 'publish'; } else { if (isset($post_data['unpublish'])) { $post_data['post_status'] = 'draft'; } } $post_data['meta']['_wpsc_price'] = wpsc_string_to_float($post_data['meta']['_wpsc_price']); $post_data['meta']['_wpsc_special_price'] = wpsc_string_to_float($post_data['meta']['_wpsc_special_price']); if (!isset($post_data['meta']['_wpsc_is_donation'])) { $post_data['meta']['_wpsc_is_donation'] = ''; } $post_data['meta']['_wpsc_is_donation'] = (int) (bool) $post_data['meta']['_wpsc_is_donation']; $post_data['meta']['_wpsc_stock'] = (int) $post_data['meta']['_wpsc_stock']; if (!isset($post_data['meta']['_wpsc_limited_stock'])) { $post_data['meta']['_wpsc_limited_stock'] = ''; } if ((bool) $post_data['meta']['_wpsc_limited_stock'] != true) { $post_data['meta']['_wpsc_stock'] = false; } unset($post_data['meta']['_wpsc_limited_stock']); if (!isset($post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'])) { $post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'] = 0; } if (!isset($post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'])) { $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = ''; } if (!isset($post_data['quantity_limited'])) { $post_data['quantity_limited'] = ''; } if (!isset($post_data['special'])) { $post_data['special'] = ''; } if (!isset($post_data['meta']['_wpsc_product_metadata']['no_shipping'])) { $post_data['meta']['_wpsc_product_metadata']['no_shipping'] = ''; } $post_data['meta']['_wpsc_product_metadata']['notify_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['notify_when_none_left']; $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left']; $post_data['meta']['_wpsc_product_metadata']['quantity_limited'] = (int) (bool) $post_data['quantity_limited']; $post_data['meta']['_wpsc_product_metadata']['special'] = (int) (bool) $post_data['special']; $post_data['meta']['_wpsc_product_metadata']['no_shipping'] = (int) (bool) $post_data['meta']['_wpsc_product_metadata']['no_shipping']; // Product Weight if (!isset($post_data['meta']['_wpsc_product_metadata']['display_weight_as'])) { $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = ''; } if (!isset($post_data['meta']['_wpsc_product_metadata']['display_weight_as'])) { $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = ''; } $weight = wpsc_string_to_float($post_data['meta']['_wpsc_product_metadata']['weight']); $weight = wpsc_convert_weight($weight, $post_data['meta']['_wpsc_product_metadata']['weight_unit'], "pound", true); $post_data['meta']['_wpsc_product_metadata']['weight'] = $weight; $post_data['meta']['_wpsc_product_metadata']['display_weight_as'] = $post_data['meta']['_wpsc_product_metadata']['weight_unit']; $post_data['files'] = $_FILES; return $post_data; }