/** * get the current WPeC database version * * @return int current database version */ function wpsc_core_shipping_enabled() { $shipping_disabled = get_option('do_not_use_shipping', -1); if ($shipping_disabled === -1) { // if shipping enabled comes back as -1 we want to set it to the default value, this is // because unset WordPress options are not cached. That means if this option isn't in the database // we could make a trip to the database every time this option is looked at. This variable // can be tested many times per page view, so let's make it clean update_option('do_not_use_shipping', false); $shipping_disabled = false; } $shipping_disabled = _wpsc_make_value_into_bool($shipping_disabled); return !$shipping_disabled; }
/** * when visitor meta is updated we need to check if the shipping same as billing * option is selected. If so we need to update the corresponding meta value. * * @since 3.8.14 * @access private * @param $meta_value varies value being stored * @param $meta_key string name of the attribute being stored * @param $visitor_id int id of the visitor to which the attribute applies * @return n/a */ function _wpsc_vistor_shipping_same_as_billing_meta_update($meta_value, $meta_key, $visitor_id) { // remove the action so we don't cause an infinite loop remove_action('wpsc_updated_visitor_meta', '_wpsc_vistor_shipping_same_as_billing_meta_update', _WPSC_USER_META_HOOK_PRIORITY); // if the shipping same as billing option is being checked then copy meta from billing to shipping if ($meta_key == 'shippingSameBilling') { $meta_value = _wpsc_make_value_into_bool($meta_value); if ($meta_value) { $checkout_names = wpsc_checkout_unique_names(); foreach ($checkout_names as $meta_key) { $meta_key_starts_with_billing = strpos($meta_key, 'billing', 0) === 0; if ($meta_key_starts_with_billing) { $other_meta_key_name = 'shipping' . substr($meta_key, strlen('billing')); if (in_array($other_meta_key_name, $checkout_names)) { $billing_meta_value = wpsc_get_customer_meta($meta_key); wpsc_update_visitor_meta($visitor_id, $other_meta_key_name, $billing_meta_value); } } } } } else { $shipping_same_as_billing = wpsc_get_visitor_meta($visitor_id, 'shippingSameBilling', true); if ($shipping_same_as_billing) { $meta_key_starts_with_billing = strpos($meta_key, 'billing', 0) === 0; $meta_key_starts_with_shipping = strpos($meta_key, 'shipping', 0) === 0; if ($meta_key_starts_with_billing) { $checkout_names = wpsc_checkout_unique_names(); $other_meta_key_name = 'shipping' . substr($meta_key, strlen('billing')); if (in_array($other_meta_key_name, $checkout_names)) { wpsc_update_visitor_meta($visitor_id, $other_meta_key_name, $meta_value); } } elseif ($meta_key_starts_with_shipping) { $checkout_names = wpsc_checkout_unique_names(); $other_meta_key_name = 'billing' . substr($meta_key, strlen('shipping')); if (in_array($other_meta_key_name, $checkout_names)) { wpsc_update_visitor_meta($visitor_id, $other_meta_key_name, $meta_value); } } } } // restore the action we removed at the start add_action('wpsc_updated_visitor_meta', '_wpsc_vistor_shipping_same_as_billing_meta_update', _WPSC_USER_META_HOOK_PRIORITY, 3); }