Child Function.php not pulling in code - by samtex9

This topic has 6 replies, 2 voices, and was last updated 6 years ago ago by Rose Tyler

  • Avatar: samtex9
    samtex9
    Participant
    April 23, 2018 at 11:38

    I put the following code in the child function.php and it did not work. I put the same code in the main theme function.php and it worked perfectly …
    Please advise

    add_action('woocommerce_check_cart_items','check_cart_weight');
    
    function check_cart_weight(){
        global $woocommerce;
        $weight = $woocommerce->cart->cart_contents_weight;
        if( $weight > 30 ){
            wc_add_notice( sprintf( __( 'You have %sKg weight and we allow only 30Kg of weight per order.', 'woocommerce' ), $weight ), 'error' );
        }
    }
    5 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 23, 2018 at 12:21

    Hello,

    Have you activated the child theme on site (Appearance > Themes)?
    Try to check if this function does not work at all from child theme, you may just echo ‘some text’; in the function to see if it works. If so then it could be wc_add_notice function causes the problem and try to add next strings

    add_action('wp_ajax_add_transfer', 'check_cart_weight');
    add_action('wp_ajax_nopriv_add_transfer', 'check_cart_weight');

    If the problem woun’t be solved, provide temporary wp-admin access and describe in more details how to recreate (what dares to do to see how it works).

    Regards

    Avatar: samtex9
    samtex9
    Participant
    April 23, 2018 at 13:52

    I have tried to echo out in the child theme and it still does not work. You will find access below to the admin section of the

    Please, contact administrator
    for this information.
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 23, 2018 at 14:57

    On your site, the active theme is the parent theme https://prnt.sc/j90esu
    If you make changes in the child theme and want to see an effect of changes, you need to activate the child theme on site.

    Regards

    Avatar: samtex9
    samtex9
    Participant
    April 23, 2018 at 15:41

    You are right. That was a very basic error on our part and we are very sorry for taking your time with this matter. Thank you for spotting our mistake.

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    April 23, 2018 at 15:44

    You’re welcome!
    Have a nice day.

    Regards

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.