Home Forums WoodMart support forum Custom plugin

Custom plugin

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #509459

    webkurimaslt
    Participant

    Hey 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.
    #509463

    webkurimaslt
    Participant

    Or 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);
    #509566

    Luke Nielsen
    Keymaster

    Hello,

    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

    #509588

    webkurimaslt
    Participant

    I said for certain categories only. Thats why I made the plugin 🙂

    #509596

    Luke Nielsen
    Keymaster

    Hello,

    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

    #509865

    webkurimaslt
    Participant

    I did my research and didn’t find anything about showing log in instead of add to cart for certain product categories 🙁

    #510126

    Luke Nielsen
    Keymaster

    Hello,

    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

    #510353

    webkurimaslt
    Participant

    I have already added my logins at the initial post if you can see it?

    #510506

    Luke Nielsen
    Keymaster

    Hello,

    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

    #510642

    webkurimaslt
    Participant

    First 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.

    #510752

    Luke Nielsen
    Keymaster

    Hello,

    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

    #510928

    webkurimaslt
    Participant

    I 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.

    #511212

    Luke Nielsen
    Keymaster

    Hello,

    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.
    #511243

    webkurimaslt
    Participant

    What hook should i use on my woodmart single product page?

    #511246

    webkurimaslt
    Participant

    solved

    #511348

    Luke Nielsen
    Keymaster

    Hello,

    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.
Viewing 16 posts - 1 through 16 (of 16 total)

The topic ‘Custom plugin’ is closed to new replies.