woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.39k stars 10.76k forks source link

Custom Taxonomy Block Templates pulling /wp-includes/template-canvas.php #40497

Open webd-uk opened 1 year ago

webd-uk commented 1 year ago

Prerequisites

Describe the bug

When you have a custom product taxonomy block template in the wp_posts table of the database that doesn't otherwise exist in the actual theme files (such as taxonomy-your_custom_tax.html) WooCommerce completely ignores the template and this code has to be used to enable it again ...

add_filter('woocommerce_has_block_template', 'my_woocommerce_has_block_template', 10, 2);

function my_woocommerce_has_block_template($has_template, $template_name) {

    if ('taxonomy-your_custom_tax' === $template_name) { $has_template = true; }

    return $has_template;

}

Instead of just checking the theme for the template, has_block_template() should also check the wp_posts database to make sure that it doesn't also exist there before automatically returning false.

Oliver

Expected behavior

When a block template exists in wp_posts table, has_block_template() should return true whether the theme has the corresponding .html block template file or not.

Actual behavior

When a block template exists in wp_posts table and the theme does not have the corresponding .html block template file, has_block_template() returns false causing the depreciated header and footer templates to be loaded.

Steps to reproduce

  1. Install WooCommerce and Twenty Twenty-Three
  2. Add a custom taxonomy to Products
  3. Add a custom taxonomy block template to the database
  4. Load a taxonomy archive page for your custom taxonomy
  5. You will see the depreciated template loaded instead of your custom taxonomy block template

WordPress Environment

