/** * Get settings array. * * @return array */ public function get_settings() { $settings = apply_filters('woocommerce_payment_gateways_settings', array(array('title' => __('Checkout process', 'woocommerce'), 'type' => 'title', 'id' => 'checkout_process_options'), array('title' => __('Coupons', 'woocommerce'), 'desc' => __('Enable the use of coupons', 'woocommerce'), 'id' => 'woocommerce_enable_coupons', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => 'start', 'desc_tip' => __('Coupons can be applied from the cart and checkout pages.', 'woocommerce')), array('desc' => __('Calculate coupon discounts sequentially', 'woocommerce'), 'id' => 'woocommerce_calc_discounts_sequentially', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce'), 'checkboxgroup' => 'end', 'autoload' => false), array('title' => __('Checkout process', 'woocommerce'), 'desc' => __('Enable guest checkout', 'woocommerce'), 'desc_tip' => __('Allows customers to checkout without creating an account.', 'woocommerce'), 'id' => 'woocommerce_enable_guest_checkout', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => 'start', 'autoload' => false), array('desc' => __('Force secure checkout', 'woocommerce'), 'id' => 'woocommerce_force_ssl_checkout', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => '', 'show_if_checked' => 'option', 'desc_tip' => sprintf(__('Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce'), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3')), 'unforce_ssl_checkout' => array('desc' => __('Force HTTP when leaving the checkout', 'woocommerce'), 'id' => 'woocommerce_unforce_ssl_checkout', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'end', 'show_if_checked' => 'yes'), array('type' => 'sectionend', 'id' => 'checkout_process_options'), array('title' => __('Checkout pages', 'woocommerce'), 'desc' => __('These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce'), 'type' => 'title', 'id' => 'checkout_page_options'), array('title' => __('Cart page', 'woocommerce'), 'desc' => sprintf(__('Page contents: [%s]', 'woocommerce'), apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart')), 'id' => 'woocommerce_cart_page_id', 'type' => 'single_select_page', 'default' => '', 'class' => 'wc-enhanced-select-nostd', 'css' => 'min-width:300px;', 'desc_tip' => true), array('title' => __('Checkout page', 'woocommerce'), 'desc' => sprintf(__('Page contents: [%s]', 'woocommerce'), apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout')), 'id' => 'woocommerce_checkout_page_id', 'type' => 'single_select_page', 'default' => '', 'class' => 'wc-enhanced-select-nostd', 'css' => 'min-width:300px;', 'desc_tip' => true), array('title' => __('Terms and conditions', 'woocommerce'), 'desc' => __('If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce'), 'id' => 'woocommerce_terms_page_id', 'default' => '', 'class' => 'wc-enhanced-select-nostd', 'css' => 'min-width:300px;', 'type' => 'single_select_page', 'desc_tip' => true, 'autoload' => false), array('type' => 'sectionend', 'id' => 'checkout_page_options'), array('title' => __('Checkout endpoints', 'woocommerce'), 'type' => 'title', 'desc' => __('Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce'), 'id' => 'account_endpoint_options'), array('title' => __('Pay', 'woocommerce'), 'desc' => __('Endpoint for the "Checkout → Pay" page.', 'woocommerce'), 'id' => 'woocommerce_checkout_pay_endpoint', 'type' => 'text', 'default' => 'order-pay', 'desc_tip' => true), array('title' => __('Order received', 'woocommerce'), 'desc' => __('Endpoint for the "Checkout → Order received" page.', 'woocommerce'), 'id' => 'woocommerce_checkout_order_received_endpoint', 'type' => 'text', 'default' => 'order-received', 'desc_tip' => true), array('title' => __('Add payment method', 'woocommerce'), 'desc' => __('Endpoint for the "Checkout → Add payment method" page.', 'woocommerce'), 'id' => 'woocommerce_myaccount_add_payment_method_endpoint', 'type' => 'text', 'default' => 'add-payment-method', 'desc_tip' => true), array('title' => __('Delete payment method', 'woocommerce'), 'desc' => __('Endpoint for the delete payment method page.', 'woocommerce'), 'id' => 'woocommerce_myaccount_delete_payment_method_endpoint', 'type' => 'text', 'default' => 'delete-payment-method', 'desc_tip' => true), array('title' => __('Set default payment method', 'woocommerce'), 'desc' => __('Endpoint for the setting a default payment method page.', 'woocommerce'), 'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint', 'type' => 'text', 'default' => 'set-default-payment-method', 'desc_tip' => true), array('type' => 'sectionend', 'id' => 'checkout_endpoint_options'), array('title' => __('Payment gateways', 'woocommerce'), 'desc' => __('Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'woocommerce'), 'type' => 'title', 'id' => 'payment_gateways_options'), array('type' => 'payment_gateways'), array('type' => 'sectionend', 'id' => 'payment_gateways_options'))); if (wc_site_is_https()) { unset($settings['unforce_ssl_checkout']); } return apply_filters('woocommerce_get_settings_' . $this->id, $settings); }
/** * Backports wc_checkout_is_https() to 2.4.x * * @since 4.3.0-beta * @return bool */ public static function wc_checkout_is_https() { if (self::is_wc_version_gte_2_5()) { return wc_checkout_is_https(); } else { return wc_site_is_https() || 'yes' === get_option('woocommerce_force_ssl_checkout') || class_exists('WordPressHTTPS') || strstr(wc_get_page_permalink('checkout'), 'https:'); } }
/** * Check if the checkout is configured for https. Look at options, WP HTTPS plugin, or the permalink itself. * * @since 2.5.0 * @return bool */ function wc_checkout_is_https() { return wc_site_is_https() || 'yes' === get_option('woocommerce_force_ssl_checkout') || class_exists('WordPressHTTPS') || strstr(wc_get_page_permalink('checkout'), 'https:'); }
/** * Check if SSL is enabled and notify the user */ public function admin_notices() { if ($this->enabled == 'no') { return; } $addons = class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order') ? '_addons' : ''; // Check required fields if (!$this->secret_key) { echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; return; } elseif (!$this->publishable_key) { echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; return; } // Simple check for duplicate keys if ($this->secret_key == $this->publishable_key) { echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; return; } // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected if (function_exists('wc_site_is_https') && !wc_site_is_https() && ('no' === get_option('woocommerce_force_ssl_checkout') && !class_exists('WordPressHTTPS'))) { echo '<div class="error"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; } }
/** * Check if SSL is enabled and notify the user */ public function admin_notices() { if ('no' === $this->enabled) { return; } // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. if (function_exists('wc_site_is_https') && !wc_site_is_https() && ('no' === get_option('woocommerce_force_ssl_checkout') && !class_exists('WordPressHTTPS'))) { echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; } }
/** * Get the site index. * * This endpoint describes the capabilities of the site. * * @since 2.3 * @return array Index entity */ public function get_index() { // General site data $available = array('store' => array('name' => get_option('blogname'), 'description' => get_option('blogdescription'), 'URL' => get_option('siteurl'), 'wc_version' => WC()->version, 'version' => WC_API::VERSION, 'routes' => array(), 'meta' => array('timezone' => wc_timezone_string(), 'currency' => get_woocommerce_currency(), 'currency_format' => get_woocommerce_currency_symbol(), 'currency_position' => get_option('woocommerce_currency_pos'), 'thousand_separator' => get_option('woocommerce_price_thousand_sep'), 'decimal_separator' => get_option('woocommerce_price_decimal_sep'), 'price_num_decimals' => wc_get_price_decimals(), 'tax_included' => wc_prices_include_tax(), 'weight_unit' => get_option('woocommerce_weight_unit'), 'dimension_unit' => get_option('woocommerce_dimension_unit'), 'ssl_enabled' => 'yes' === get_option('woocommerce_force_ssl_checkout') || wc_site_is_https(), 'permalinks_enabled' => '' !== get_option('permalink_structure'), 'generate_password' => 'yes' === get_option('woocommerce_registration_generate_password'), 'links' => array('help' => 'https://woothemes.github.io/woocommerce-rest-api-docs/')))); // Find the available routes foreach ($this->get_routes() as $route => $callbacks) { $data = array(); $route = preg_replace('#\\(\\?P(<\\w+?>).*?\\)#', '$1', $route); foreach (self::$method_map as $name => $bitmask) { foreach ($callbacks as $callback) { // Skip to the next route if any callback is hidden if ($callback[1] & self::HIDDEN_ENDPOINT) { continue 3; } if ($callback[1] & $bitmask) { $data['supports'][] = $name; } if ($callback[1] & self::ACCEPT_DATA) { $data['accepts_data'] = true; } // For non-variable routes, generate links if (strpos($route, '<') === false) { $data['meta'] = array('self' => get_woocommerce_api_url($route)); } } } $available['store']['routes'][$route] = apply_filters('woocommerce_api_endpoints_description', $data); } return apply_filters('woocommerce_api_index', $available); }
/** * Test wc_site_is_https(). */ public function test_wc_site_is_https() { $this->assertFalse(wc_site_is_https()); add_filter('pre_option_home', array($this, '_https_url')); $this->assertTrue(wc_site_is_https()); }
/** * Template redirect - if we end up on a page ensure it has the correct http/https url. */ public static function unforce_https_template_redirect() { if (function_exists('is_customize_preview') && is_customize_preview()) { return; } if (!wc_site_is_https() && is_ssl() && $_SERVER['REQUEST_URI'] && !is_checkout() && !is_ajax() && !is_account_page() && apply_filters('woocommerce_unforce_ssl_checkout', true)) { if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) { wp_safe_redirect(preg_replace('|^https://|', 'http://', $_SERVER['REQUEST_URI'])); exit; } else { wp_safe_redirect('http://' . (!empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI']); exit; } } }