- This topic has 13 replies, 2 voices, and was last updated 4 years, 6 months ago by
David.
-
AuthorPosts
-
November 29, 2018 at 4:33 am #743614
wonzilla
Hi there,
I need to add a different width to the short description area but I can’t since the product image and short description have separate div containers. Beside the div container around these two, I want to wrap the short product description with a second div container to apply some padding. Hope someone can help me with this. Thank you!
November 29, 2018 at 5:21 am #743645David
StaffCustomer SupportHi there,
can you provide a link to the product page? Will help providing a solution.
November 29, 2018 at 5:39 am #743666wonzilla
Hi David,
My site is under construction right now but it’s the same html markup as in the standard WooCommerce single product page. I’ve attached some screenshots below to see where I want to add the containers:
Wrap product image and short description:
https://ibb.co/ZdCVSjYAlso wrap short description:
https://ibb.co/KzJDP0RNovember 29, 2018 at 6:13 am #743693David
StaffCustomer SupportOK, so using the Hook Element, you can add those opening and closing elements to the following hooks and assign the display rules to Product:
Product summary wrapper:
Open:woocommerce_before_single_product_summary
Close:woocommerce_after_single_product_summary
The inner wrapper try:
Open:woocommerce_single_product_summary
Close:woocommerce_share
As some of these hooks will be being used you may need to increase or decrease the Hooks Priority to get them where you need them.
November 29, 2018 at 6:53 am #743830wonzilla
Thank you, it works! However there are 4 different hooks that I need to add and this doesn’t seem to be very elegant. Isn’t there a code to do this job because I don’t feel really confident using this method.
November 29, 2018 at 7:01 am #743837David
StaffCustomer SupportYou can add PHP functions for each of he hooks, example of one here step and repeat for each hook making sure each has a unique function:
add_action( 'woocommerce_before_single_product_summary', 'my_unique_named_function', 15 ); function my_unique_named_function() { echo 'HTML here'; }
November 29, 2018 at 7:05 am #743840wonzilla
Also it is ok to add the opening and close tags in different hooks because it looks kind of buggy… sorry but I’m not very familiar with php.
November 29, 2018 at 7:10 am #743844David
StaffCustomer SupportYeah it looks buggy 🙂 But is fine – its just the code checker reporting the fact the other part of the element is missing. I generally add a HTML comment before these elements to make it clearer e.g
<!-- close custom wrapper --?</div>
It will still flag red but it just makes it easier to read.
November 29, 2018 at 7:11 am #743846wonzilla
Thank you for the code, but I have a doubt when adding the html. If I add it without the closing tag, it automatically adds it on the product page and I wonder if this is ok or should I add it manually somewhere in the code?
add_action( 'woocommerce_before_single_product_summary', 'my_unique_named_function', 15 ); function my_unique_named_function() { echo '<div class="wrap-product-summary">'; }
November 29, 2018 at 7:22 am #743855David
StaffCustomer SupportHi there,
some Hooks are related like those before and after hooks and will self close.
Personally i still add the closing function. It won’t make any difference.Where there isn’t a relationship between the two like with the inner summary you will (should) need both.
November 29, 2018 at 7:27 am #743863wonzilla
Oh, ok. I was afraid that this will lead to some errors. Now I’m unsure which method should I choose for best results – using the hooks or adding the code? I want to make sure that everything loads perfectly. Thank you again!
November 29, 2018 at 7:52 am #743882David
StaffCustomer SupportEither way works. The code means you keep them all together. The Hooks makes them a little more accessible for editing. Glad to be of help.
November 29, 2018 at 8:04 am #743894wonzilla
Hi David,
Sorry for the confusion but when I add the code without the closing tag for
woocommerce_before_single_product_summary
it wraps the whole page and makes it impossible to apply a background color for the short description area.This is how I added the closing tag but I’m not sure if this is the best method (please note that the priority is set to 9 because otherwise it will also wrap the description and reviews tabs):
add_action( 'woocommerce_before_single_product_summary', 'my_unique_named_function', 5 ); function my_unique_named_function() { echo '<div class="clearfix wrap-product-summary">'; } add_action( 'woocommerce_after_single_product_summary', 'my_unique_named_functionn', 9 ); function my_unique_named_functionn() { echo '</div>'; }
Is there any way to add it without so much code?
November 29, 2018 at 8:24 am #743907David
StaffCustomer SupportThat looks fine to me.
-
AuthorPosts
- You must be logged in to reply to this topic.