From 752e80acfaea9b75441562561b68923fe97e0cf5 Mon Sep 17 00:00:00 2001 From: Shani Date: Tue, 30 Jul 2024 10:46:59 -0400 Subject: [PATCH] Docs/linter fixes code snippets (#50102) * Adds merchant code-snippets * Adds updated manifest.json * Fixes linting issues on a number of files * Adds manifest.json again * Additional linter fixes * Updates manifest.json --------- Co-authored-by: Shani Banerjee --- .../check_payment_method_support.md | 44 ++++ .../configuring_special_tax_scenarios.md | 81 +++++++ ...arketplace_suggestions_programmatically.md | 13 ++ ...ing_custom_fields_in_your_theme_or_site.md | 41 ++++ .../free_shipping_customization.md | 147 ++++++++++++ ...kup_advacned_settings_and_customization.md | 37 +++ .../making_translations_upgrade_safe.md | 29 +++ docs/code-snippets/shipping_method_api.md | 210 ++++++++++++++++++ ...hind_load_balanacers_or_reverse_proxies.md | 22 ++ .../uninstall_remove_all_woocommerce_data.md | 26 +++ ...erver_to_protect_your_uploads_directory.md | 35 +++ docs/docs-manifest.json | 101 ++++++++- 12 files changed, 784 insertions(+), 2 deletions(-) create mode 100644 docs/code-snippets/check_payment_method_support.md create mode 100644 docs/code-snippets/configuring_special_tax_scenarios.md create mode 100644 docs/code-snippets/disabling_marketplace_suggestions_programmatically.md create mode 100644 docs/code-snippets/displaying_custom_fields_in_your_theme_or_site.md create mode 100644 docs/code-snippets/free_shipping_customization.md create mode 100644 docs/code-snippets/legacy_local_pickup_advacned_settings_and_customization.md create mode 100644 docs/code-snippets/making_translations_upgrade_safe.md create mode 100644 docs/code-snippets/shipping_method_api.md create mode 100644 docs/code-snippets/ssl_and_https_and_woocommerce_websites_behind_load_balanacers_or_reverse_proxies.md create mode 100644 docs/code-snippets/uninstall_remove_all_woocommerce_data.md create mode 100644 docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md diff --git a/docs/code-snippets/check_payment_method_support.md b/docs/code-snippets/check_payment_method_support.md new file mode 100644 index 00000000000..d28fcef8b9a --- /dev/null +++ b/docs/code-snippets/check_payment_method_support.md @@ -0,0 +1,44 @@ +--- +post_title: Check if a Payment Method Support Refunds, Subscriptions or Pre-orders +menu_title: Payment method support for refunds, subscriptions, pre-orders +tags: payment-methods +current wccom url: https://woocommerce.com/document/check-if-payment-gateway-supports-refunds-subscriptions-preorders/ +--- + +# Check if a Payment Method Support Refunds, Subscriptions or Pre-orders + +If a payment method's documentation doesn’t clearly outline the supported features, you can often find what features are supported by looking at payment methods code. + +Payment methods can add support for certain features from WooCommerce and its extensions. For example, a payment method can support refunds, subscriptions or pre-orders functionality. + +## Simplify Commerce example + +Taking the Simplify Commerce payment method as an example, open the plugin files in your favorite editor and search for `$this->supports`. You'll find the supported features: + +```php +class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway { + +/** * Constructor */ + public function __construct() { + $this->id + = 'simplify_commerce'; + $this->method_title + = __( 'Simplify Commerce', 'woocommerce' ); + $this->method_description = __( 'Take payments via Simplify Commerce - uses simplify.js to create card tokens and the Simplify Commerce SDK. Requires SSL when sandbox is disabled.', 'woocommerce' ); + $this->has_fields = true; + $this->supports = array( + 'subscriptions', + 'products', + 'subscription_cancellation', + 'subscription_reactivation', + 'subscription_suspension', + 'subscription_amount_changes', + 'subscription_payment_method_change', + 'subscription_date_changes', + 'default_credit_card_form', + 'refunds', + 'pre-orders' + ); +``` + +If you don’t find `$this->supports` in the plugin files, that may mean that the payment method isn’t correctly declaring support for refunds, subscripts or pre-orders. diff --git a/docs/code-snippets/configuring_special_tax_scenarios.md b/docs/code-snippets/configuring_special_tax_scenarios.md new file mode 100644 index 00000000000..6b3c7e07126 --- /dev/null +++ b/docs/code-snippets/configuring_special_tax_scenarios.md @@ -0,0 +1,81 @@ +--- +post_title: Code snippets for configuring special tax scenarios +menu_title: Configuring special tax scenarios +tags: code-snippet, tax +current wccom url: https://woocommerce.com/document/setting-up-taxes-in-woocommerce/configuring-specific-tax-setups-in-woocommerce/#configuring-special-tax-setups +--- + +# Code snippets for configuring special tax scenarios + +## Scenario A: Charge the same price regardless of location and taxes + +Scenario A: Charge the same price regardless of location and taxes + +If a store enters product prices including taxes, but levies various location-based tax rates, the prices will appear to change depending on which tax rate is applied. In reality, the base price remains the same, but the taxes influence the total. [Follow this link for a detailed explanation](https://woocommerce.com/document/how-taxes-work-in-woocommerce/#cross-border-taxes). + +Some merchants prefer to dynamically change product base prices to account for the changes in taxes and so keep the total price consistent regardless of tax rate. Enable that functionality by adding the following snippet to your child theme’s functions.php file or via a code snippet plugin. + +```php +cart->subtotal <= 110 ) + $tax_class = 'Zero Rate'; + + return $tax_class; +} +``` + +## Scenario C: Apply different tax rates based on the customer role + +Some merchants may require different tax rates to be applied based on a customer role to accommodate for wholesale status or tax exemption. + +To enable this functionality, add the following snippet to your child theme’s functions.php file or via a code snippet plugin. In this snippet, users with “administrator” capabilities will be assigned the **Zero rate tax class**. Adjust it according to your requirements. + +```php +get_id(), 'woo_custom_field', true ); + + if ( ! empty( $custom_field_value ) ) { + echo '
' . esc_html( $custom_field_value ) . '
'; + } +} + +add_action( 'woocommerce_before_add_to_cart_form', 'woocommerce_custom_field_example', 10 ); +``` diff --git a/docs/code-snippets/free_shipping_customization.md b/docs/code-snippets/free_shipping_customization.md new file mode 100644 index 00000000000..6d4d700a39f --- /dev/null +++ b/docs/code-snippets/free_shipping_customization.md @@ -0,0 +1,147 @@ +--- +post_title: Free Shipping Customizations +menu_title: Free shipping customizations +tags: code-snippets +current wccom url: https://woocommerce.com/document/free-shipping/#advanced-settings-customization +combined with: https://woocommerce.com/document/hide-other-shipping-methods-when-free-shipping-is-available/#use-a-plugin +--- + +## Free Shipping: Advanced Settings/Customization + +### Overview + +By default, WooCommerce shows all shipping methods that match the customer and the cart contents. This means Free Shipping also shows along with Flat Rate and other Shipping Methods. + +The functionality to hide all other methods, and only show Free Shipping, requires either custom PHP code or a plugin/extension. + +### Adding code + +Before adding snippets, clear your WooCommerce cache. Go to WooCommerce > System Status > Tools > WooCommerce Transients > Clear transients. + +Add this code to your child theme’s `functions.php`, or via a plugin that allows custom functions to be added. Please don’t add custom code directly to a parent theme’s `functions.php` as changes are entirely erased when a parent theme updates. + +## Code Snippets + +### Enabling or Disabling Free Shipping via Hooks + +You can hook into the `is_available` function of the free shipping method. + +```php +return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available ); +``` + +This means you can use `add_filter()` on `woocommerce_shipping_free_shipping_is_available` and return `true` or `false`. + +### How do I only show Free Shipping? + +The following snippet hides everything but `free_shipping`, if it’s available and the customer's cart qualifies. + +```php +/** + * Hide shipping rates when free shipping is available. + * Updated to support WooCommerce 2.6 Shipping Zones. + * + * @param array $rates Array of rates found for the package. + * @return array + */ +function my_hide_shipping_when_free_is_available( $rates ) { + $free = array(); + foreach ( $rates as $rate_id => $rate ) { + if ( 'free_shipping' === $rate->method_id ) { + $free[ $rate_id ] = $rate; + break; + } + } + return ! empty( $free ) ? $free : $rates; +} +add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 ); +``` + +### How do I only show Local Pickup and Free Shipping? + +The snippet below hides everything but `free_shipping` and `local_pickup`, if it’s available and the customer's cart qualifies. + +```php + +/** + * Hide shipping rates when free shipping is available, but keep "Local pickup" + * Updated to support WooCommerce 2.6 Shipping Zones + */ + +function hide_shipping_when_free_is_available( $rates, $package ) { + $new_rates = array(); + foreach ( $rates as $rate_id => $rate ) { + // Only modify rates if free_shipping is present. + if ( 'free_shipping' === $rate->method_id ) { + $new_rates[ $rate_id ] = $rate; + break; + } + } + + if ( ! empty( $new_rates ) ) { + //Save local pickup if it's present. + foreach ( $rates as $rate_id => $rate ) { + if ('local_pickup' === $rate->method_id ) { + $new_rates[ $rate_id ] = $rate; + break; + } + } + return $new_rates; + } + + return $rates; +} + +add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 ); +``` + +### Only show free shipping in all states except… + +This snippet results in showing only free shipping in all states except the exclusion list. It hides free shipping if the customer is in one of the states listed: + +```php +/** + * Hide ALL shipping options when free shipping is available and customer is NOT in certain states + * + * Change $excluded_states = array( 'AK','HI','GU','PR' ); to include all the states that DO NOT have free shipping + */ +add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 2 ); + +/** + * Hide ALL Shipping option when free shipping is available + * + * @param array $available_methods + */ +function hide_all_shipping_when_free_is_available( $rates, $package ) { + + $excluded_states = array( 'AK','HI','GU','PR' ); + if( isset( $rates['free_shipping'] ) AND !in_array( WC()->customer->shipping_state, $excluded_states ) ) : + // Get Free Shipping array into a new array + $freeshipping = array(); + $freeshipping = $rates['free_shipping']; + + // Empty the $available_methods array + unset( $rates ); + + // Add Free Shipping back into $avaialble_methods + $rates = array(); + $rates[] = $freeshipping; + + endif; + + if( isset( $rates['free_shipping'] ) AND in_array( WC()->customer->shipping_state, $excluded_states ) ) { + + // remove free shipping option + unset( $rates['free_shipping'] ); + + } + + return $rates; +} +``` + +### Enable Shipping Methods on a per Class / Product Basis, split orders, or other scenarios? + +Need more flexibility? Take a look at our [premium Shipping Method extensions](https://woocommerce.com/product-category/woocommerce-extensions/shipping-methods/). + + diff --git a/docs/code-snippets/legacy_local_pickup_advacned_settings_and_customization.md b/docs/code-snippets/legacy_local_pickup_advacned_settings_and_customization.md new file mode 100644 index 00000000000..d05a8c7e788 --- /dev/null +++ b/docs/code-snippets/legacy_local_pickup_advacned_settings_and_customization.md @@ -0,0 +1,37 @@ +--- +post_title: Legacy Local Pickup Advanced Settings and Customization +tags: code-snippet +current wccom url: https://woocommerce.com/document/local-pickup/#advanced-settings-customization +note: Docs links out to Skyverge's site for howto add a custom email - do we have our own alternative? +--- + +# Advanced settings and customization for legacy Local Pickup + +## Disable local taxes when using local pickup + +Local Pickup calculates taxes based on your store’s location (address) by default, and not the customer’s address. Add this snippet at the end of your theme's `functions.php` to use your standard tax configuration instead: + +```php +add_filter( 'woocommerce_apply_base_tax_for_local_pickup', '__return_false' ); +``` + +Regular taxes is then used when local pickup is selected, instead of store-location-based taxes. + +## Changing the location for local taxes + +To charge local taxes based on the postcode and city of the local pickup location, you need to define the shop’s base city and post code using this example code: + +```php +add_filter( 'woocommerce_countries_base_postcode', create_function( '', 'return "80903";' ) ); +add_filter( 'woocommerce_countries_base_city', create_function( '', 'return "COLORADO SPRINGS";' ) ); +``` + +Update `80903` to reflect your preferred postcode/zip, and `COLORADO SPRINGS` with your preferred town or city. + +## Custom emails for local pickup + +_Shipping Address_ is not displayed on the admin order emails when Local Pickup is used as the shipping method. + +Since all core shipping options use the standard order flow, customers receive the same order confirmation email whether they select local pickup or any other shipping option. +Use this guide to create custom emails for local pickup if you’d like to send a separate email for local pickup orders: [How to Add a Custom WooCommerce Email](https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/). + diff --git a/docs/code-snippets/making_translations_upgrade_safe.md b/docs/code-snippets/making_translations_upgrade_safe.md new file mode 100644 index 00000000000..2753c1f43bf --- /dev/null +++ b/docs/code-snippets/making_translations_upgrade_safe.md @@ -0,0 +1,29 @@ +--- +post_title: Making your translation upgrade safe +menu_title: Translation upgrade safety +tags: code-snippet +current wccom url: https://woocommerce.com/document/woocommerce-localization/#making-your-translation-upgrade-safe +--- + +# Making your translation upgrade safe + +Like all other plugins, WooCommerce keeps translations in `wp-content/languages/plugins`. + +However, if you want to include a custom translation, you can add them to `wp-content/languages/woocommerce`, or you can use a snippet to load a custom translation stored elsewhere: + +```php +// Code to be placed in functions.php of your theme or a custom plugin file. +add_filter( 'load_textdomain_mofile', 'load_custom_plugin_translation_file', 10, 2 ); + +/* + * Replace 'textdomain' with your plugin's textdomain. e.g. 'woocommerce'. + * File to be named, for example, yourtranslationfile-en_GB.mo + * File to be placed, for example, wp-content/lanaguages/textdomain/yourtranslationfile-en_GB.mo + */ +function load_custom_plugin_translation_file( $mofile, $domain ) { + if ( 'textdomain' === $domain ) { + $mofile = WP_LANG_DIR . '/textdomain/yourtranslationfile-' . get_locale() . '.mo'; + } + return $mofile; +} +``` diff --git a/docs/code-snippets/shipping_method_api.md b/docs/code-snippets/shipping_method_api.md new file mode 100644 index 00000000000..5752e45f2ce --- /dev/null +++ b/docs/code-snippets/shipping_method_api.md @@ -0,0 +1,210 @@ +--- +post_title: Shipping Method API +menu_title: Shipping method API +tags: shipping, API +current wccom url: https://woocommerce.com/document/shipping-method-api/ +--- + + +# Shipping Method API + +WooCommerce has a shipping method API which plugins can use to add their own rates. This article outlines steps to create a new shipping method and interact with the API. + +## Create a plugin + +First, create a regular WordPress/WooCommerce plugin (see [Create a plugin](https://woocommerce.com/document/create-a-plugin/)). You’ll define your shipping method class in this plugin file and maintain it outside of WooCommerce. + +## Create a function to house your class + +To ensure the classes you need to extend exist, you should wrap your class in a function which is called after all plugins are loaded: + +```php +function your_shipping_method_init() { + // Your class will go here +} + +add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' ); +``` + +## Create your class + +Create your class and place it inside the function you just created. Make sure it extends the shipping method class so that you have access to the API. You’ll see below we also init our shipping method options. + +```php +if ( ! class_exists( 'WC_Your_Shipping_Method' ) ) { + class WC_Your_Shipping_Method extends WC_Shipping_Method { + /** + * Constructor for your shipping class + * + * @access public + * @return void + */ + public function __construct() { + $this->id = 'your_shipping_method'; + $this->title = __( 'Your Shipping Method' ); + $this->method_description = __( 'Description of your shipping method' ); // + $this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled + $this->init(); + } + + /** + * Init your settings + * + * @access public + * @return void + */ + function init() { + // Load the settings API + $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings + $this->init_settings(); // This is part of the settings API. Loads settings you previously init. + + // Save settings in admin if you have any defined + add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); + } + + /** + * calculate_shipping function. + * + * @access public + * @param mixed $package + * @return void + */ + public function calculate_shipping( $package ) { + // This is where you'll add your rates + } + } +} +``` + +As well as declaring your class, you also need to tell WooCommerce it exists with another function: + +```php +function add_your_shipping_method( $methods ) { + $methods['your_shipping_method'] = 'WC_Your_Shipping_Method'; + return $methods; +} + +add_filter( 'woocommerce_shipping_methods', 'add_your_shipping_method' ); +``` + +## Defining settings/options + +You can define your options once the above is in place by using the settings API. In the snippets above you’ll notice we `init_form_fields` and `init_settings`. These load up the settings API. To see how to add settings, see [WooCommerce settings API](https://woocommerce.com/document/settings-api/). + +## The calculate_shipping() method + +Add your rates by usign the `calculate_shipping()` method. WooCommerce calls this when doing shipping calculations. Do your plugin specific calculations here and then add the rates via the API. Like so: + +```php +$rate = array( + 'label' => "Label for the rate", + 'cost' => '10.99', + 'calc_tax' => 'per_item' +); + +// Register the rate +$this->add_rate( $rate ); +``` + +`Add_rate` takes an array of options. The defaults/possible values for the array are as follows: + +```php +$defaults = array( + 'label' => '', // Label for the rate + 'cost' => '0', // Amount for shipping or an array of costs (for per item shipping) + 'taxes' => '', // Pass an array of taxes, or pass nothing to have it calculated for you, or pass 'false' to calculate no tax for this method + 'calc_tax' => 'per_order' // Calc tax per_order or per_item. Per item needs an array of costs passed via 'cost' +); +``` + +Your shipping method can pass as many rates as you want – just ensure that the id for each is different. The user will get to choose rate during checkout. + + +## Piecing it all together + +The skeleton shipping method code all put together looks like this: + +```php +id = 'your_shipping_method'; // Id for your shipping method. Should be uunique. + $this->method_title = __( 'Your Shipping Method' ); // Title shown in admin + $this->method_description = __( 'Description of your shipping method' ); // Description shown in admin + + $this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled + $this->title = "My Shipping Method"; // This can be added as an setting but for this example its forced. + + $this->init(); + } + + /** + * Init your settings + * + * @access public + * @return void + */ + function init() { + // Load the settings API + $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings + $this->init_settings(); // This is part of the settings API. Loads settings you previously init. + + // Save settings in admin if you have any defined + add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); + } + + /** + * calculate_shipping function. + * + * @access public + * @param array $package + * @return void + */ + public function calculate_shipping( $package = array() ) { + $rate = array( + 'label' => $this->title, + 'cost' => '10.99', + 'calc_tax' => 'per_item' + ); + + // Register the rate + $this->add_rate( $rate ); + } + } + } + } + + add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' ); + + function add_your_shipping_method( $methods ) { + $methods['your_shipping_method'] = 'WC_Your_Shipping_Method'; + return $methods; + } + + add_filter( 'woocommerce_shipping_methods', 'add_your_shipping_method' ); +} +``` + +For further information, please check out the [Shipping Method API Wiki](https://github.com/woocommerce/woocommerce/wiki/Shipping-Method-API). diff --git a/docs/code-snippets/ssl_and_https_and_woocommerce_websites_behind_load_balanacers_or_reverse_proxies.md b/docs/code-snippets/ssl_and_https_and_woocommerce_websites_behind_load_balanacers_or_reverse_proxies.md new file mode 100644 index 00000000000..8f6d733bec3 --- /dev/null +++ b/docs/code-snippets/ssl_and_https_and_woocommerce_websites_behind_load_balanacers_or_reverse_proxies.md @@ -0,0 +1,22 @@ +--- +post_title: SSL and HTTPS and WooCommerce +menu_title: SSL and HTTPS and WooCommerce +tags: code-snippet +current wccom url: https://woocommerce.com/document/ssl-and-https/#websites-behind-load-balancers-or-reverse-proxies +--- + +## Websites behind load balancers or reverse proxies + +WooCommerce uses the `is_ssl()` WordPress function to verify if your website using SSL or not. + +`is_ssl()` checks if the connection is via HTTPS or on Port 443. However, this won’t work for websites behind load balancers, especially websites hosted at Network Solutions. For details, read [WordPress is_ssl() function reference notes](https://codex.wordpress.org/Function_Reference/is_ssl#Notes). + +Websites behind load balancers or reverse proxies that support `HTTP_X_FORWARDED_PROTO` can be fixed by adding the following code to the `wp-config.php` file, above the require_once call: + +```php +if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { + $_SERVER['HTTPS'] = 'on'; +} +``` + +**Note:** If you use CloudFlare, you need to configure it. Check their documentation. diff --git a/docs/code-snippets/uninstall_remove_all_woocommerce_data.md b/docs/code-snippets/uninstall_remove_all_woocommerce_data.md new file mode 100644 index 00000000000..be83e2bca03 --- /dev/null +++ b/docs/code-snippets/uninstall_remove_all_woocommerce_data.md @@ -0,0 +1,26 @@ +--- +post_title: Uninstall and remove all WooCommerce Data +menu_title: Uninstalling and removing data +tags: code-snippet +current wccom url: https://woocommerce.com/document/installing-uninstalling-woocommerce/#uninstalling-woocommerce +--- + +# Uninstall and remove all WooCommerce Data + +The WooCommerce plugin can be uninstalled like any other WordPress plugin. By default, the WooCommerce data is left in place though. + +If you need to remove *all* WooCommerce data as well, including products, order data, coupons, etc., you need to to modify the site’s `wp-config.php` *before* deactivating and deleting the WooCommerce plugin. + +As this action is destructive and permanent, the information is provided as is. WooCommerce Support cannot help with this process or anything that happens as a result. + +To fully remove all WooCommerce data from your WordPress site, open `wp-config.php`, scroll down to the bottom of the file, and add the following constant on its own line above `/* That’s all, stop editing. */`. + +```php +define( 'WC_REMOVE_ALL_DATA', true ); + +/* That’s all, stop editing! Happy publishing. */ +``` + +Then, once the changes are saved to the file, when you deactivate and delete WooCommerce, all of its data is removed from your WordPress site database. + +![Uninstall WooCommerce WPConfig](https://woocommerce.com/wp-content/uploads/2020/03/uninstall_wocommerce_plugin_wpconfig.png) diff --git a/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md b/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md new file mode 100644 index 00000000000..3f3171a90e5 --- /dev/null +++ b/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md @@ -0,0 +1,35 @@ +--- +post_title: Using NGINX server to protect your upload directory +menu_title: NGINX server to protect upload directory +tags: code-snippet +current wccom url: https://woocommerce.com/document/digital-downloadable-product-handling/#protecting-your-uploads-directory +--- + +## Using NGINX server to protect your upload directory + +If you using NGINX server for your site along with **X-Accel-Redirect/X-Sendfile** or **Force Downloads** download method, it is necessary that you add this configuration for better security: + +```php +# Protect WooCommerce upload folder from being accessed directly. +# You may want to change this config if you are using "X-Accel-Redirect/X-Sendfile" or "Force Downloads" method for downloadable products. +# Place this config towards the end of "server" block in NGINX configuration. +location ~* /wp-content/uploads/woocommerce_uploads/ { + if ( $upstream_http_x_accel_redirect = "" ) { + return 403; + } + internal; +} +``` + +And this the configuration in case you are using **Redirect only** download method: + +```php +# Protect WooCommerce upload folder from being accessed directly. +# You may want to change this config if you are using "Redirect Only" method for downloadable products. +# Place this config towards the end of "server" block in NGINX configuration. +location ~* /wp-content/uploads/woocommerce_uploads/ { + autoindex off; +} +``` + +If you do not know which web server you are using, please reach out to your host along with a link to this support page. diff --git a/docs/docs-manifest.json b/docs/docs-manifest.json index 967f83980af..96457b28a0b 100644 --- a/docs/docs-manifest.json +++ b/docs/docs-manifest.json @@ -52,6 +52,15 @@ "category_slug": "code-snippets", "category_title": "Code Snippets", "posts": [ + { + "post_title": "Using NGINX server to protect your upload directory", + "menu_title": "NGINX server to protect upload directory", + "tags": "code-snippet", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md", + "hash": "5d7afe5c8217c3a5f753eb2f468b8304f7f9b5b1275461abf2146e4de82ed6b2", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md", + "id": "8b325d3483f9a8d09961ca1082839752137faebf" + }, { "post_title": "Useful core functions", "tags": "code-snippet", @@ -60,6 +69,15 @@ "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/useful-functions.md", "id": "0d99f1dee7c104b5899fd62b96157fb6709ebfb8" }, + { + "post_title": "Uninstall and remove all WooCommerce Data", + "menu_title": "Uninstalling and removing data", + "tags": "code-snippet", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/uninstall_remove_all_woocommerce_data.md", + "hash": "73483ff158ceac81685a9cd52335dc98e99ac7f84d89cdbcf4ce994e18afe30d", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/uninstall_remove_all_woocommerce_data.md", + "id": "36b571fcf2471737729ab4769e2c721b2248187f" + }, { "post_title": "Unhook and remove WooCommerce emails", "tags": "code-snippet", @@ -68,6 +86,24 @@ "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/unhook--remove-woocommerce-emails.md", "id": "0fdfe3b483ae74a9e5dc1fc21b80814462222ec3" }, + { + "post_title": "SSL and HTTPS and WooCommerce", + "menu_title": "SSL and HTTPS and WooCommerce", + "tags": "code-snippet", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/ssl_and_https_and_woocommerce_websites_behind_load_balanacers_or_reverse_proxies.md", + "hash": "92a5091c27d1af6c0b49df143dd13886fb2cb30538fa877f68000cab69f4f502", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/ssl_and_https_and_woocommerce_websites_behind_load_balanacers_or_reverse_proxies.md", + "id": "78d5b5a20ce6471b74f809386eff41fffe2d1adb" + }, + { + "post_title": "Shipping Method API", + "menu_title": "Shipping method API", + "tags": "shipping, API", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/shipping_method_api.md", + "hash": "bd7cbc361fe94acaa40fbc5befa8d14f302705a9d700dd7d7e78a482b003fe0b", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/shipping_method_api.md", + "id": "a419b97e5594918a015c61227ad9226c509eb314" + }, { "post_title": "Rename a country", "tags": "code-snippet", @@ -84,6 +120,15 @@ "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/number-of-products-per-row.md", "id": "7369dc328c49206771a2f8d0da5d920c480b5207" }, + { + "post_title": "Making your translation upgrade safe", + "menu_title": "Translation upgrade safety", + "tags": "code-snippet", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/making_translations_upgrade_safe.md", + "hash": "e2d296630d7af888a072de51870f3b4ff311b3c29f706fda735bd8f9122c8710", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/making_translations_upgrade_safe.md", + "id": "0c1add87ef9f5452b4c8404bb55021ad8265c171" + }, { "post_title": "Add link to logged data", "menu_title": "Add link to logged data", @@ -93,6 +138,40 @@ "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/link-to-logged-data.md", "id": "34da337f79be5ce857024f541a99d302174ca37d" }, + { + "post_title": "Legacy Local Pickup Advanced Settings and Customization", + "tags": "code-snippet", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/legacy_local_pickup_advacned_settings_and_customization.md", + "hash": "d0269f1ee2700356672a032e4e54491666b901765045f7c5224ef07eeb9d9598", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/legacy_local_pickup_advacned_settings_and_customization.md", + "id": "c4d4a2276fc251082a80a8330eea1eb62a97c3bb" + }, + { + "post_title": "Free Shipping Customizations", + "menu_title": "Free shipping customizations", + "tags": "code-snippets", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/free_shipping_customization.md", + "hash": "c18884a45e4e1cc7b174820c2553d2722df95b98f6783c2700096a5b7e19bffd", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/free_shipping_customization.md", + "id": "cac6f1ccd661588e9a5fa7405643e9c6d4da388e" + }, + { + "post_title": "Displaying Custom Fields in Your Theme or Site", + "menu_title": "Displaying custom fields in theme", + "tags": "code-snippet", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/displaying_custom_fields_in_your_theme_or_site.md", + "hash": "8048c2e9e5d25268d17d4f4ca7929e265eddbd4653318dd8f544856ddecd39dd", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/displaying_custom_fields_in_your_theme_or_site.md", + "id": "3e3fd004afda355cf9dbb05f0967523d6d0da1ce" + }, + { + "post_title": "Disabling Marketplace Suggestions Programmatically", + "menu_title": "Disabling marketplace suggestions", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/disabling_marketplace_suggestions_programmatically.md", + "hash": "3d5bd50d64a46efaea99efb0a87dfdb8882cb83598b7be8a8154ad0e464eb6f5", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/disabling_marketplace_suggestions_programmatically.md", + "id": "94a7a28e5dd3d9394650e66abec2429445e87028" + }, { "post_title": "Customizing checkout fields using actions and filters", "tags": "code-snippet", @@ -101,6 +180,24 @@ "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/customising-checkout-fields.md", "id": "83097d3b7414557fc80dcf9f8f1a708bbdcdd884" }, + { + "post_title": "Code snippets for configuring special tax scenarios", + "menu_title": "Configuring special tax scenarios", + "tags": "code-snippet, tax", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/configuring_special_tax_scenarios.md", + "hash": "128193e0e980f484f354c93e59d34c3948f112e4a1c99158cf3e5d9969db9352", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/configuring_special_tax_scenarios.md", + "id": "a8ab8b6734ba2ac5af7c6653635d15548abdab2a" + }, + { + "post_title": "Check if a Payment Method Support Refunds, Subscriptions or Pre-orders", + "menu_title": "Payment method support for refunds, subscriptions, pre-orders", + "tags": "payment-methods", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/code-snippets/check_payment_method_support.md", + "hash": "6cae4b1fda5980c327c99d6bae8b1978fd05849f07179f0699a174b57d27b862", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/code-snippets/check_payment_method_support.md", + "id": "2919c9fc523bce46f43a5f35f821d0c6623c5ede" + }, { "post_title": "Change a currency symbol", "tags": "code-snippet", @@ -716,7 +813,7 @@ "post_title": "Product editor development handbook", "menu_title": "Development handbook", "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/product-editor-development/product-editor.md", - "hash": "a014d4f53a860ff74eec6cefbe868279616bcad5509b2f30f02bb8e118935c98", + "hash": "b574a4a5476899342cd229033a22ecdf9859914ea34446f8276e2b0ad5cb8c7f", "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/product-editor-development/product-editor.md", "id": "59450404de2750d918137e7cf523e52bedfd7214", "links": { @@ -1367,5 +1464,5 @@ "categories": [] } ], - "hash": "73bcb44585da56302a4dd3056b4a7aab16b58a516f214bbfde7b9b7d7157e84b" + "hash": "d8fe058ebcce4d1f40585f1634b1e98e27063d81dd0dd7783217ab60d0bc915a" } \ No newline at end of file