How to override woocommerce “class-wc-twenty-nineteen.php” in my child theme
-
Hi ?? I have asked the same question in my theme’s support but nobody had the answer. Since it has to do with Woocommerce, I’m giving it a chance here too:
I am using my own child theme (from Twenty Nineteen) for my e-shop with woocommerce.
I would like to change the width for my products “main image” (see here https://www.dreamsonearth.com/produit/pack-cartes-postales-geologie/ the picture with the leaves). It is set to 450px and I’d like to set it to 600px.
I read a lot of forum threads about similar issues and here is what I learnt:
1) I should be able to customize this width in Appearance > Customize > WooCommerce > Product Images but the option is not shown here.
2) It is because my main theme (Twenty Nineteen) has declared WooCommerce support and defined those settings itself. And if so, the settings are removed from the customizer.
3) After a while I found where those settings were defined: in /wp-content/plugins/woocommerce/includes/theme-support/class-wc-twenty-nineteen.php :
<?php /** * Twenty Nineteen support. * * @since 3.5.X * @package WooCommerce/Classes */ defined( 'ABSPATH' ) || exit; /** * WC_Twenty_Nineteen class. */ class WC_Twenty_Nineteen { /** * Theme init. */ public static function init() { // Change WooCommerce wrappers. remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); add_action( 'woocommerce_before_main_content', array( __CLASS__, 'output_content_wrapper' ), 10 ); add_action( 'woocommerce_after_main_content', array( __CLASS__, 'output_content_wrapper_end' ), 10 ); // This theme doesn't have a traditional sidebar. remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 ); // Enqueue theme compatibility styles. add_filter( 'woocommerce_enqueue_styles', array( __CLASS__, 'enqueue_styles' ) ); // Register theme features. add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); add_theme_support( 'woocommerce', array( 'thumbnail_image_width' => 300, >>>>>>>>>>>>>>>>>>>>>>>>>'single_image_width' => 450, ) ); // Tweak Twenty Nineteen features. add_action( 'wp', array( __CLASS__, 'tweak_theme_features' ) ); // Color scheme CSS add_filter( 'twentynineteen_custom_colors_css', array( __CLASS__, 'custom_colors_css' ), 10, 3 ); } /** * Open the Twenty Nineteen wrapper. */ public static function output_content_wrapper() { echo '<section id="primary" class="content-area">'; echo '<main id="main" class="site-main">'; } /** * Close the Twenty Nineteen wrapper. */ public static function output_content_wrapper_end() { echo '</main>'; echo '</section>'; } /** * Enqueue CSS for this theme. * * @param array $styles Array of registered styles. * @return array */ public static function enqueue_styles( $styles ) { unset( $styles['woocommerce-general'] ); $styles['woocommerce-general'] = array( 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-nineteen.css', 'deps' => '', 'version' => WC_VERSION, 'media' => 'all', 'has_rtl' => true, ); return apply_filters( 'woocommerce_twenty_nineteen_styles', $styles ); } /** * Tweak Twenty Nineteen features. */ public static function tweak_theme_features() { if ( is_woocommerce() ) { add_filter( 'twentynineteen_can_show_post_thumbnail', '__return_false' ); } } /** * Filters Twenty Nineteen custom colors CSS. * * @param string $css Base theme colors CSS. * @param int $primary_color The user's selected color hue. * @param string $saturation Filtered theme color saturation level. */ public static function custom_colors_css( $css, $primary_color, $saturation ) { if ( function_exists( 'register_block_type' ) && is_admin() ) { return $css; } $lightness = absint( apply_filters( 'twentynineteen_custom_colors_lightness', 33 ) ); $lightness = $lightness . '%'; $css .= ' .onsale, .woocommerce-info, .woocommerce-store-notice { background-color: hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' ); } .woocommerce-tabs ul li.active a { color: hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' ); box-shadow: 0 2px 0 hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' ); } '; return $css; } } WC_Twenty_Nineteen::init();
4) When I write 600 instead of 450 (“>>>>>>>>>>>>>>>>>>>>>>>>>” line in the code above) and regenerate my thumbnails, it works! But I know that as soon as I’ll update woocommerce next, my edit will be lost. I would like to make this change in my child theme and not directly in woocommerce folders.
5) Here is the issue: I tried different ways of adding the code to my child theme but none of them worked.
– > Reading articles like this one I added this code to my child theme’s functions.php:function mytheme_add_woocommerce_support() { add_theme_support( 'woocommerce', array( 'thumbnail_image_width' => 300, 'single_image_width' => 600, ) ); } add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
– > I also tried to copy the class-wc-twenty-nineteen.php file in my child theme and edit it the way I want, hoping it would override the one in woocommerce folder (didn’t work either ^^)
– > I tried adding remove_theme_support before the add_theme_support in my code but it didn’t work either:
function doe_thumbnail_width() { remove_theme_support( 'woocommerce' ); add_theme_support( 'woocommerce', array( 'thumbnail_image_width' => 300, 'single_image_width' => 600, ) ); } add_action( 'after_setup_theme', 'doe_thumbnail_width', 11 );
Any idea of how to add this simple change to my child theme to avoid editing the woocommerce file over and over each time I have to update the plugin?
Thank you
IsabellePS : My system status report:
### WordPress Environment ### WordPress address (URL): https://www.dreamsonearth.com Site address (URL): https://www.dreamsonearth.com WC Version: 3.7.1 REST API Version: ? 1.0.2 Log Directory Writable: ? WP Version: 5.2.4 WP Multisite: – WP Memory Limit: 4 GB WP Debug Mode: – WP Cron: ? Language: fr_FR External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 7.2.22 PHP Post Max Size: 512 MB PHP Time Limit: 360 PHP Max Input Vars: 2000000 cURL Version: 7.66.0 OpenSSL/1.0.2t SUHOSIN Installed: – MySQL Version: 5.5.5-10.2.27-MariaDB Max Upload Size: 512 MB Default Timezone is UTC: ? fsockopen/cURL: ? SoapClient: ? DOMDocument: ? GZip: ? Multibyte String: ? Remote Post: ? Remote Get: ? ### Database ### WC Database Version: 3.7.1 WC Database Prefix: wpwf_ MaxMind GeoIP Database: ? Taille totale de la base de données: 54.88MB Taille de la base de données: 51.20MB Taille de l’index: 3.68MB wpwf_woocommerce_sessions: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_woocommerce_api_keys: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_woocommerce_attribute_taxonomies: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_woocommerce_downloadable_product_permissions: Données?: 0.02MB + Index?: 0.06MB + Moteur InnoDB wpwf_woocommerce_order_items: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_woocommerce_order_itemmeta: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_woocommerce_tax_rates: Données?: 0.02MB + Index?: 0.06MB + Moteur InnoDB wpwf_woocommerce_tax_rate_locations: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_woocommerce_shipping_zones: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_woocommerce_shipping_zone_locations: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_woocommerce_shipping_zone_methods: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_woocommerce_payment_tokens: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_woocommerce_payment_tokenmeta: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_woocommerce_log: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_berocket_termmeta: Données?: 0.00MB + Index?: 0.00MB + Moteur MyISAM wpwf_commentmeta: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_comments: Données?: 0.02MB + Index?: 0.09MB + Moteur InnoDB wpwf_failed_jobs: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_links: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_mailchimp_carts: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_options: Données?: 2.03MB + Index?: 0.06MB + Moteur InnoDB wpwf_postmeta: Données?: 21.13MB + Index?: 1.81MB + Moteur InnoDB wpwf_posts: Données?: 18.45MB + Index?: 0.36MB + Moteur InnoDB wpwf_queue: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_subscribe_reloaded_subscribers: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_termmeta: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_terms: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_term_relationships: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_term_taxonomy: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_usermeta: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_users: Données?: 0.02MB + Index?: 0.05MB + Moteur InnoDB wpwf_wc_download_log: Données?: 0.02MB + Index?: 0.03MB + Moteur InnoDB wpwf_wc_product_meta_lookup: Données?: 0.00MB + Index?: 0.01MB + Moteur MyISAM wpwf_wc_tax_rate_classes: Données?: 0.00MB + Index?: 0.01MB + Moteur MyISAM wpwf_wc_webhooks: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_wdi_feeds: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_wdi_themes: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_wfblockediplog: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wfblocks7: Données?: 0.02MB + Index?: 0.05MB + Moteur InnoDB wpwf_wfconfig: Données?: 1.27MB + Index?: 0.00MB + Moteur InnoDB wpwf_wfcrawlers: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wffilechanges: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wffilemods: Données?: 4.52MB + Index?: 0.00MB + Moteur InnoDB wpwf_wfhits: Données?: 1.02MB + Index?: 0.20MB + Moteur InnoDB wpwf_wfhoover: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_wfissues: Données?: 0.02MB + Index?: 0.06MB + Moteur InnoDB wpwf_wfknownfilelist: Données?: 1.52MB + Index?: 0.00MB + Moteur InnoDB wpwf_wflivetraffichuman: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_wflocs: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wflogins: Données?: 0.13MB + Index?: 0.03MB + Moteur InnoDB wpwf_wfls_2fa_secrets: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_wfls_settings: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wfnotifications: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wfpendingissues: Données?: 0.02MB + Index?: 0.06MB + Moteur InnoDB wpwf_wfreversecache: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_wfsnipcache: Données?: 0.02MB + Index?: 0.05MB + Moteur InnoDB wpwf_wfstatus: Données?: 0.13MB + Index?: 0.09MB + Moteur InnoDB wpwf_wftrafficrates: Données?: 0.02MB + Index?: 0.00MB + Moteur InnoDB wpwf_yoast_seo_links: Données?: 0.02MB + Index?: 0.02MB + Moteur InnoDB wpwf_yoast_seo_meta: Données?: 0.06MB + Index?: 0.00MB + Moteur InnoDB ### Security ### Secure connection (HTTPS): ? Hide errors from visitors: ? ### Active Plugins (26) ### Akismet Anti-Spam: par Automattic – 4.1.2 BackWPup: par Inpsyde GmbH – 3.6.10 Controlled Admin Access: par WPRuby – 1.3.6 Elementor Addons & Templates - Sizzify Lite: par ThemeIsle – 1.3.2 Elementor Pro: par Elementor.com – 2.7.2 Elementor: par Elementor.com – 2.7.4 Image Hover Effects Addon for Elementor: par Blocksera – 1.2.6 Jetpack par WordPress.com: par Automattic – 7.8 Loco Translate: par Tim Whitlock – 2.3.0 Mailchimp for WooCommerce: par Mailchimp – 2.2.4 MC4WP: Mailchimp for WordPress: par ibericode – 4.6.1 Premium Addons for Elementor: par Leap13 – 3.7.8 Regenerate Thumbnails: par Alex Mills (Viper007Bond) – 3.1.1 SSL Insecure Content Fixer: par WebAware – 2.7.2 Subscribe to Comments Reloaded: par WPKube – 191011 Title Remover: par WPGurus – 1.2.1 Widget Importer & Exporter: par ChurchThemes.com – 1.5.5 WooCommerce Blocks: par Automattic – 2.4.3 WooCommerce PayPal Checkout Gateway: par WooCommerce – 1.6.17 WooCommerce Stripe Gateway: par WooCommerce – 4.2.5 WooCommerce Services: par Automattic – 1.21.1 WooCommerce: par Automattic – 3.7.1 Wordfence Security: par Wordfence – 7.4.0 WordPress Importer: par wordpressdotorg – 0.6.4 Yoast SEO: par L’équipe Yoast – 12.2 WP Comment Policy Checkbox: par Fco. J. Godoy – 0.3.2 ### Inactive Plugins (6) ### Contact Form 7: par Takayuki Miyoshi – 5.1.4 Elementor - Header, Footer & Blocks: par Brainstorm Force Nikhil Chavan – 1.1.3 NavMenu Addon For Elementor: par ThemeIsle – 1.1.6 Redirection: par John Godley – 4.3 SuevaFree Essential Kit: par ThemeinProgress – 1.0.6 WIP Custom Login: par ThemeinProgress – 1.1.3 ### Settings ### API Enabled: – Force SSL: – Currency: EUR (€) Currency Position: right_space 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: – ### WC Pages ### Base de la boutique: #315 - /boutique/ Panier: #316 - /panier/ Validation de la commande: #317 - /commande/ Mon compte: #318 - /mon-compte/ Conditions générales de vente et d’utilisation: #3 - /mentions-legales-politique-confidentialite-cgv/ ### Theme ### Name: isabellejouvieTN Version: 0.1.0 Author URL: https://www.dreamsonearth.com Child Theme: ? Parent Theme Name: Twenty Nineteen Parent Theme Version: 1.4 Parent Theme Author URL: https://fr.www.ads-software.com/ WooCommerce Support: ? ### Templates ### Overrides: – ### Action Scheduler ### Complete: 0 Oldest: – Newest: – Pending: 0 Oldest: – Newest: – Canceled: 0 Oldest: – Newest: – In-progress: 0 Oldest: – Newest: – Failed: 0 Oldest: – Newest: –
The page I need help with: [log in to see the link]
- The topic ‘How to override woocommerce “class-wc-twenty-nineteen.php” in my child theme’ is closed to new replies.