/** * Sets the legacy public variables for backwards compatibility. * * @param string $key * @param mixed $value */ public function __set($key, $value) { switch ($key) { case 'enable_signup': $bool_value = wc_string_to_bool($value); if ($bool_value !== $this->is_registration_enabled()) { remove_filter('woocommerce_checkout_registration_enabled', '__return_true', 0); remove_filter('woocommerce_checkout_registration_enabled', '__return_false', 0); add_filter('woocommerce_checkout_registration_enabled', $bool_value ? '__return_true' : '__return_false', 0); } break; case 'enable_guest_checkout': $bool_value = wc_string_to_bool($value); if ($bool_value !== $this->is_registration_required()) { remove_filter('woocommerce_checkout_registration_required', '__return_true', 0); remove_filter('woocommerce_checkout_registration_required', '__return_false', 0); add_filter('woocommerce_checkout_registration_required', $bool_value ? '__return_false' : '__return_true', 0); } break; case 'checkout_fields': $this->fields = $value; break; case 'shipping_methods': WC()->session->set('chosen_shipping_methods', $value); break; case 'legacy_posted_data': $this->legacy_posted_data = $value; break; } }
/** * Converts a bool to a string. * @since 2.7.0 * @param bool $bool * @return string yes or no */ function wc_bool_to_string($bool) { if (!is_bool($bool)) { $bool = wc_string_to_bool($bool); } return true === $bool ? 'yes' : 'no'; }
/** * Developers can programically return coupons. This function will read those values into our WC_Coupon class. * @since 2.7.0 * @param string $code Coupon code * @param array $coupon Array of coupon properties */ public function read_manual_coupon($code, $coupon) { foreach ($coupon as $key => $value) { switch ($key) { case 'excluded_product_ids': case 'exclude_product_ids': if (!is_array($coupon[$key])) { _doing_it_wrong($key, $key . ' should be an array instead of a string.', '2.7'); $coupon['excluded_product_ids'] = wc_string_to_array($value); } break; case 'exclude_product_categories': case 'excluded_product_categories': if (!is_array($coupon[$key])) { _doing_it_wrong($key, $key . ' should be an array instead of a string.', '2.7'); $coupon['excluded_product_categories'] = wc_string_to_array($value); } break; case 'product_ids': if (!is_array($coupon[$key])) { _doing_it_wrong($key, $key . ' should be an array instead of a string.', '2.7'); $coupon[$key] = wc_string_to_array($value); } break; case 'individual_use': case 'free_shipping': case 'exclude_sale_items': if (!is_bool($coupon[$key])) { _doing_it_wrong($key, $key . ' should be true or false instead of yes or no.', '2.7'); $coupon[$key] = wc_string_to_bool($value); } break; case 'expiry_date': $coupon['date_expires'] = $value; break; } } $this->set_code($code); $this->set_props($coupon); }
/** * Return if product manage stock. * * @since 2.7.0 * @param string $context * @return boolean|string true, false, or parent. */ public function get_manage_stock($context = 'view') { $value = $this->get_prop('manage_stock', $context); // Inherit value from parent. if ('view' === $context && false === $value && true === wc_string_to_bool($this->parent_data['manage_stock'])) { $value = 'parent'; } return $value; }
/** * Set if the product is downloadable. * * @since 2.7.0 * @param bool|string */ public function set_downloadable($downloadable) { $this->set_prop('downloadable', wc_string_to_bool($downloadable)); }
/** * Gets information about whether stock was reduced. * * @param WC_Order|int $order * @return bool */ public function get_stock_reduced($order) { $order_id = WC_Order_Factory::get_order_id($order); return wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true)); }
/** * Set if variation. * @param bool $value */ public function set_variation($value) { $this->data['variation'] = wc_string_to_bool($value); }