woocommerce/includes
vedanshujain c69e1f5799 Remove protection as we already diff and update only if needed.
In #26642 we removed adding reduced_stock meta when adding new order item to prevent ghost entries, but in inadvertently exposed an underlying bug where _reduced_stock meta was getting set to 0 if its emtpy.

We were then checking the presence of this meta, but also not reducing the stock in case it was not set.
2020-09-24 00:54:24 +05:30
..
abstracts
admin Remove protection as we already diff and update only if needed. 2020-09-24 00:54:24 +05:30
cli
customizer
data-stores Improve the query to retrieve "Any..."-attributed variations in filtering widget 2020-09-01 16:47:41 +02:00
emails
export
gateways Merge pull request #27616 from woocommerce/fix/26960 2020-09-18 09:34:57 -03:00
import
integrations/maxmind-geolocation Replace 'DIRECTORY_SEPARATOR' with '/' 2020-08-26 15:50:34 -05:00
interfaces
legacy Fixed usage of package tag in REST API and templates 2020-09-17 11:56:08 -03:00
libraries
log-handlers
payment-tokens
queue
rest-api Fixed usage of package tag in REST API and templates 2020-09-17 11:56:08 -03:00
shipping Fixed use __DIR__ for relative paths 2020-08-26 18:46:44 -03:00
shortcodes Fixed $columns type in docblock 2020-08-21 12:55:28 -05:00
theme-support
tracks remove WC_Admin_Setup_Wizard_Tracking from tracking classes 2020-09-18 15:26:18 -03:00
traits
walkers
wccom-site
widgets Reintroduce adjust_posts_count, and remove unnecessary comment. 2020-09-10 15:17:43 +02:00
README.md
class-wc-ajax.php Replace 'DIRECTORY_SEPARATOR' with '/' 2020-08-26 17:02:07 -05:00
class-wc-api.php Fixed usage of package tag in REST API and templates 2020-09-17 11:56:08 -03:00
class-wc-auth.php Fixed usage of package tag in REST API and templates 2020-09-17 11:56:08 -03:00
class-wc-autoloader.php
class-wc-background-emailer.php
class-wc-background-updater.php
class-wc-breadcrumb.php
class-wc-cache-helper.php
class-wc-cart-fees.php
class-wc-cart-session.php
class-wc-cart-totals.php
class-wc-cart.php Prevented zero from being considered empty when validating posted variation attributes 2020-09-09 11:29:31 -07:00
class-wc-checkout.php
class-wc-cli.php
class-wc-comments.php
class-wc-countries.php Use reference in wc_asort_by_locale 2020-09-10 16:02:39 -03:00
class-wc-coupon.php
class-wc-customer-download-log.php
class-wc-customer-download.php
class-wc-customer.php
class-wc-data-exception.php
class-wc-data-store.php
class-wc-datetime.php
class-wc-deprecated-action-hooks.php
class-wc-deprecated-filter-hooks.php
class-wc-discounts.php
class-wc-download-handler.php
class-wc-emails.php Update version in @since tag of the woocommerce_should_send_no_stock_notification filter 2020-09-18 12:08:36 -03:00
class-wc-embed.php
class-wc-form-handler.php Merge pull request #27219 from woocommerce/fix/filter-quantity-in-add_to_cart_handler_grouped 2020-09-12 15:56:49 -03:00
class-wc-frontend-scripts.php
class-wc-geo-ip.php
class-wc-geolite-integration.php
class-wc-geolocation.php
class-wc-https.php
class-wc-install.php Merge pull request #27047 from woocommerce/fix/26972 2020-09-18 16:46:43 -03:00
class-wc-integrations.php
class-wc-log-levels.php
class-wc-logger.php
class-wc-meta-data.php
class-wc-order-factory.php
class-wc-order-item-coupon.php
class-wc-order-item-fee.php
class-wc-order-item-meta.php
class-wc-order-item-product.php
class-wc-order-item-shipping.php
class-wc-order-item-tax.php
class-wc-order-item.php
class-wc-order-query.php
class-wc-order-refund.php
class-wc-order.php
class-wc-payment-gateways.php
class-wc-payment-tokens.php
class-wc-post-data.php
class-wc-post-types.php Fix #27436 2020-08-22 17:22:45 +12:00
class-wc-privacy-background-process.php
class-wc-privacy-erasers.php
class-wc-privacy-exporters.php
class-wc-privacy.php Replace 'DIRECTORY_SEPARATOR' with '/' 2020-08-26 15:50:34 -05:00
class-wc-product-attribute.php
class-wc-product-download.php
class-wc-product-external.php
class-wc-product-factory.php
class-wc-product-grouped.php
class-wc-product-query.php
class-wc-product-simple.php
class-wc-product-variable.php Revert improved filtering for variations. 2020-09-09 17:36:26 +02:00
class-wc-product-variation.php
class-wc-query.php Reintroduce adjust_posts_count, and remove unnecessary comment. 2020-09-10 15:17:43 +02:00
class-wc-rate-limiter.php
class-wc-regenerate-images-request.php
class-wc-regenerate-images.php Improve choice of words 2020-08-25 18:03:03 -03:00
class-wc-register-wp-admin-settings.php
class-wc-rest-authentication.php Fixed usage of package tag in REST API and templates 2020-09-17 11:56:08 -03:00
class-wc-rest-exception.php Fixed usage of package tag in REST API and templates 2020-09-17 11:56:08 -03:00
class-wc-session-handler.php
class-wc-shipping-rate.php
class-wc-shipping-zone.php Replace 'DIRECTORY_SEPARATOR' with '/' 2020-08-26 15:50:34 -05:00
class-wc-shipping-zones.php
class-wc-shipping.php
class-wc-shortcodes.php
class-wc-structured-data.php
class-wc-tax.php
class-wc-template-loader.php
class-wc-tracker.php Update includes/class-wc-tracker.php 2020-09-18 14:30:39 +02:00
class-wc-validation.php
class-wc-webhook.php Replace 'DIRECTORY_SEPARATOR' with '/' 2020-08-26 15:50:34 -05:00
class-woocommerce.php Bump WC version to 4.7.0 2020-09-19 15:24:12 -03:00
wc-account-functions.php
wc-attribute-functions.php
wc-cart-functions.php
wc-conditional-functions.php
wc-core-functions.php Merge pull request #27416 from woocommerce/fix/27415 2020-09-17 10:35:43 -03:00
wc-coupon-functions.php Fix docblock summary for wc_get_coupon_id_by_code 2020-08-22 22:20:12 +02:00
wc-deprecated-functions.php
wc-formatting-functions.php Improve bool <-> string conversion functions docs 2020-09-13 13:01:14 +02:00
wc-notice-functions.php
wc-order-functions.php
wc-order-item-functions.php
wc-page-functions.php
wc-product-functions.php
wc-rest-functions.php
wc-stock-functions.php
wc-template-functions.php Encapsulate scope of `c` variable 2020-09-08 09:20:18 +02:00
wc-template-hooks.php
wc-term-functions.php
wc-update-functions.php Improve the query to retrieve "Any..."-attributed variations in filtering widget 2020-09-01 16:47:41 +02:00
wc-user-functions.php Improve choice of words 2020-08-25 18:03:03 -03:00
wc-webhook-functions.php
wc-widget-functions.php

