-
AuthorPosts
-
June 22, 2017 at 3:36 pm #811612
Hi Guys,
Ok I added a hook to show a button on the single product page
add_action(‘woocommerce_after_add_to_cart_button’,’cmk_additional_button’);
function cmk_additional_button() {
echo ‘<button type=”submit” class=”button alt”>test</button>’;
}This works and is shown on all products now.
How can I restrict this so it only shows on single product pages that are within certain categories, for example “Commercial Gym Equipment” only?
Thank you in advance.
June 22, 2017 at 7:24 pm #811774Hey Gekko101,
You need a conditional statement that would check for category id or single product template and show it then.
Best regards,
VictoriaJune 22, 2017 at 7:47 pm #811788Thanks, I got it working here (link supplied)
How can I pad the space between the new button and the Add to Cart button?
June 22, 2017 at 8:00 pm #811796The extra button seems to have the class – button.button.alt (I could be wrong)
How can I pad this new button or in fact pad the existing ‘Add to cart’ button to make a space between the 2 buttons?
June 23, 2017 at 6:50 am #811967Hi,
Please try the following in Quick CSS under Enfold->General Styling:
.single_add_to_cart_button { margin-right: 10px; }
Best regards,
RikardJune 23, 2017 at 11:37 am #812054Thanks, however this code doesnt work for me and doesnt change this?
.single_add_to_cart_button {
margin-right: 10px;
}June 23, 2017 at 7:09 pm #812255Hi Gekko101,
Here is the code you can put in Enfold > General Styling > Quick Css, if it does not work, put into themes/enfold/css/custom.css
.single_add_to_cart_button { margin-right: 10px !important; }
If you need further assistance please let us know.
Best regards,
VictoriaJune 24, 2017 at 4:58 pm #812461Thank you, this works!
However when I click the new ‘Commercial Finance’ button, instead of linking out to the relevant page it adds the item to the cart instead?
The full code I’m using is –
add_action(‘woocommerce_after_add_to_cart_button’, ‘cmk_additional_button’);
function cmk_additional_button() {if ( is_product() && has_term( ‘Commercial Gym Equipment’, ‘product_cat’ ) ) {
echo ‘<button type=”submit” class=”button alt”>Commercial Finance Available</button>’;
}
}
Why is this new button adding products to the cart, its only meant to be a button that links to a page?- This reply was modified 7 years, 5 months ago by Gekko101.
June 24, 2017 at 6:09 pm #812473June 24, 2017 at 6:14 pm #812475Thanks, I tried this but if I remove button type=”submit” it removes the entire button and just leaves behind the text?
June 24, 2017 at 6:45 pm #812483Hi,
I meant like this:<button class=”button alt”>Commercial Finance Available</button>
Best regards,
MikeJune 24, 2017 at 7:11 pm #812489Thanks for the reply mike, however it changed the style of the button, but it still adds the item to the cart and doent link out to the nominated URL
June 24, 2017 at 7:12 pm #812490Also I note when I post the code here, the forum strips some of the details out
June 24, 2017 at 7:18 pm #812492Hi,
Oh, that link makes more sense :) I’ll have to do some more research.Best regards,
MikeJune 24, 2017 at 10:18 pm #812547Thanks Mike, let me know what you think, I have a client breathing down my neck on this one ;(
June 26, 2017 at 10:11 am #812945Hi Gekko101,
You don’t have a closing tag to the link in your code. Try adding it. Also, you don’t need the button element, you can have just the link and style it as the button.
Best regards,
VictoriaJune 26, 2017 at 10:27 am #812955Thank you so much for your reply, I have added the closing tag however it makes no difference.
I keep going round and round in circles with this one… :(
June 26, 2017 at 1:59 pm #813058Hi Gekko101,
You could try these attributes
but the button is in the form, so even that might not work, you have to find another action, that would render the button outside of the form.Best regards,
VictoriaJune 26, 2017 at 3:04 pm #813081Thank you, this has finally worked. Thank you very much :)
The button is misaligned on mobile devices however..
- This reply was modified 7 years, 5 months ago by Gekko101. Reason: Update
June 26, 2017 at 3:39 pm #813111Hi,
We’re glad that the team was able to help you. We’ll close this thread now, but if you have any other questions or issues, feel free to post them here on the forum and we will do our best to help.
Thank you for using Enfold.
Cheers!
Sarah -
AuthorPosts
- The topic ‘Show button for nominated category only?’ is closed to new replies.