• Resolved yerim25

    (@yerim25)


    Hi,
    I’m trying to create a child theme for customizing Woocommerce registration fields. However, neither my child style.css nor functions.php do not work.

    Below is my style.css:

    /*
     Theme Name:   Shopper Child
     Template:     shopper
    */
    
    * { background-color: red !important; }

    I added a background color to all elements to see if the child theme works, I refreshed the site, but nothing changed.

    Below is my functions.php file :

    <?php
    
    function shopper_child_enqueue_styles() {
    
        $parent_style = 'shopper-style'; 
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }
    add_action( 'wp_enqueue_scripts', 'shopper_child_enqueue_styles' );
    /**
    * Add new register fields for WooCommerce registration.
    * 
    *
    * @return string Register fields HTML.
    */
    function wooc_extra_register_fields() {
    ?>
    
    <p class="form-row form-row-wide">
    <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
    </p>
    
    <p class="form-row form-row-wide">
    <label for="reg_billing_address_1"><?php _e( 'Address', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_address_1" id="reg_billing_address_1" value="<?php if ( ! empty( $_POST['billing_address_1'] ) ) esc_attr_e( $_POST['billing_address_1'] ); ?>" />
    </p>
    
    <p class="form-row form-row-wide">
    <label for="reg_billing_postcode"><?php _e( 'postcode', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_postcode" id="reg_billing_postcode" value="<?php if ( ! empty( $_POST['billing_postcode'] ) ) esc_attr_e( $_POST['billing_postcode'] ); ?>" />
    </p>
    
    <p class="form-row form-row-wide">
    <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />
    </p>
    
    <?php
    }
    
    add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
    
     ?>

    I think this isn’t the theme’s problem because I tried creating a child theme to 2 sites using different themes but neither of them worked.

    The location of the folder is correct: I created a child theme folder where other themes are, and inside the folder, there are two files: style.css and functions.php.

    If I create a plugin and add my code to it, it works. But I prefer using a child theme to installing a plugin, so I want to know why my child themes don’t work.

    Thank you in advance.

    • This topic was modified 6 years, 10 months ago by yerim25.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What do you mean by the style.css file doesn’t work?

    Thread Starter yerim25

    (@yerim25)

    CSS style doesn’t apply to the elements at all.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you show us your site? If not, first ensure the Child Theme style.css file is being loaded in the website (source code).

    Thread Starter yerim25

    (@yerim25)

    This is my site:

    https://yerimk.sgedu.site/

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Your Child Theme style.css file isn’t being loaded in. This may be a plugin or theme conflict. Please attempt to disable all plugins, and use one of the default (Twenty*) themes. If the problem goes away, enable them one by one to identify the source of your troubles.

    If you can install plugins, install “Health Check”: https://www.ads-software.com/plugins/health-check/ On the troubleshooting tab, you can click the button to disable all plugins and change the theme for you, while you’re still logged in, without affecting normal visitors to your site.

    This is to narrow down the problem. If it’s a theme or plugin problem, we’ll then be able to forward you to the right people.

    Thread Starter yerim25

    (@yerim25)

    I disabled all plugins, made a child theme of Twenty Seventeen theme, and in the style.css file I added a background color to all elements, but it still doesn’t work.

    Just a sanity check: Have you selected the child-theme to be used under Appearance > themes?

    Thread Starter yerim25

    (@yerim25)

    I activated the child theme, and it worked! The theme didn’t work because I didn’t activate it.

    Thank you so much!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Child theme doesn’t work’ is closed to new replies.