Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'wcfm_is_allow_pm_add_products', function( $is_allow ) {
- global $wp;
- if ( $is_allow && function_exists( 'wcfm_is_vendor' ) && wcfm_is_vendor() ) {
- $vendor_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
- if(check_profile_completeness_percent($vendor_id) < 100) {
- $is_allow = false;
- if ( isset( $wp->query_vars['wcfm-products-manage'] ) ) {
- wcfm_restriction_message_show( __( "You'll need to complete your store setup before adding new products!", "wc-fronend-manager" ), false, true );
- }
- }
- }
- return $is_allow;
- }, 60 );
- function check_profile_completeness_percent($user_id) {
- $vendor_data = get_user_meta($user_id, 'wcfmmp_profile_settings', true);
- $profile_complete_components = apply_filters('vendor_profile_complete_components', array(
- 'banner' => 'wcfm_profile_componenet_banner',
- 'gravatar' => 'wcfm_profile_componenet_logo',
- 'store_name' => 'wcfm_profile_componenet_name',
- 'phone' => 'wcfm_profile_componenet_phone',
- 'about' => 'wcfm_profile_componenet_description',
- 'address' => 'wcfm_profile_componenet_address',
- 'location' => 'wcfm_profile_componenet_location',
- 'payment' => 'wcfm_profile_componenet_payment',
- 'policy' => 'wcfm_profile_componenet_policy',
- 'support' => 'wcfm_profile_componenet_support',
- 'seo' => 'wcfm_profile_componenet_vseo',
- 'shipping' => 'wcfm_profile_componenet_vshipping'
- ));
- $component = $completed = 0;
- foreach($profile_complete_components as $componenet => $callback) {
- if(is_callable($callback)) {
- $result = call_user_func($callback, $user_id, $vendor_data);
- if( $result !== -1 ) {
- $component++;
- $completed += $result;
- }
- }
- }
- return ($completed / $component) * 100;
- }
- function wcfm_profile_componenet_banner($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_store_banner', true )) {
- if(isset( $vendor_data['banner'] ) && absint( $vendor_data['banner'] )) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_logo($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_store_logo', true )) {
- if(isset( $vendor_data['gravatar'] ) && absint( $vendor_data['gravatar'] )) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_name($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_store_name', true )) {
- if(isset( $vendor_data['store_name'] ) && esc_attr( $vendor_data['store_name'] )) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_phone($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_store_phone', true )) {
- if(isset( $vendor_data['phone'] ) && !is_array( $vendor_data['phone'] ) && esc_attr( $vendor_data['phone'] )) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_description($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_store_description', true )) {
- if(wcfm_get_user_meta( $user_id, '_store_description', true )) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_address($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_store_address', true )) {
- $street_1 = isset( $vendor_data['address']['street_1'] ) ? $vendor_data['address']['street_1'] : '';
- $country = isset( $vendor_data['address']['country'] ) ? $vendor_data['address']['country'] : '';
- if($street_1 && $country) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_location($user_id, $vendor_data) {
- global $WCFMmp;
- if(apply_filters( 'wcfm_is_allow_store_address', true ) && apply_filters( 'wcfm_is_allow_store_map_location', true )) {
- $api_key = isset( $WCFMmp->wcfmmp_marketplace_options['wcfm_google_map_api'] ) ? $WCFMmp->wcfmmp_marketplace_options['wcfm_google_map_api'] : '';
- $wcfm_map_lib = isset( $WCFMmp->wcfmmp_marketplace_options['wcfm_map_lib'] ) ? $WCFMmp->wcfmmp_marketplace_options['wcfm_map_lib'] : '';
- if( !$wcfm_map_lib && $api_key ) {
- $wcfm_map_lib = 'google';
- } elseif( !$wcfm_map_lib && !$api_key ) {
- $wcfm_map_lib = 'leaftlet';
- }
- if( ( ( $wcfm_map_lib == 'google' && !empty( $api_key ) ) || $wcfm_map_lib == 'leaflet' ) &&
- isset( $vendor_data['store_location'] ) && esc_attr( $vendor_data['store_location'] )
- ) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_payment($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_pref_withdrawal', true ) && apply_filters( 'wcfm_is_allow_billing_settings', true )) {
- $payment_mode = isset( $vendor_data['payment']['method'] ) ? esc_attr( $vendor_data['payment']['method'] ) : '' ;
- $paypal = isset( $vendor_data['payment']['paypal']['email'] ) ? esc_attr( $vendor_data['payment']['paypal']['email'] ) : '' ;
- $skrill = isset( $vendor_data['payment']['skrill']['email'] ) ? esc_attr( $vendor_data['payment']['skrill']['email'] ) : '' ;
- $ac_number = isset( $vendor_data['payment']['bank']['ac_number'] ) ? esc_attr( $vendor_data['payment']['bank']['ac_number'] ) : '';
- if( $payment_mode && ( $paypal || $skrill || $ac_number || $payment_mode == 'stripe' || $payment_mode == 'by_cash' ) ) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_policy($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_pref_policies', true ) && apply_filters( 'wcfm_is_allow_policy_settings', true )) {
- $wcfm_policy_vendor_options = (array) get_user_meta( $user_id, 'wcfm_policy_vendor_options', true );
- $_wcfm_vendor_policy_tab_title = isset( $wcfm_policy_vendor_options['policy_tab_title'] ) ? $wcfm_policy_vendor_options['policy_tab_title'] : '';
- $_wcfm_vendor_shipping_policy = isset( $wcfm_policy_vendor_options['shipping_policy'] ) ? $wcfm_policy_vendor_options['shipping_policy'] : '';
- $_wcfm_vendor_refund_policy = isset( $wcfm_policy_vendor_options['refund_policy'] ) ? $wcfm_policy_vendor_options['refund_policy'] : '';
- $_wcfm_vendor_cancellation_policy = isset( $wcfm_policy_vendor_options['cancellation_policy'] ) ? $wcfm_policy_vendor_options['cancellation_policy'] : '';
- if( $_wcfm_vendor_policy_tab_title && $_wcfm_vendor_shipping_policy && $_wcfm_vendor_refund_policy && $_wcfm_vendor_cancellation_policy ) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_support($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_customer_support_settings', true ) && apply_filters( 'wcfm_is_allow_customer_support', true )) {
- $vendor_customer_phone = isset( $vendor_data['customer_support']['phone'] ) ? $vendor_data['customer_support']['phone'] : '';
- $vendor_customer_email = isset( $vendor_data['customer_support']['email'] ) ? $vendor_data['customer_support']['email'] : '';
- $vendor_csd_return_address1 = isset( $vendor_data['customer_support']['address1'] ) ? $vendor_data['customer_support']['address1'] : '';
- $vendor_csd_return_country = isset( $vendor_data['customer_support']['country'] ) ? $vendor_data['customer_support']['country'] : '';
- if( $vendor_customer_phone && $vendor_customer_email && $vendor_csd_return_address1 && $vendor_csd_return_country ) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_vseo($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_vseo_settings', true )) {
- $wcfmmp_seo_meta_title = isset( $vendor_data['store_seo']['wcfmmp-seo-meta-title'] ) ? $vendor_data['store_seo']['wcfmmp-seo-meta-title'] : '';
- $wcfmmp_seo_meta_desc = isset( $vendor_data['store_seo']['wcfmmp-seo-meta-desc'] ) ? $vendor_data['store_seo']['wcfmmp-seo-meta-desc'] : '';
- $wcfmmp_seo_meta_keywords = isset( $vendor_data['store_seo']['wcfmmp-seo-meta-keywords'] ) ? $vendor_data['store_seo']['wcfmmp-seo-meta-keywords'] : '';
- if( $wcfmmp_seo_meta_title && $wcfmmp_seo_meta_desc && $wcfmmp_seo_meta_keywords ) {
- return 1;
- }
- return 0;
- }
- return -1;
- }
- function wcfm_profile_componenet_vshipping($user_id, $vendor_data) {
- if(apply_filters( 'wcfm_is_allow_shipping', true ) && apply_filters( 'wcfm_is_allow_vshipping_settings', true )) {
- return 1;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement