Home › Forums › WoodMart support forum › Custom plugin
Custom plugin
- This topic has 15 replies, 2 voices, and was last updated 1 year, 1 month ago by Luke Nielsen.
-
AuthorPosts
-
November 2, 2023 at 8:50 pm #509459
webkurimasltParticipantHey i recently made a custom plugin for additional woocommerce functionality and tested it with astra theme, and it did work. It should remove add to cart for certain categories and show login button, but with your theme it doesnt. Maybe you could give me a clue what woodmart is doing differently?
Working page where i tested the code, you can see login button : https://cat.aerealty.lt/product/postcard-v2/
Woodmart page where it does remove add to cart but there is no button iserted in the product summary: https://laverita.lt/product/7514-3000-23/
I also additionally will add my plugin file down below, so you can check the code. And will add my credentials to the store.
Thanks
Attachments:
You must be logged in to view attached files.November 2, 2023 at 8:58 pm #509463
webkurimasltParticipantOr maybe you could suggest a way to insert to woodmart single product summary, because this code doesn’t work:
function display_buttons_for_selected_categories() { if (is_product()) { global $product; $selected_categories = get_option('custom_category_access_selected_categories', array()); // Get the current user object. $user = wp_get_current_user(); // Check if the user has the "Sertifikuotas" role. $is_sertifikuotas = in_array('sertifikuotas', (array)$user->roles); if (has_term($selected_categories, 'product_cat', $product->get_id())) { if ($is_sertifikuotas) { // User has the "Sertifikuotas" role, so no need to show the button. return; } elseif (is_user_logged_in()) { echo '<a href="#"; return false;" class="opt-in-button popmake-5544">Opt in to buy this product</a>'; } else { $button_style = 'style="background-color: green; color: white; border: 2px solid green; padding: 10px 20px; text-decoration: none; display: inline-block;"'; echo '<a href="/my-account/" class="login-signup-button" ' . $button_style . '>Login/Signup</a>'; } } } } add_action('woocommerce_single_product_summary', 'display_buttons_for_selected_categories', 30);
November 3, 2023 at 10:59 am #509566
Luke NielsenKeymasterHello,
In Theme Settings we have the “Login to see add to cart and prices” option: https://prnt.sc/8GkEdSfwnd_m
So you can use this option to have the “Add to cart” button only for the logged-in users.
Kind Regards
November 3, 2023 at 12:12 pm #509588
webkurimasltParticipantI said for certain categories only. Thats why I made the plugin 🙂
November 3, 2023 at 12:39 pm #509596
Luke NielsenKeymasterHello,
If you want to use it only for certain categories, you may use our Theme Presets, which gives the ability to enable the option to the specific category/product/page by using conditions, more detail about it is here: https://xtemos.com/docs-topic/theme-settings-presets/
Kind Regards
November 4, 2023 at 1:41 pm #509865
webkurimasltParticipantI did my research and didn’t find anything about showing log in instead of add to cart for certain product categories 🙁
November 6, 2023 at 11:07 am #510126
Luke NielsenKeymasterHello,
Could you please send me access to the admin dashboard so I can replicate that solution on your side with some specific category?
Looking forward to collaborating with you!
Kind Regards
November 6, 2023 at 10:31 pm #510353
webkurimasltParticipantI have already added my logins at the initial post if you can see it?
November 7, 2023 at 1:25 pm #510506
Luke NielsenKeymasterHello,
I have created the preset with such condition: https://take.ms/LbEHC , then enable the “Login to see add to cart and prices” option and as a result the “add to cart” button is hidden for that category that I set in the condition: https://prnt.sc/pcFdouaeKFc7
So to hide the price and show an appropriate message for logining, paste the below code to the functions.php file in your child theme:
add_action( 'wp', 'woodmart_hide_price_not_logged_in', 1200 );
Kind Regards
November 7, 2023 at 8:42 pm #510642
webkurimasltParticipantFirst of all it doesn’t seem to work for me, second of all i want for the prices to be visible to not logged in user but not allow to add to cart. Thats why i created the custom plugin.
November 8, 2023 at 10:57 am #510752
Luke NielsenKeymasterHello,
1. Without the custom code that is mentioned above, it hides only the “add to cart” button: https://prnt.sc/pcFdouaeKFc7 for not logged in users.
2. Sorry to say but we do not support custom plugins and editing the third-party code is not covered by our support. It requires Customization and this is beyond our limitations and support policy scope. Hope you can understand our limitations.
Kind Regards
November 8, 2023 at 6:30 pm #510928
webkurimasltParticipantI completely understand that you can’t help me with my plugin, but I’m asking you about your theme and what your theme is doing differently than other themes, because on other themes my plugin works and on yours don’t. I provided you with a piece of code in the initial post where in trying to insert the buttons to woocommerces single product pages product summary, but woodmart is somehow overwriting it.
November 9, 2023 at 6:05 pm #511212
Luke NielsenKeymasterHello,
Most likely, your code doesn’t work because you use the Layouts for product page which does not include the Woocomerce hook element with the
woocommerce_single_product_summary
hook selected.Kind Regards
- This reply was modified 1 year, 1 month ago by Luke Nielsen.
November 9, 2023 at 8:56 pm #511243
webkurimasltParticipantWhat hook should i use on my woodmart single product page?
November 9, 2023 at 9:21 pm #511246
webkurimasltParticipantsolved
November 10, 2023 at 10:44 am #511348
Luke NielsenKeymasterHello,
Glad that you have solved the issue.
If there’s anything you need, please write me or another member of our help desk team. We’re here for you!
Have a good day!
Kind Regards
- This reply was modified 1 year, 1 month ago by Luke Nielsen.
-
AuthorPosts
The topic ‘Custom plugin’ is closed to new replies.
- You must be logged in to create new topics. Login / Register