71fccd6a07
This bug was introduced in #26260. The sequence is: 1. WC_Query::adjust_posts_count runs, to handle found_posts filter, this indirectly executes wc_setup_loop. 2. At this point $GLOBALS['wp_query']->max_num_pages hasn't been set yet, and has a value of 0. Thus the loop variable total_pages is set to 0. 3. Later wc_setup_loop runs again and this time $GLOBALS['wp_query']->max_num_pages is already set, but since the loop variable total_pages already exists, it keeps its value of 0. 4. The pagination controls never show if total_pages is less than 2. The fix consists of hooking into the_posts to set the value of total_pages again, at that point $GLOBALS['wp_query']->max_num_pages is already set. |
||
---|---|---|
.. | ||
abstracts | ||
admin | ||
cli | ||
customizer | ||
data-stores | ||
emails | ||
export | ||
gateways | ||
import | ||
integrations/maxmind-geolocation | ||
interfaces | ||
legacy | ||
libraries | ||
log-handlers | ||
payment-tokens | ||
queue | ||
shipping | ||
shortcodes | ||
theme-support | ||
tracks | ||
traits | ||
walkers | ||
wccom-site | ||
widgets | ||
README.md | ||
class-wc-ajax.php | ||
class-wc-api.php | ||
class-wc-auth.php | ||
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 | ||
class-wc-checkout.php | ||
class-wc-cli.php | ||
class-wc-comments.php | ||
class-wc-countries.php | ||
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 | ||
class-wc-embed.php | ||
class-wc-form-handler.php | ||
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 | ||
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 | ||
class-wc-privacy-background-process.php | ||
class-wc-privacy-erasers.php | ||
class-wc-privacy-exporters.php | ||
class-wc-privacy.php | ||
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 | ||
class-wc-product-variation.php | ||
class-wc-query.php | ||
class-wc-rate-limiter.php | ||
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 | ||
class-wc-shipping-rate.php | ||
class-wc-shipping-zone.php | ||
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 | ||
class-wc-validation.php | ||
class-wc-webhook.php | ||
class-woocommerce.php | ||
wc-account-functions.php | ||
wc-attribute-functions.php | ||
wc-cart-functions.php | ||
wc-conditional-functions.php | ||
wc-core-functions.php | ||
wc-coupon-functions.php | ||
wc-deprecated-functions.php | ||
wc-formatting-functions.php | ||
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 | ||
wc-template-hooks.php | ||
wc-term-functions.php | ||
wc-update-functions.php | ||
wc-user-functions.php | ||
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 forincludes
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.