woocommerce/includes
Nestor Soriano 9de1306c21 Fix counters in nav filtering widgets for variable products.
After the change that registers variation attributes as terms
(in addition to reigstering them as post meta) it is now time
to modify the get_filtered_term_product_counts methods in
WC_Widget_Layered_Nav so that it works consistently for both
variable and non-variable products. The logic for the counters
is now as follows:

with OR operator:
- Simple products: count the attributes of all visible products
  (unchanged behavior).
- Variable products: count attributes corresponding to
  visible variations.

with AND operator:
- Simple products: count the attributes of visible products but only
  for products that have all the selected (unchanged behavior).
- Variable products: find all the products for which all the variations
  corresponding to the selected attributes exist and are visible,
  then count the attributes corresponding to the visible variations
  of those products.

A product is "visible" if it's published, not excluded for catalog,
and has stock. Additionally, a variable product will not be considered
visible if the parent product is not.
2020-07-28 08:55:55 +02:00
..
abstracts Fix visibility of variable products with layered nav filtering. 2020-07-28 08:55:52 +02:00
admin Merge pull request #26750 from woocommerce/implement/core-language-packs-updates 2020-07-27 12:45:58 -07:00
cli Removed the default `id` field added to all CLI commands 2020-07-10 14:16:30 -07:00
customizer remove privacy page dropdown 2020-06-18 10:40:17 -03:00
data-stores Record attribute terms for product variations in wp_term_relationships. 2020-07-28 08:55:55 +02:00
emails Merge pull request #25630 from woocommerce/fix-25603 2020-05-11 19:43:08 -07:00
export [Importer/Exporter] Fix "Published" column values 2020-07-15 21:45:51 -03:00
gateways Extend BACS accounts filter with order ID 2020-07-06 13:36:24 +02:00
import [Importer/Exporter] Fix "Published" column values 2020-07-15 21:45:51 -03:00
integrations/maxmind-geolocation Use urlencode 2020-03-05 11:54:41 -03:00
interfaces
legacy Renamed `WC_Cart::is_tax_displayed()` to `WC_Cart::get_tax_price_display_mode()` to clarify intent 2020-07-13 07:21:19 -07:00
libraries Don't echo error when doing AJAX because it invalidates JSON 2020-03-17 16:49:52 +05:30
log-handlers Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages 2020-01-28 21:21:29 -08:00
payment-tokens Fix wrong context help for translators 2020-01-26 17:55:17 +01:00
queue Changes in the overall organization of the dependency injection: 2020-07-24 09:23:01 +02:00
shipping Tweak explanation for coupon discounts 2020-04-24 15:47:02 +02:00
shortcodes Revert "Revert "Introduce a `reserved stock` class and database table to prevent race conditions during checkout"" 2020-06-05 15:18:01 +05:30
theme-support Replaced direct access of many constants with the Constants library 2020-01-31 22:18:47 -08:00
tracks [Tracker] Added order_total to orders_edit_status_change 2020-07-01 18:24:47 -03:00
traits Use standard way to calculate total in `get_subtotal_to_display` for consistency. 2019-11-27 04:43:23 +05:30
walkers
wccom-site Change "products" argument type from array to object. 2020-03-10 17:41:39 +03:00
widgets Fix counters in nav filtering widgets for variable products. 2020-07-28 08:55:55 +02:00
README.md Add documentation about the container and good coding practices. 2020-07-24 09:25:12 +02:00
class-wc-ajax.php Merge pull request #26642 from woocommerce/fix/26607 2020-07-24 13:23:53 +02:00
class-wc-api.php
class-wc-auth.php
class-wc-autoloader.php Added the WC Admin enabled db update notice. 2020-02-23 21:59:03 +01:00
class-wc-background-emailer.php Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages 2020-01-28 21:21:29 -08:00
class-wc-background-updater.php
class-wc-breadcrumb.php
class-wc-cache-helper.php add Google weblight user agent check 2020-06-24 14:26:25 -03:00
class-wc-cart-fees.php
class-wc-cart-session.php
class-wc-cart-totals.php Use round_item_subtotal for shipping because shipping prices never include taxes so no need to wc_round_tax_total. 2020-07-24 19:12:25 +05:30
class-wc-cart.php Do not use `wc_round_tax_total` in shipping tax for accuracy. 2020-07-24 19:12:25 +05:30
class-wc-checkout.php Undo the registration of old singletons in the DI container. 2020-07-24 09:20:24 +02:00
class-wc-cli.php
class-wc-comments.php Update saving of comment_type for product reviews to account for WP 5.5 default comment_type 2020-06-08 17:36:34 -05:00
class-wc-countries.php Merge pull request #26697 from passatgt/master 2020-07-01 12:55:50 -03:00
class-wc-coupon.php Improve coupon name output handling. 2020-02-26 12:24:04 +01:00
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 Use the spread operator instead of call_user_func_array() in WC_Data_Store 2019-11-21 11:52:47 -03:00
class-wc-datetime.php
class-wc-deprecated-action-hooks.php
class-wc-deprecated-filter-hooks.php
class-wc-discounts.php Added a check to prevent coupon cent remainders from decreasing the item cost below zero 2020-03-16 21:32:25 -07:00
class-wc-download-handler.php Fallback to force for remote file because xsendfile don;t support it by default 2020-02-07 17:54:54 +05:30
class-wc-emails.php Revert a couple of files to its original content after a messed rebase 2020-07-24 09:20:24 +02:00
class-wc-embed.php
class-wc-form-handler.php Merge pull request #26237 from woocommerce/fix/24000 2020-06-11 13:13:12 +02:00
class-wc-frontend-scripts.php Extracted the repetitive Constants::get_constant( 'WC_VERSION' ) calls where possible 2020-02-04 14:02:57 -08:00
class-wc-geo-ip.php
class-wc-geolite-integration.php Added a deprecation to the old Geolite library wrapper class' public methods 2020-01-14 13:44:41 -08:00
class-wc-geolocation.php Fixed conditional code 2020-01-14 16:44:01 -03:00
class-wc-https.php
class-wc-install.php Record attribute terms for product variations in wp_term_relationships. 2020-07-28 08:55:55 +02:00
class-wc-integrations.php Fixed missing methods, added deprecated notices and @since 2020-01-10 11:58:53 -03:00
class-wc-log-levels.php
class-wc-logger.php Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages 2020-01-28 21:21:29 -08:00
class-wc-meta-data.php
class-wc-order-factory.php Removed variable and set exception paramater to array containing the order id. 2019-11-20 22:52:04 -06:00
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 Merge pull request #26846 from woocommerce/add/new_order_note_action 2020-07-01 12:56:55 -03:00
class-wc-payment-gateways.php Undo the registration of old singletons in the DI container. 2020-07-24 09:20:24 +02:00
class-wc-payment-tokens.php
class-wc-post-data.php Deprecated old cache function and replaced it with a new one. 2019-11-28 14:03:57 +01:00
class-wc-post-types.php Merge pull request #26877 from woocommerce/fix/26547 2020-07-08 12:08:29 -03:00
class-wc-privacy-background-process.php
class-wc-privacy-erasers.php Updated the privacy-related strings as well. 2020-02-04 13:25:47 +01:00
class-wc-privacy-exporters.php Adds support for group_description for privacy exporters which was added in WP5.3 through WPCoreChangeset#45825 and WPCoreTracTicket#45491 2020-02-04 12:57:31 -08:00
class-wc-privacy.php Update Suggested Privacy Policy text to utilize css class instead of as it was deprecated. Also wrap the contents in the div to style the section to match WordPress. This follows from WPCoreTrac#49282 and although back-compat is being introduced in WP5.4 as of WPChangeset#47112 this change will better support users of WP5.1-5.4 2020-02-04 13:24:55 -08:00
class-wc-product-attribute.php
class-wc-product-download.php Fix WordPress.Arrays.MultipleStatementAlignment errors automatically using phpcbf 2019-12-20 13:51:26 -03:00
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 Add 404 check when creating add to cart url for single products. 2019-10-09 12:44:47 +02:00
class-wc-product-variable.php Fix visibility of variable products with layered nav filtering. 2020-07-28 08:55:52 +02:00
class-wc-product-variation.php Record attribute terms for product variations in wp_term_relationships. 2020-07-28 08:55:55 +02:00
class-wc-query.php Fix visibility of variable products with layered nav filtering. 2020-07-28 08:55:52 +02:00
class-wc-rate-limiter.php Fix Generic.Formatting.MultipleStatementAlignment violations 2019-12-20 14:21:08 -03:00
class-wc-regenerate-images-request.php
class-wc-regenerate-images.php
class-wc-register-wp-admin-settings.php
class-wc-rest-authentication.php
class-wc-rest-exception.php
class-wc-session-handler.php Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages 2020-01-28 21:21:29 -08:00
class-wc-shipping-rate.php
class-wc-shipping-zone.php
class-wc-shipping-zones.php Fix Generic.Formatting.MultipleStatementAlignment violations 2019-12-20 14:21:08 -03:00
class-wc-shipping.php Revert a couple of files to its original content after a messed rebase 2020-07-24 09:20:24 +02:00
class-wc-shortcodes.php Fix PEAR.Functions.FunctionCallSignature violations 2019-12-20 15:25:23 -03:00
class-wc-structured-data.php Added missing schema markup 2020-02-14 10:51:41 +02:00
class-wc-tax.php Pass $customer to woocommerce_match_rates hook. 2020-05-01 13:49:55 -07:00
class-wc-template-loader.php Validate page template 2020-04-29 17:53:04 +05:30
class-wc-tracker.php fix logic errors in get_blocks_from_page: 2020-04-07 10:23:03 +12:00
class-wc-validation.php Fixes for Hungarian address format and name order 2020-06-04 19:21:41 +02:00
class-wc-webhook.php Merge pull request #25183 from om4james/webhook-de-duplication 2020-02-05 18:38:15 +01:00
class-woocommerce.php Improevements on ExtendedContainer and LegacyProxy documentation. 2020-07-24 09:25:11 +02:00
wc-account-functions.php Address / Addresses strings in correct order for _n() 2020-05-07 20:57:30 -04:00
wc-attribute-functions.php Fix set cache loop when no attributes exist 2020-05-14 12:37:29 -05:00
wc-cart-functions.php Update min files and selectWoo 2020-06-16 17:15:12 +02:00
wc-conditional-functions.php Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages 2020-01-28 21:21:29 -08:00
wc-core-functions.php Small changes after review feedback: 2020-07-24 09:24:06 +02:00
wc-coupon-functions.php
wc-deprecated-functions.php Changed all of the constant accesses into corresponding Automattic\Jetpack\Constants usages 2020-01-28 21:21:29 -08:00
wc-formatting-functions.php Merge pull request #26462 from db2000ro/fix/24885 2020-07-01 13:20:01 -03:00
wc-notice-functions.php Prevent empty notices to get added 2020-01-24 13:31:05 -03:00
wc-order-functions.php Allow custom values in wc_generate_order_key() 2020-05-20 17:41:22 -03:00
wc-order-item-functions.php Deprecated old cache function and replaced it with a new one. 2019-11-28 14:03:57 +01:00
wc-page-functions.php
wc-product-functions.php Merge branch 'master' into refactor/add-jetpack-constants 2020-02-04 14:36:35 -08:00
wc-rest-functions.php Fix PEAR.Functions.FunctionCallSignature violations 2019-12-20 15:25:23 -03:00
wc-stock-functions.php Merge pull request #26503 from Knyazevich/origin/fix/wc_update_product_stock_status-phpdoc 2020-07-01 13:21:21 -03:00
wc-template-functions.php Fix visibility of variable products with layered nav filtering. 2020-07-28 08:55:52 +02:00
wc-template-hooks.php Introduced wc_get_pay_buttons() function 2019-11-07 17:23:38 -03:00
wc-term-functions.php Simplify and modernize wc_walk_category_dropdown_tree() 2019-11-22 15:25:44 -03:00
wc-update-functions.php Record attribute terms for product variations in wp_term_relationships. 2020-07-28 08:55:55 +02:00
wc-user-functions.php Add login link for existing account 2020-06-22 09:57:28 -06:00
wc-webhook-functions.php Switch to use WordPress' shutdown action instead of register_shutdown_function 2020-07-27 12:11:40 -04:00
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.