README.md

WooCommerce includes files

This directory contains WooCommerce legacy code. Ideally, the code in this folder should only get the minimum required changes for bug fixing, and any new code should go in the src directory instead.

Interacting with the src folder

Whenever you need to get an instance of a class from the src directory, please don't instantiate it directly, but instead use the container. To get an instance of the container itself you can use the wc_get_container function, for example:

$container = wc_get_container();
$service = $container->get( \Automattic\WooCommerce\TheNamespace\TheService::class );
$service->do_something();

The exception to this rule might be data-only classes that could be created the old way (using a plain new statement); but in general, all classes in the src directory are registered in the container and should be resolved using it.

Adding new actions and filters

Please take a look at the considerations for creation new hooks in src code, as they apply for includes code as well. The short version is that new hooks should be introduced only if they provide a valuable extension point for plugins, and not with the purpose of driving WooCommerce's internal logic.

Writing unit tests

As it's the case for the src folder, writing unit tests is generally mandatory if you are a WooCommerce team member or a contributor from another Automattic team, and encouraged if you are an external contributor. Tests should cover any new code (although as mentioned, adding new code in includes should be rare) and any modifications to existing code.

In order to make it easier to write unit tests, there are a couple of mechanisms in place that you can use:

  • The code hacker. Pros: you don't need to do any special changes to your code to make it testable. Cons: it's a hack, the tested code is being actually modified while being loaded by the PHP engine, so not an ideal solution.

  • The legacy proxy and the related helper methods in WC_Unit_Test_case: although these are intended in principle for writing tests for code in the src directory, they can be used for includes code as well. Pros: a clean approach, no hacks involved. Cons: you need to modify your code to use the proxy whenever you need to call a function or static method that makes the code difficult to test.

It's up to you as a contributor to decide which mechanism to use in each case. Choose wisely.