• Resolved isadoe

    (@isadoe)


    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
    Isabelle

    PS : 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]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support EtienneP a11n

    (@etiennep)

    Hi there!

    Thank you for all that information!

    You actually only need to add the following to your child-theme functions.php to be able to customize the image sizes in Customize;

    function remove_woocommerce_support() {
        remove_theme_support( 'woocommerce' );
    }
    add_action( 'after_setup_theme', 'remove_woocommerce_support');

    That will bring back the option to set the image sizes;


    Link to image: https://cld.wthms.co/1Q6dm2

    Thread Starter isadoe

    (@isadoe)

    Hi Etienne,

    Thank you for your answer!
    I added your code to my child-theme functions.php but Customizing > WooCommerce > Product Images still only features the “Thumbnail cropping” part and not the “Main image width” one ??

    Isabelle

    Plugin Support EtienneP a11n

    (@etiennep)

    It might be then that something in the child theme is still overriding this. Can you add the same code to the site using this plugin – https://www.ads-software.com/plugins/code-snippets/

    Then check if those options show. If they do not, then temporarily switch to the Twenty Nineteen parent theme to see if they show then.

    If they do, something in the child theme is the cause of them not showing

    Thread Starter isadoe

    (@isadoe)

    EDIT : Oops, I wrote too fast! Adding the code to the plugin indeed made the “main image width” customization part come back, BUT my site disappeared in the process…. it’s a white empty page now..

    Original answer :

    Hi Etienne,

    It works like a charm when I use the Code Snippets plugin, thanks so much!
    Any idea why it works with the plugin and not with my functions.php file? (it would be perfect if it could work with my file, I’m trying to use as less plugins as I can)

    Here’s my function.php file, maube there’s a basic error since I’m new to coding.. :

    <?php
    /**
    ** activation theme
    **/
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
     wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    /*-----------------------------------------------------------------------------------*/
    /* FAIRE REAPPARAITRE OPTION WOOCOMMERCE DANS MENU PERSONNALISER THEME */
    /*-----------------------------------------------------------------------------------*/ 
    function remove_woocommerce_support() {
        remove_theme_support( 'woocommerce' );
    }
    add_action( 'after_setup_theme', 'remove_woocommerce_support');
    
    /*-----------------------------------------------------------------------------------*/
    /* MODIF COMMENTAIRES */
    /*---------------------------------------------------------woocom--------------------------*/ 
    
    /* COMMENTAIRES EN EUX MEME :*/
    
    /*couleur des commentaires . EST APPELE ligne 38 de comments.php de JL */
    	function isabelle_comments_callback ($comment, $args, $depth) {
    	
    		$GLOBALS['comment'] = $comment; ?>
       
    		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     
    		<div id="comment-<?php comment_ID(); ?>" class="comment-container">
             
    			<div class="comment-avatar">
    				<?php echo get_avatar( $comment->comment_author_email, 80 ); ?>
    			</div>
             
    			<div class="comment-text">
    			
                	<header class="comment-author"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                    
                        <span class="author"><cite><?php printf( esc_html__('%s','twentynineteen'), get_comment_author_link());?> </cite> </span>
                        <time datetime="<?php echo get_comment_date("c")?>" class="comment-date">  
                        <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(esc_html__('%1$s at %2$s','twentynineteen'), get_comment_date(),  get_comment_time()) ?></a> - 
                        <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
                        <?php edit_comment_link(esc_html__('(Edit)','twentynineteen')) ?>
                        </time>
                    
    				</header>
        
    				<?php if ($comment->comment_approved == '0') : ?>
    				<br /><em><?php esc_html_e('Your comment is awaiting approval.','twentynineteen') ?></em>
    				<?php endif; ?>
              
    				<?php comment_text() ?>
              
    			</div>
            
    			<div class="clear"></div>
            
    		</div>
    
    <?php 
    
    	} 
    	
    	
    	
    /* FORMULAIRE AJOUTER UN COMMENTAIRE : mettre placeholders a l interieur des champs commentaire : */
    
    /* version avec légende au-dessus cases :
    function isabelle_update_comment_fields( $fields ) {
    
    	$commenter = wp_get_current_commenter();
    	$req       = get_option( 'require_name_email' );
    	$label     = $req ? '*' : ' ' . __( '(optional)', 'text-domain' );
    	$aria_req  = $req ? "aria-required='true'" : '';
    
    	$fields['author'] =
    		'<p class="comment-form-author">
    			<label for="author">' . __( "", "text-domain" ) . $label . '</label>
    			<input id="author" name="author" type="text" placeholder="' . esc_attr__( "Votre nom *", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author'] ) .
    		'" size="30" ' . $aria_req . ' />
    		</p>';
    
    	$fields['email'] =
    		'<p class="comment-form-email">
    			<label for="email">' . __( "Email", "text-domain" ) . $label . '</label>
    			<input id="email" name="email" type="email" placeholder="' . esc_attr__( "Votre adresse email *", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author_email'] ) .
    		'" size="30" ' . $aria_req . ' />
    		</p>';
    
    	$fields['url'] =
    		'<p class="comment-form-url">
    			<label for="url">' . __( "Website", "text-domain" ) . '</label>
    			<input id="url" name="url" type="url"  placeholder="' . esc_attr__( "https://google.com", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author_url'] ) .
    		'" size="30" />
    			</p>';
    
    	return $fields;
    }
    add_filter( 'comment_form_default_fields', 'isabelle_update_comment_fields' ); */
    
    /* version SANS legende : */
    function isabelle_update_comment_fields( $fields ) {
    
    	$commenter = wp_get_current_commenter();
    	$req       = get_option( 'require_name_email' );
    	$label     = $req ? '*' : ' ' . __( '(optional)', 'text-domain' );
    	$aria_req  = $req ? "aria-required='true'" : '';
    
    	$fields['author'] =
    		'<p class="comment-form-author">
    			<input id="author" name="author" type="text" placeholder="' . esc_attr__( "Votre nom *", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author'] ) .
    		'" size="30" ' . $aria_req . ' />
    		</p>';
    
    	$fields['email'] =
    		'<p class="comment-form-email">
    			<input id="email" name="email" type="email" placeholder="' . esc_attr__( "Votre adresse email *", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author_email'] ) .
    		'" size="30" ' . $aria_req . ' />
    		</p>';
    
    	$fields['url'] =
    		'<p class="comment-form-url">
    			<label for="url">' . __( "Website", "text-domain" ) . '</label>
    			<input id="url" name="url" type="url"  placeholder="' . esc_attr__( "https://google.com", "text-domain" ) . '" value="' . esc_attr( $commenter['comment_author_url'] ) .
    		'" size="30" />
    			</p>';
    			
    	return $fields;
    }
    add_filter( 'comment_form_default_fields', 'isabelle_update_comment_fields' );
    
    function isabelle_update_comment_field( $comment_field ) {
      $comment_field =
        '<p class="comment-form-comment">
                <textarea required id="comment" name="comment" placeholder="' . esc_attr__( "Au plaisir de vous lire ! :)", "text-domain" ) . '" cols="45" rows="8" aria-required="true"></textarea>
            </p>';
    
      return $comment_field;
    }
    add_filter( 'comment_form_field_comment', 'isabelle_update_comment_field' );	
    
    function comment_form_isabelle( $args = array(), $post_id = null ) {
    	if ( null === $post_id ) {
    		$post_id = get_the_ID();
    	}
    
    	// Exit the function when comments for the post are closed.
    	if ( ! comments_open( $post_id ) ) {
    		/**
    		 * Fires after the comment form if comments are closed.
    		 *
    		 * @since 3.0.0
    		 */
    		do_action( 'comment_form_comments_closed' );
    
    		return;
    	}
    
    	$commenter     = wp_get_current_commenter();
    	$user          = wp_get_current_user();
    	$user_identity = $user->exists() ? $user->display_name : '';
    
    	$args = wp_parse_args( $args );
    	if ( ! isset( $args['format'] ) ) {
    		$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
    	}
    
    	$req      = get_option( 'require_name_email' );
    	$html_req = ( $req ? " required='required'" : '' );
    	$html5    = 'html5' === $args['format'];
    	
    	
    
    	$fields   = array(
    		'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    					 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>',
    		'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    					 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $html_req . ' /></p>',
    		'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
    					 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
    	);
    
    	if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) {
    		$consent           = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>';
    
    		// Ensure that the passed fields include cookies consent.
    		if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) {
    			$args['fields']['cookies'] = $fields['cookies'];
    		}
    	}
    
    	$required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' );
    
    	/**
    	 * Filters the default comment form fields.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param string[] $fields Array of the default comment fields.
    	 */
    	$fields   = apply_filters( 'comment_form_default_fields', $fields );
    	$defaults = array(
    		'fields'               => $fields,
    		'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>',
    		
    		/** This filter is documented in wp-includes/link-template.php */
    		'must_log_in'          => '<p class="must-log-in">' . sprintf(
    			/* translators: %s: login URL */
    									__( 'You must be <a href="%s">logged in</a> to post a comment.' ),
    			wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
    		) . '</p>',
    		/** This filter is documented in wp-includes/link-template.php */
    		'logged_in_as'         => '<p class="logged-in-as">' . sprintf(
    			/* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
    									__( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
    			get_edit_user_link(),
    			/* translators: %s: user name */
    									esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
    			$user_identity,
    			wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
    		) . '</p>',
    		'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>',
    		'comment_notes_after'  => '',
    		'action'               => site_url( '/wp-comments-post.php' ),
    		'id_form'              => 'commentform',
    		'id_submit'            => 'submit',
    		'class_form'           => 'comment-form',
    		'class_submit'         => 'submit',
    		'name_submit'          => 'submit',
    		'title_reply'          => __( 'Leave a Reply' ),
    		'title_reply_to'       => __( 'Leave a Reply to %s' ),
    		'title_reply_before'   => '<h3 id="reply-title" class="comment-reply-title">',
    		'title_reply_after'    => '</h3>',
    		'cancel_reply_before'  => ' <small>',
    		'cancel_reply_after'   => '</small>',
    		'cancel_reply_link'    => __( 'Cancel reply' ),
    		'label_submit'         => __( 'Post Comment' ),
    		'submit_button'        => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
    		'submit_field'         => '<p class="form-submit">%1$s %2$s</p>',
    		'format'               => 'xhtml',
    	);
    
    	/**
    	 * Filters the comment form default arguments.
    	 *
    	 * Use {@see 'comment_form_default_fields'} to filter the comment fields.
    	 *
    	 * @since 3.0.0
    	 *
    	 * @param array $defaults The default comment form arguments.
    	 */
    	$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
    
    	// Ensure that the filtered args contain all required default values.
    	$args = array_merge( $defaults, $args );
    
    	/**
    	 * Fires before the comment form.
    	 *
    	 * @since 3.0.0
    	 */
    	do_action( 'comment_form_before' );
    	?>
    	<div id="respond" class="comment-respond">
    		<?php
    		echo $args['title_reply_before'];
    
    		comment_form_title( $args['title_reply'], $args['title_reply_to'] );
    
    		echo $args['cancel_reply_before'];
    
    		cancel_comment_reply_link( $args['cancel_reply_link'] );
    
    		echo $args['cancel_reply_after'];
    
    		echo $args['title_reply_after'];
    
    		if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :
    			echo $args['must_log_in'];
    			/**
    			 * Fires after the HTML-formatted 'must log in after' message in the comment form.
    			 *
    			 * @since 3.0.0
    			 */
    			do_action( 'comment_form_must_log_in_after' );
    		else :
    			?>
    			<form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>>
    				<?php
    				/**
    				 * Fires at the top of the comment form, inside the form tag.
    				 *
    				 * @since 3.0.0
    				 */
    				do_action( 'comment_form_top' );
    
    				if ( is_user_logged_in() ) :
    					/**
    					 * Filters the 'logged in' message for the comment form for display.
    					 *
    					 * @since 3.0.0
    					 *
    					 * @param string $args_logged_in The logged-in-as HTML-formatted message.
    					 * @param array  $commenter      An array containing the comment author's
    					 *                               username, email, and URL.
    					 * @param string $user_identity  If the commenter is a registered user,
    					 *                               the display name, blank otherwise.
    					 */
    					echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
    
    					/**
    					 * Fires after the is_user_logged_in() check in the comment form.
    					 *
    					 * @since 3.0.0
    					 *
    					 * @param array  $commenter     An array containing the comment author's
    					 *                              username, email, and URL.
    					 * @param string $user_identity If the commenter is a registered user,
    					 *                              the display name, blank otherwise.
    					 */
    					do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
    
    				else :
    
    					echo $args['comment_notes_before'];
    
    				endif;
    
    				// Prepare an array of all fields, including the textarea
    				$comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
    
    				/**
    				 * Filters the comment form fields, including the textarea.
    				 *
    				 * @since 4.4.0
    				 *
    				 * @param array $comment_fields The comment fields.
    				 */
    				$comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
    
    				// Get an array of field names, excluding the textarea
    				$comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
    
    				// Get the first and the last field name, excluding the textarea
    				$first_field = reset( $comment_field_keys );
    				$last_field  = end( $comment_field_keys );
    
    				foreach ( $comment_fields as $name => $field ) {
    
    					if ( 'comment' === $name ) {
    
    						/**
    						 * Filters the content of the comment textarea field for display.
    						 *
    						 * @since 3.0.0
    						 *
    						 * @param string $args_comment_field The content of the comment textarea field.
    						 */
    						echo apply_filters( 'comment_form_field_comment', $field );
    
    						echo $args['comment_notes_after'];
    
    					} elseif ( ! is_user_logged_in() ) {
    
    						if ( $first_field === $name ) {
    							/**
    							 * Fires before the comment fields in the comment form, excluding the textarea.
    							 *
    							 * @since 3.0.0
    							 */
    							do_action( 'comment_form_before_fields' );
    						}
    
    						/**
    						 * Filters a comment form field for display.
    						 *
    						 * The dynamic portion of the filter hook, <code>$name</code>, refers to the name
    						 * of the comment form field. Such as 'author', 'email', or 'url'.
    						 *
    						 * @since 3.0.0
    						 *
    						 * @param string $field The HTML-formatted output of the comment form field.
    						 */
    						echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
    
    						if ( $last_field === $name ) {
    							/**
    							 * Fires after the comment fields in the comment form, excluding the textarea.
    							 *
    							 * @since 3.0.0
    							 */
    							do_action( 'comment_form_after_fields' );
    						}
    					}
    				}
    
    				$submit_button = sprintf(
    					$args['submit_button'],
    					esc_attr( $args['name_submit'] ),
    					esc_attr( $args['id_submit'] ),
    					esc_attr( $args['class_submit'] ),
    					esc_attr( $args['label_submit'] )
    				);
    
    				/**
    				 * Filters the submit button for the comment form to display.
    				 *
    				 * @since 4.2.0
    				 *
    				 * @param string $submit_button HTML markup for the submit button.
    				 * @param array  $args          Arguments passed to comment_form().
    				 */
    				$submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
    
    				$submit_field = sprintf(
    					$args['submit_field'],
    					$submit_button,
    					get_comment_id_fields( $post_id )
    				);
    
    				/**
    				 * Filters the submit field for the comment form to display.
    				 *
    				 * The submit field includes the submit button, hidden fields for the
    				 * comment form, and any wrapper markup.
    				 *
    				 * @since 4.2.0
    				 *
    				 * @param string $submit_field HTML markup for the submit field.
    				 * @param array  $args         Arguments passed to comment_form().
    				 */
    				echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
    
    				/**
    				 * Fires at the bottom of the comment form, inside the closing </form> tag.
    				 *
    				 * @since 1.5.0
    				 *
    				 * @param int $post_id The post ID.
    				 */
    				do_action( 'comment_form', $post_id );
    				?>
    			</form>
    		<?php endif; ?>
    	</div><!-- #respond -->
    	<?php
    
    	/**
    	 * Fires after the comment form.
    	 *
    	 * @since 3.0.0
    	 */
    	do_action( 'comment_form_after' );
    }
    
    /* mettre champs nom et email AVANT celui commentaire */
    
    if ( !wp_is_mobile() ) {
    function isabelle_move_comment_field_to_bottom( $fields ) {
    $comment_field = $fields['comment'];
    unset( $fields['comment'] );
    $fields['comment'] = $comment_field;
    return $fields;
    }
    
    add_filter( 'comment_form_fields', 'isabelle_move_comment_field_to_bottom' );
    }
    
    /* retrait website */
    
    add_filter( 'comment_form_defaults', 'isabelle_manage_default_fields');
     
    // $default contient tous les messages du formulaire de commentaire
    // il contient également "comment_field", le textarea du message
     
    if ( !function_exists('isabelle_manage_default_fields')) {
       function isabelle_manage_default_fields( $default ) {
     
          // Récupération des infos connues sur le visiteur
          // Permet de pré-remplir nos nouveaux champs
     	
          $commenter = wp_get_current_commenter();
     
          // Suppression d'un champ par défaut parmi : author, email, url
     	
          unset ( $default['fields']['url'] );
     	
     	
          // On retourne le tableau des champs
     	
          return $default;
       }
    }
    
    /*-----------------------------------------------------------------------------------*/
    /* AJOUTER BOUTON CONTINUER SHOPPING DANS PANIER */
    /*-----------------------------------------------------------------------------------*/ 
    
    add_action( 'woocommerce_after_cart_totals', 'isa_continue_shopping_button' );
    
    function isa_continue_shopping_button() {
    
    	 // On récupère le lien de votre page boutique   
    	 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
     
    	 // On ajoute notre bouton 
    	echo '<div class="isa-continue-shopping">';
    	echo ' <a href="'.$shop_page_url.'" class="button isa-shopping-button">Ou continuer le shopping</a>';
    	echo '</div>';
    }
    
    /*-----------------------------------------------------------------------------------*/
    /* BOUTON BACK TO TOP (lié à fichier js créé par moi) */
    /*-----------------------------------------------------------------------------------*/ 
    /**
     * Enqueue button javascript script.
     */
    function themeslug_add_button_script() {
      wp_enqueue_script( 'custom-script', get_stylesheet_directory_uri() . '/js/back-to-top.js', array( 'jquery' ) );
    }
    add_action( 'wp_enqueue_scripts', 'themeslug_add_button_script' );
    
    /**
     * Add button HTML to the footer section.
     */
    function themeslug_add_scroll_button() {
      echo '<a href="#" id="topbutton"></a>';
    }
    add_action( 'wp_footer', 'themeslug_add_scroll_button' );
    }
    • This reply was modified 5 years, 1 month ago by isadoe.
    Plugin Support EtienneP a11n

    (@etiennep)

    Ok, the white screen is probably since you still have the same code in the child theme and now in the plugin as well and that is causing this.

    I copied the code from above and had a look at it, and the only thing I noticed was an out of place } right on the last line of the file.

    Remove that and add it back in right in the beginning after;

    /**
    ** activation theme
    **/
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
     wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

    So, like this;

    /**
    ** activation theme
    **/
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
     wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }

    When I do that, using your functions.php file above with that change works on my site with Twenty Nineteen and a child theme and you would not need the Code Snippets plugin again

    Thread Starter isadoe

    (@isadoe)

    Yaay, you made my day, it works! Haha, thank you for your help and your patience, I knew that all could come down to a bracket and here’s the perfect example. I didn’t see that error because it wasn’t marked with a red cross in my editor…

    Everything works fine now, thanks again and have a nice day ??

    Isabelle

    Plugin Support EtienneP a11n

    (@etiennep)

    It was a pleasure!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to override woocommerce “class-wc-twenty-nineteen.php” in my child theme’ is closed to new replies.