Advertisement
palsushobhan

wcfm-vendor-registration-custom-field-shortcode

Nov 26th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. add_shortcode('wcfm_vendor_registration_custom_field', function ($attr) {
  2. global $post;
  3.  
  4. $custom_field_label = $attr['label'] ?? '';
  5. if(!$custom_field_label) return;
  6.  
  7. $store_id = '';
  8. if ( isset( $attr['id'] ) && ! empty( $attr['id'] ) ) {
  9. $store_id = absint( $attr['id'] );
  10. }
  11. if ( wcfm_is_store_page() ) {
  12. $wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
  13. $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
  14. $store_id = 0;
  15. if ( ! empty( $store_name ) ) {
  16. $store_user = get_user_by( 'slug', $store_name );
  17. $store_id = $store_user->ID;
  18. }
  19. }
  20. if ( is_product() ) {
  21. $store_id = $post->post_author;
  22. }
  23. if( !$store_id ) return;
  24.  
  25. $wcfmmp_addition_info_fields = wcfm_get_option('wcfmvm_registration_custom_fields', array());
  26. if (empty($wcfmmp_addition_info_fields)) return;
  27.  
  28. $wcfmvm_custom_infos = (array) get_user_meta($store_id, 'wcfmvm_custom_infos', true);
  29. $field_value = '';
  30. foreach ($wcfmmp_addition_info_fields as $wcfmvm_registration_custom_field) {
  31. if (!isset($wcfmvm_registration_custom_field['enable'])) continue;
  32. if (!$wcfmvm_registration_custom_field['label']) continue;
  33. if ($wcfmvm_registration_custom_field['label'] !== $custom_field_label) continue;
  34. $field_name = sanitize_title($wcfmvm_registration_custom_field['label']);
  35. $field_value = isset($wcfmvm_custom_infos[$field_name]) ? $wcfmvm_custom_infos[$field_name] : '';
  36. break;
  37. }
  38. if ($field_value) {
  39. ?>
  40. <div class="store_info_parallal wcfmmp_store_header_custom">
  41. <p><?php echo $custom_field_label; ?>: <span><?php echo $field_value; ?></span></p>
  42. </div>
  43. <?php
  44. }
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement