woocommerce/plugins/woocommerce/includes
Corey McKrill 9f8ae8b46f
REST API: Ensure meta_data prop contains an array (#34966)
REST API: Ensure meta_data prop contains an array

When filtering the meta_data array of a response with include_meta or
exclude_meta, the array indexes were getting preserved so that it was
possible for the array to not contain a 0 index, but still have some
subsequent numbers. When such an array was converted to JSON, it was
interpreted as an object rather than an array.

This ensures the meta_data array indexes are reset after filtering, and
adds unit tests to check that meta_data always contains an array, and
not an object.
2022-10-05 14:39:33 -07:00
..
abstracts Move props from datastore to order object and implement $save params for DataStore (#34627) 2022-09-28 14:07:41 -03:00
admin Correct the textarea name in the Product Short Description template. (#34936) 2022-10-05 16:05:32 +02:00
blocks create BlocksUtil file - refactor 2022-05-02 11:26:34 +02:00
cli make `wccom` commands text translatable, add application-password section URL (#34363) 2022-08-25 09:27:36 -05:00
customizer Enable WC Customizer panels in customize.php routes also for block themes (#34443) 2022-08-30 12:47:10 +02:00
data-stores Move props from datastore to order object and implement $save params for DataStore (#34627) 2022-09-28 14:07:41 -03:00
emails Move props from datastore to order object and implement $save params for DataStore (#34627) 2022-09-28 14:07:41 -03:00
export Add exporter instance parameter to `woocommerce_product_export_row_data` filter (#33390) 2022-07-04 19:22:13 -07:00
gateways Upgrade misc WooCommerce bits to support COT (#34124) 2022-08-03 09:41:37 -07:00
import Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
integrations/maxmind-geolocation Update plugins/woocommerce/includes/integrations/maxmind-geolocation/class-wc-integration-maxmind-geolocation.php 2022-05-18 21:22:13 +00:00
interfaces Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
legacy [PHP 8.1] Fix code that throws deprecation notices in tests in PHP 8.1 (#31333) 2022-06-21 12:16:44 +02:00
libraries Update wp-background-process.php to use wp_convert_hr_to_bytes() (#30908) 2022-07-04 19:23:52 -07:00
log-handlers Serializing error message to avoid problems with log parser 2022-04-22 06:19:52 +02:00
payment-tokens git mv a few folders 2021-10-19 10:35:45 +13:00
queue Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
react-admin Render order edit page (#33638) 2022-07-28 15:07:34 +05:30
rest-api REST API: Ensure meta_data prop contains an array (#34966) 2022-10-05 14:39:33 -07:00
shipping Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
shortcodes Stock checks not required if stock levels have already been reduced. (#33575) 2022-09-15 17:57:22 -03:00
theme-support Fix: Twenty Twenty-Two integration (#32840) 2022-06-02 11:04:27 +01:00
tracks Fix recording events without props (#34595) 2022-09-06 16:37:31 -03:00
traits git mv a few folders 2021-10-19 10:35:45 +13:00
walkers git mv a few folders 2021-10-19 10:35:45 +13:00
wccom-site git mv a few folders 2021-10-19 10:35:45 +13:00
widgets git mv a few folders 2021-10-19 10:35:45 +13:00
README.md Fix internal links in README files 2022-02-25 11:27:58 +01:00
class-wc-ajax.php [COT] Restore refund removal functionality when COT is active (#34785) 2022-09-22 15:00:20 -07:00
class-wc-api.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-auth.php Changes to class-wc-auth that allows it to work with sso auth 2022-03-23 15:51:42 +02:00
class-wc-autoloader.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-background-emailer.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-background-updater.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-breadcrumb.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-cache-helper.php fix variable name 2022-04-23 15:59:48 -04:00
class-wc-cart-fees.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-cart-session.php Filter is_purchasable when getting cart item from session (#26179) 2022-09-15 09:10:02 -03:00
class-wc-cart-totals.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-cart.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-checkout.php Cherry picked sec changes 2022-03-08 13:00:34 -08:00
class-wc-cli.php Add the wp wc com extension list command (#33783) 2022-07-14 13:18:50 -03:00
class-wc-comments.php Product review page in WooCommerce Core (#32763) 2022-06-05 10:45:28 -07:00
class-wc-countries.php Fix: can't place orders for Saint Martin (#34920) 2022-10-03 11:26:48 +02:00
class-wc-coupon.php Merge pull request #31798 from Saggre/fix/documentation-typos 2022-03-30 14:46:23 -07:00
class-wc-customer-download-log.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-customer-download.php Add ReturnTypeWillChange attribute to classes implementing ArrayAccess 2021-11-24 16:22:49 +01:00
class-wc-customer.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-data-exception.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-data-store.php [COT] Implement `query()` in the COT datastore (#33834) 2022-07-25 21:06:53 +05:30
class-wc-datetime.php Add more "#[\ReturnTypeWillChange]" attributes. 2022-03-24 14:08:18 +01:00
class-wc-deprecated-action-hooks.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-deprecated-filter-hooks.php Re-introduce woocommerce_product_csv_importer_check_import_file_path 2022-04-25 10:49:15 +02:00
class-wc-discounts.php Trashed coupons should not be usable (unless restored). (#33791) 2022-08-25 05:26:01 -07:00
class-wc-download-handler.php Add inline file delivery to WC_Download_Handler (#31145) 2022-08-25 11:03:03 -07:00
class-wc-emails.php Upgrade misc WooCommerce bits to support COT (#34124) 2022-08-03 09:41:37 -07:00
class-wc-embed.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-form-handler.php change `wp_safe_redirect` location from user dashboard to `edit-account` endpoint 2022-03-30 22:04:56 +02:00
class-wc-frontend-scripts.php Fix/34667 (#34671) 2022-09-14 09:52:47 -03:00
class-wc-geo-ip.php Rename Swaziland to Eswatini 2021-11-13 18:38:30 +02:00
class-wc-geolite-integration.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-geolocation.php class-wc-geolocation.php: hide blog URL from third-party providers (#31941) 2022-06-24 17:34:29 -03:00
class-wc-https.php use native wp_doing_ajax instead of custom is_ajax 2021-11-09 17:55:02 +01:00
class-wc-install.php Remove marketing transient on upgrade to 7.0 (#34679) 2022-09-16 17:25:37 +03:00
class-wc-integrations.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-log-levels.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-logger.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-meta-data.php Add more "#[\ReturnTypeWillChange]" attributes. 2022-03-24 14:08:18 +01:00
class-wc-order-factory.php Add support for refunds and other order types in custom order tables (#34050) 2022-08-24 14:33:03 -05:00
class-wc-order-item-coupon.php Add ReturnTypeWillChange attribute to classes implementing ArrayAccess 2021-11-24 16:22:49 +01:00
class-wc-order-item-fee.php Add ReturnTypeWillChange attribute to classes implementing ArrayAccess 2021-11-24 16:22:49 +01:00
class-wc-order-item-meta.php use native wp_doing_ajax instead of custom is_ajax 2021-11-09 17:55:02 +01:00
class-wc-order-item-product.php Add ReturnTypeWillChange attribute to classes implementing ArrayAccess 2021-11-24 16:22:49 +01:00
class-wc-order-item-shipping.php Add ReturnTypeWillChange attribute to classes implementing ArrayAccess 2021-11-24 16:22:49 +01:00
class-wc-order-item-tax.php Add ReturnTypeWillChange attribute to classes implementing ArrayAccess 2021-11-24 16:22:49 +01:00
class-wc-order-item.php Add get_all_formatted_meta_data wrapper 2021-11-26 15:48:06 +00:00
class-wc-order-query.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-order-refund.php Move props from datastore to order object and implement $save params for DataStore (#34627) 2022-09-28 14:07:41 -03:00
class-wc-order.php Move props from datastore to order object and implement $save params for DataStore (#34627) 2022-09-28 14:07:41 -03:00
class-wc-payment-gateways.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-payment-tokens.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-post-data.php Upgrade misc WooCommerce bits to support COT (#34124) 2022-08-03 09:41:37 -07:00
class-wc-post-types.php Improve menu integration (classic as well as the new WC Admin nav feature). 2022-05-20 13:52:40 +00:00
class-wc-privacy-background-process.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-privacy-erasers.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-privacy-exporters.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-privacy.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-product-attribute.php Fix PHPDoc Type 2022-01-07 11:50:53 +02:00
class-wc-product-download.php Product downloads → support a concept of active/inactive files. 2022-04-11 14:59:56 -07:00
class-wc-product-external.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-product-factory.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-product-grouped.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-product-query.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-product-simple.php Only show the product image upload tip once, and on all product edit pages (#34739) 2022-09-20 08:09:31 -04:00
class-wc-product-variable.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-product-variation.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-query.php Add the AccessiblePrivateMethods trait (#34019) 2022-09-15 09:24:35 +02:00
class-wc-rate-limiter.php Update db table name to use the new convention. 2021-11-26 11:35:29 +01:00
class-wc-regenerate-images-request.php Remove legacy image sizes which were planned for removal into 4.6.0 (#32709) 2022-06-20 12:00:33 +02:00
class-wc-regenerate-images.php Remove legacy image sizes which were planned for removal into 4.6.0 (#32709) 2022-06-20 12:00:33 +02:00
class-wc-register-wp-admin-settings.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-rest-authentication.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-rest-exception.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-session-handler.php Merge pull request #31798 from Saggre/fix/documentation-typos 2022-03-30 14:46:23 -07:00
class-wc-shipping-rate.php Make the message more clear. 2021-10-19 11:45:42 +02:00
class-wc-shipping-zone.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-shipping-zones.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-shipping.php add phpdoc block with gist reference to woocommerce_package_rates filter 2021-10-19 13:15:43 -03:00
class-wc-shortcodes.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-structured-data.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-tax.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
class-wc-template-loader.php Updated @since version 2022-01-14 15:57:31 +05:30
class-wc-tracker.php Test Failures: Check WP version 5.9 before adding mini_cart_block to WC Tracker (#32862) 2022-05-04 14:09:21 +12:00
class-wc-validation.php git mv a few folders 2021-10-19 10:35:45 +13:00
class-wc-webhook.php Upgrade misc WooCommerce bits to support COT (#34124) 2022-08-03 09:41:37 -07:00
class-woocommerce.php Add the WooCommerce features engine, take 2 (#34727) 2022-09-27 09:26:09 +02:00
wc-account-functions.php git mv a few folders 2021-10-19 10:35:45 +13:00
wc-attribute-functions.php Change attribute slug length requirement and add wc_create_attribute tests (#31795) 2022-06-09 10:51:38 +02:00
wc-cart-functions.php Merge pull request #31798 from Saggre/fix/documentation-typos 2022-03-30 14:46:23 -07:00
wc-conditional-functions.php Merge pull request #31266 from carlalexander/patch-1 2022-01-27 16:05:45 -08:00
wc-core-functions.php Remove PHP 8.1 warnings and errors (#34336) 2022-08-16 10:22:53 -07:00
wc-coupon-functions.php git mv a few folders 2021-10-19 10:35:45 +13:00
wc-deprecated-functions.php Partially revert #31113 2022-01-18 11:28:35 -06:00
wc-formatting-functions.php [PHP 8.1] Fix code that throws deprecation notices in tests in PHP 8.1 (#31333) 2022-06-21 12:16:44 +02:00
wc-notice-functions.php git mv a few folders 2021-10-19 10:35:45 +13:00
wc-order-functions.php Link backfilling to migration process (#34167) 2022-08-19 06:27:19 -05:00
wc-order-item-functions.php git mv a few folders 2021-10-19 10:35:45 +13:00
wc-page-functions.php git mv a few folders 2021-10-19 10:35:45 +13:00
wc-product-functions.php Only show the product image upload tip once, and on all product edit pages (#34739) 2022-09-20 08:09:31 -04:00
wc-rest-functions.php Supressing warnings originating from metadata functions 2022-05-11 15:59:49 -07:00
wc-stock-functions.php Fix typos in phpdocs and comments 2022-02-01 17:06:58 +02:00
wc-template-functions.php [redux] Coerce variable type of form field argument 'class' in woocommerce_form_field() (#33454) 2022-06-16 10:35:22 -03:00
wc-template-hooks.php git mv a few folders 2021-10-19 10:35:45 +13:00
wc-term-functions.php [PHP 8.1] Fix code that throws deprecation notices in tests in PHP 8.1 (#31333) 2022-06-21 12:16:44 +02:00
wc-update-functions.php Remove marketing transient on upgrade to 7.0 (#34679) 2022-09-16 17:25:37 +03:00
wc-user-functions.php Support `wc_customer_bought_product` for hpos. (#34931) 2022-10-04 15:52:02 -03:00
wc-webhook-functions.php Respect the $limit parameter (0) 2022-03-01 17:45:13 -03:00
wc-widget-functions.php git mv a few folders 2021-10-19 10:35:45 +13:00

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.