How can I make sure the child theme functions.php is running

I bought the Porto Wordpress Theme, and created and activated a child theme.

In the child theme, I put a functions.php file to make the Woocommerce phone billing field optional.

There is no closing ?> tag that could cause any kind of problem.

//make billing fields not required in checkout
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
    return $address_fields;
}

I also put exit(); in the file to see what happens, but nothing happens at all.

How can I make sure the functions.php file is being called at all.

Full functions.php content

(Some snippets could be outdated but none of them works, and that is strange).

    add_action( 'wp_enqueue_scripts', 'porto_child_css', 1001 );

    // Load CSS
    function porto_child_css() {
        // porto child theme styles
        wp_deregister_style( 'styles-child' );
        wp_register_style( 'styles-child', esc_url( get_stylesheet_directory_uri() ) . '/style.css' );
        wp_enqueue_style( 'styles-child' );
    }


    // Pre-populate Woocommerce checkout fields
    add_filter('woocommerce_checkout_get_value', function($input, $key ) {

        global $current_user;

        switch ($key) :
            case 'billing_first_name':
            case 'shipping_first_name':
                return "HEEEY".$current_user->first_name;
            break;

            case 'billing_last_name':
            case 'shipping_last_name':
                return $current_user->last_name;
            break;

            case 'billing_email':
                return $current_user->user_email;
            break;

            case 'billing_phone':
                return $current_user->phone;
            break;

        endswitch;

    }, 10, 2);




    // Remove some fields from Woocommerce

    add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );

    function custom_remove_woo_checkout_fields( $fields ) {

        // remove billing fields
        //unset($fields['billing']['billing_first_name']);
        //unset($fields['billing']['billing_last_name']);
        unset($fields['billing']['billing_company']);
        unset($fields['billing']['billing_address_1']);
        unset($fields['billing']['billing_address_2']);
        unset($fields['billing']['billing_city']);
        unset($fields['billing']['billing_postcode']);
        unset($fields['billing']['billing_country']);
        unset($fields['billing']['billing_state']);
        unset($fields['billing']['billing_phone']);
        unset($fields['billing']['billing_email']);

        // remove shipping fields 
        unset($fields['shipping']['shipping_first_name']);    
        unset($fields['shipping']['shipping_last_name']);  
        unset($fields['shipping']['shipping_company']);
        unset($fields['shipping']['shipping_address_1']);
        unset($fields['shipping']['shipping_address_2']);
        unset($fields['shipping']['shipping_city']);
        unset($fields['shipping']['shipping_postcode']);
        unset($fields['shipping']['shipping_country']);
        unset($fields['shipping']['shipping_state']);

        // remove order comment fields
        unset($fields['order']['order_comments']);

        return $fields;
    }

    //make billing fields not required in checkout
    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
    function wc_npr_filter_phone( $address_fields ) {
        $address_fields['billing_phone']['required'] = false;
            return $address_fields;
    }

    //make shipping fields not required in checkout
    add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_shipping_fields', 10, 1 );
    function wc_npr_filter_shipping_fields( $address_fields ) {
        $address_fields['shipping_first_name']['required'] = false;
        $address_fields['shipping_last_name']['required'] = false;
        $address_fields['shipping_address_1']['required'] = false;
        $address_fields['shipping_city']['required'] = false;
        $address_fields['shipping_postcode']['required'] = false;
            return $address_fields;
    }


    // Hide the "Expires" and "Downloads Remaining" columns from emails and My Account
    add_action( 'woocommerce_account_downloads_columns', 'custom_downloads_columns', 10, 1 ); // Orders and account
    add_action( 'woocommerce_email_downloads_columns', 'custom_downloads_columns', 10, 1 ); // Email notifications
    function custom_downloads_columns( $columns ){
        // Removing "Download expires" column
        if(isset($columns['download-expires']))
            unset($columns['download-expires']);

        // Removing "Download remaining" column
        if(isset($columns['download-remaining']))
            unset($columns['download-remaining']);

        return $columns;
    }

Upvotes: 0

Views: 294

Answers (2)

awran5
awran5

Reputation: 4536

Since it's a premium theme, you should get support and the "right solution" only from your theme support team. However, you can try to increase the priority of the filter hook.

    // Default values already are '10', '1' increase '10' to '99' or more
    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 99 );

Upvotes: 0

TobiasM
TobiasM

Reputation: 398

As long as your child theme is active it should be called (Go to appearance > themes and make sure your child theme is active). You don't need a closing tag at the end of your functions.php in order for the file to work. However, a good way to test it out could be to call your style.css file that is located in your child theme folder. At the top of your functions.php you should be able to see wp_enqueue_style.

Try also enqueue the child theme style.css by using get_stylesheet_directory_uri() (the parrent style.css is using get_template_directory_uri).

It should look something like this:

// enqueue styles for child theme
function example_enqueue_styles() {

    // enqueue parent styles
    wp_enqueue_style('parent-theme', get_template_directory_uri() .'/style.css');

    // enqueue child styles
    wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/style.css', array('parent-theme'));

}
add_action('wp_enqueue_scripts', 'example_enqueue_styles');

Now reload your site -> inspect site and choose "Network tab". From here you can see all files loaded on your site. Try to locate the child theme style.css file. If you see the file in your network tab it's being called for sure.

Upvotes: 1

Related Questions