0

I want to auto check on Downloadable and Virtual checkbox on Dokan plugin, this my code:

add_action( 'woocommerce_product_options_general_product_data', 'hiding_and_set_product_settings' );
function hiding_and_set_product_settings(){

    ## ==> Set HERE your targeted user role:
    $targeted_user_roles = array( 'administrator', 'shop_manager', 'vendor', 'vendors' );

    // Getting the current user object
    $user = wp_get_current_user();
    // getting the roles of current user
    $user_roles = $user->roles;

    if ( array_intersect( $targeted_user_roles, $user_roles ) ){

        ## CSS RULES ## (change the opacity to 0 after testing)
        // HERE Goes OUR CSS To hide 'virtual' and 'downloadable' checkboxes
        ?>
        <style>
            label[for="_virtual"], label[for="_downloadable"]{ opacity: 0.2 !important; /* opacity: 0; */ }
        </style>
        <?php

        ## JQUERY SCRIPT ##
        // Here we set as selected the 'virtual' and 'downloadable' checkboxes
        ?>

        <script>
            (function($){
                $('input[name=_virtual]').prop('checked', true);
                $('input[name=_downloadable]').prop('checked', true);
            })(jQuery);
        </script>

        <?php
    }

}

This in my function, child theme. I found this code from: https://stackoverflow.com/a/42177288/6574214. But this code only work for backend only, i want on dokan frontend upload form. Anyone know the code? I want comment on https://stackoverflow.com/a/42177288/6574214 but i not have reputation for that... :(

4

1 回答 1

0

我找到了解决方案。

背景:我们正在开发一个供应商只能销售数字产品的网站。所以我们遇到了这个问题,因为我们需要隐藏选项并保持可下载和虚拟启用。

这是您可以使用的代码:

您使用的上述代码适用于 woocommerce 后端,但要使其在前端工作,您需要使用此挂钩:dokan_product_edit_after_options。

参考:https ://wedevs.com/docs/dokan/developer-documentation/seller-dashboard-action-hooks/

解决方案 :

add_action( 'dokan_product_edit_after_options', 'pitby_dokan_preselect' );
function pitby_dokan_preselect(){
    ?>
    <style>
        label[for="_virtual"], label[for="_downloadable"]{ opacity: 0; }
    </style>
    <?php
    
    ?>
    <script>
        (function($){
            $('input[name=_virtual]').prop('checked', true);
            $('input[name=_downloadable]').prop('checked', true);
        })(jQuery);
    </script>
    <?php
}

谢谢和问候,Vamsi。

于 2021-01-08T07:55:24.143 回答