• Resolved gad123

    (@gad123)


    Hi,
    My questions deal with the integration between a child theme and WooCommerce.

    Here’s the link to a zip which contains the files of my child theme https://drive.google.com/open?id=1jQmv_-e3v6nl48swXKPAOZR__hvcN6id

    Please notice the function wc_cart_totals_shipping_method_label of WooCommerce which I copied from \plugins\woocommerce\includes\wc-cart-functions.php to the child theme’s functions.php.

    Then I came across two issues.
    The first one is critical: I couldn’t add or modified any page on my site! Only when I deleted this function from the functions.php of my child theme was I able to work as usual on my site.

    The second issue was that this function didn’t override the functions from \plugins\woocommerce\includes\wc-cart-functions.php.
    Notice that I changed
    $has_cost = 0 < $method->cost;
    to
    $has_cost = 0 <= $method->cost;

    But this change didn’t reflect in the behavior and it seemed the WP was ignoring my change and was executing the original function from \plugins\woocommerce\includes\wc-cart-functions.php.

    It seems that there are some integration issues with the WooCommerce and my child theme.

    I’ve already contacted my theme’s support and they told me that that was a Woocommerce issue.

    Any help would be highly appreciated,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hi @gad123,

    The first one is critical: I couldn’t add or modified any page on my site! Only when I deleted this function from the functions.php of my child theme was I able to work as usual on my site.

    From what you’ve described it sounds like some custom code you have been writing has broken some functionality of your site after adding that to a child themes functions.php file.

    This would not be related to your child theme or WooCommerce itself but rather the custom code you have added to your child theme. To resolve the behaviour which you’re facing you’ll either need to remove the code you’ve added to your child theme or refactor that so it does not break your website.

    Thread Starter gad123

    (@gad123)

    Hi Stuart!
    Thank you very much for your answer.
    Here’s my functions.php:

    <?php
    /**
     * Blossom Feminine Child Theme functions and definitions
     *
     * @link https://developer.www.ads-software.com/themes/basics/theme-functions/
     *
     * @package Blossom Feminine Child
     * @since 1.0.0
     */
    
    add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
    
    function enqueue_parent_styles() {
       wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );

    This part is a standard one for enqueuing the parent’s CSS.

    function mytheme_add_woocommerce_support() {
    add_theme_support( 'woocommerce' );
    }
    add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );

    This part is for making the change(s) in the functions.php override the relevant WooCommerce functions. I tried to delete this part, but the bugs I had found, could still be reproduced.

    if (!function_exists('wc_cart_totals_shipping_method_label')){
    function wc_cart_totals_shipping_method_label( $method ) {
    	$label     = $method->get_label();
    	$has_cost  = 0 <= $method->cost;
    	$hide_cost = ! $has_cost && in_array( $method->get_method_id(), array( 'free_shipping', 'local_pickup' ), true );
    
    	if ( $has_cost && ! $hide_cost ) {
    		if ( WC()->cart->display_prices_including_tax() ) {
    			$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
    			if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {
    				$label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
    			}
    		} else {
    			$label .= ': ' . wc_price( $method->cost );
    			if ( $method->get_shipping_tax() > 0 && wc_prices_include_tax() ) {
    				$label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
    			}
    		}
    	}
    
    	return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
    }
    }
    
    ?>

    This one the is the function from \plugins\woocommerce\includes\wc-cart-functions.php with a minor change (which I wanted to override the function that exists in WooCommece).

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problems after adding WooCommerce functions to functions.php’ is closed to new replies.