`

WordPress Environment

WordPress address (URL): Site address (URL): WC Version: 8.1.1 REST API Version: ✔ 8.1.1 WC Blocks Version: ✔ 10.9.3 Action Scheduler Version: ✔ 3.6.2 Log Directory Writable: ✔ WP Version: 6.3.1 WP Multisite: – WP Memory Limit: 256 MB WP Debug Mode: – WP Cron: ✔ Language: en_US External object cache: –

Server Environment

Server Info: Apache/2.4.41 (Ubuntu) PHP Version: 7.4.3-4ubuntu2.19 PHP Post Max Size: 10 MB PHP Time Limit: 300 PHP Max Input Vars: 2000 cURL Version: 7.68.0 OpenSSL/1.1.1f

SUHOSIN Installed: – MySQL Version: 8.0.34-0ubuntu0.20.04.1 Max Upload Size: 10 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Database

WC Database Version: 8.1.1 WC Database Prefix: wp_ Total Database Size: 27.78MB Database Data Size: 23.00MB Database Index Size: 4.78MB wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 0.09MB + Index: 0.13MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 0.06MB + Index: 0.03MB + Engine InnoDB wp_admin_columns: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_fbv: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_fbv_attachment_folder: Data: 0.08MB + Index: 0.00MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mclean_refs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mclean_scan: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_options: Data: 2.17MB + Index: 0.08MB + Engine InnoDB wp_postmeta: Data: 0.45MB + Index: 0.20MB + Engine InnoDB wp_posts: Data: 1.52MB + Index: 0.09MB + Engine InnoDB wp_product_catmeta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_snippets: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Data: 0.08MB + Index: 0.03MB + Engine InnoDB wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.05MB + Index: 0.02MB + Engine InnoDB wp_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_addresses: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_operational_data: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_orders: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wp_wc_orders_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfblockediplog: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfblocks7: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wfconfig: Data: 1.34MB + Index: 0.00MB + Engine InnoDB wp_wfcrawlers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wffilechanges: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wffilemods: Data: 7.52MB + Index: 0.00MB + Engine InnoDB wp_wfhits: Data: 0.38MB + Index: 0.05MB + Engine InnoDB wp_wfhoover: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfissues: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wfknownfilelist: Data: 3.52MB + Index: 0.00MB + Engine InnoDB wp_wflivetraffichuman: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wflocs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wflogins: Data: 0.45MB + Index: 0.20MB + Engine InnoDB wp_wfls_2fa_secrets: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfls_role_counts: Data: 0.00MB + Index: 0.00MB + Engine MEMORY wp_wfls_settings: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfnotifications: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_wfpendingissues: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wfreversecache: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfsecurityevents: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfsnipcache: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wfstatus: Data: 0.13MB + Index: 0.11MB + Engine InnoDB wp_wftrafficrates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfwaffailures: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpforms_payment_meta: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wpforms_payments: Data: 0.02MB + Index: 0.14MB + Engine InnoDB wp_wpforms_tasks_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_debug_events: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_tasks_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wsal_metadata: Data: 0.27MB + Index: 0.34MB + Engine InnoDB wp_wsal_occurrences: Data: 0.16MB + Index: 0.06MB + Engine InnoDB wp_yoast_indexable: Data: 1.52MB + Index: 0.83MB + Engine InnoDB wp_yoast_indexable_hierarchy: Data: 0.11MB + Index: 0.20MB + Engine InnoDB wp_yoast_migrations: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_yoast_primary_term: Data: 0.06MB + Index: 0.03MB + Engine InnoDB wp_yoast_seo_links: Data: 1.52MB + Index: 0.47MB + Engine InnoDB

Post Type Counts

attachment: 193 custom_css: 2 customize_changeset: 14 elementor_library: 1 nav_menu_item: 3 oembed_cache: 1 page: 10 porto_builder: 4 post: 8 product: 30 random_image: 24 revision: 188 shop_order: 10 wp_global_styles: 2 wp_navigation: 1 wp_template: 12 wp_template_part: 5 wpforms: 1

Security

Secure connection (HTTPS): ✔ Hide errors from visitors: ✔

Active Plugins (19)

Block wp-login: by Webd Ltd – 1.5.2 Admin Columns: by AdminColumns.com – 4.6.1 Custom Post Type UI: by WebDevStudios – 1.14.0 The Icon Block: by Nick Diego – 1.6.0 Loco Translate: by Tim Whitlock – 2.6.6 AI-SEO KISS (Keep It Simple Stupid): by Jordy Meow – 0.1.2 Options for Block Themes: by Webd Ltd – 1.2.3 UpdraftPlus - Backup/Restore: by UpdraftPlus.Com DavidAnderson – 1.23.10

Ajax add to cart for WooCommerce: by QuadLayers – 2.2.4 WooCommerce Stripe Gateway: by WooCommerce – 7.6.0 WooCommerce: by Automattic – 8.1.1 Wordfence Security: by Wordfence – 7.10.4 WP Activity Log for WooCommerce: by Melapress – 1.5.2 WP Mail SMTP: by WP Mail SMTP – 3.9.0 WP Activity Log: by WP White Security – 4.5.3 WPForms Lite: by WPForms – 1.8.4

Settings

API Enabled: – Force SSL: – Currency: GBP (£) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5)

Connected to WooCommerce.com: – Enforce Approved Product Download Directories: – HPOS feature screen enabled: – HPOS feature enabled: – Order datastore: WC_Order_Data_Store_CPT HPOS data sync enabled: –

WC Pages

Shop base: #2084 - /shop/ Cart: #2076 - /cart/ Checkout: #2078 - /checkout/ My account: ❌ Page not set Terms and conditions: #2082 - /terms-and-conditions/

Theme

Name: Twenty Twenty-Three Version: 1.2 Author URL: https://wordpress.org Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔

Templates

Overrides: /wp-content/plugins/woocommerce/packages/woocommerce-blocks/templates/notices/error.php /wp-content/plugins/woocommerce/packages/woocommerce-blocks/templates/notices/notice.php /wp-content/plugins/woocommerce/packages/woocommerce-blocks/templates/notices/success.php

Admin

Enabled Features: activity-panels analytics product-block-editor coupons core-profiler customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page

Disabled Features: customize-store minified-js new-product-management-experience product-variation-management settings async-product-editor-category-field

Daily Cron: ✔ Next scheduled: 2023-09-29 12:15:41 +01:00 Options: ✔ Notes: 55 Onboarding: completed

Action Scheduler

Complete: 106 Oldest: 2023-08-31 12:45:53 +0100 Newest: 2023-09-28 16:50:10 +0100

Failed: 23 Oldest: 2023-02-14 21:53:04 +0000 Newest: 2023-09-28 14:21:24 +0100

Pending: 6 Oldest: 2023-09-29 12:14:00 +0100 Newest: 2023-10-05 13:46:48 +0100

Status report information

Generated at: 2023-09-28 18:41:03 +01:00 `

Isolating the problem

tjcafferkey commented 10 months ago

Hi @webd-uk, apologies for the late reply but thank you for submitting this issue. Currently out method of handling block templates through Woos codebase has become rather complex and we're planning a refactor for this (https://github.com/woocommerce/woocommerce/issues/42251).

With this particular issue, we will consider it during the refactor if it's related to the code on Woo's side and hopefully be able to implement a solution.

As for timeframes, I won't be able to give you a specific date but hopefully it'll be towards the end of Q1 in 2024.