Adding code to woocomerce.php

Each time I update the X theme my add to cart button reverts back to being over the picture. A developer changed it (numerous times due to updates) to go under the picture instead so when you click the picture customers don’t add the item to cart by accident. Because this happens with EVERY update I was sick of paying the developer to keep fixing it so she told me to just add the code to here: public_html/wp-content/themes/x/framework/functions/plugins/woocommerce.php file:
Im able to get to that but Im not sure where to actually put the code as there seems to be differnet sections, does it just go at the bottom?

Thanks for the help

Hi Nonie,

Thank you for writing in, maybe that is the issue, you keep modifying a file in the parent theme. Your custom functions should go to your child theme’s functions.php file.

Why use a Child Theme?

If you don’t have a child theme yet, please set up one.

How To Setup Child Themes

Hope it helps,
Cheers!

Hi Friech I do have the child theme set up, that was the first thing my freelance developer did. The area they have told me to put it isn’t part of the child theme?

Hi There,

This is a parent theme directory public_html/wp-content/themes/x/
The child theme is public_html/wp-content/themes/x-child/ you will see the functions.php file inside this directory.

Add your custom functions on the bottom of that file.

Let us know how it goes,
Cheers!

So this is the code they gave me: function x_woocommerce_after_shop_loop_item_title() {
echo ‘’;
woocommerce_template_loop_add_to_cart();
}

When I put this in the bottom of the functions.php in child theme I get this message:

Your PHP code changes were rolled back due to an error on line 168 of file wp-content/themes/x/framework/functions/plugins/woocommerce.php. Please fix and try saving again.

Cannot redeclare x_woocommerce_after_shop_loop_item_title() (previously declared in wp-content/themes/x-child/functions.php:155)

Hi,

You can actually do it using css.

Please remove that code then add this in Theme Options > CSS

.woocommerce li.product .entry-header .button {
    opacity:1;
    position: static;
}

That way it will not get overwritten during updates.

Thanks.

Thank you, its almost perfect and so much easier doing it in the css! The only thing is they don’t line up, anyway to get them all the same?

Hi,

Please change css code to this,

.woocommerce li.product .entry-header {
    min-height: 120px;
}

.woocommerce li.product .entry-header .button {
    position: absolute;
    top:auto;
    bottom:0;
    opacity:1;
}

I’ll list below some CSS/HTML resources that should help you to carry on these modifications on your own in the future:

Hope that helps

WOW thank you so much its perfect! That was really easy.
I wonder why the developer made it so difficult and did it so differently.
You are all so helpful here, I really appreciate it!

You’re welcome! :slight_smile:

can I ask one separate question. How do I change the colour of the drop down menu? Ive done it before but cant find the css code to change it. I just changed the header colour and now the drop down is a different colour.
www.honestlynatural.com.au

Hi,

You can change the color in Appearance> Customize > Additional > CSS

Find the following code and change the color (rgb)

div.x-navbar, div.x-navbar .sub-menu{
     background-color: rgb(208, 187, 215) !important;
}
.sub-menu, .sub-menu * {
     background: rgb(208, 187, 215) !important;
     border-color: rgb(208,187,215) !important;
}

Thanks

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.