Advertisement
palsushobhan

wcfm-vendor-tiktok-social-link-support

Jan 25th, 2023 (edited)
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. add_filter('wcfm_profile_fields_social', function($social_fields, $vendor_id) {
  2.     $vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
  3.     $social_accounts = $vendor_data['social'] ?? array();
  4.     $tiktok = $social_accounts['tiktok'] ?? '';
  5.     return array_merge(
  6.         $social_fields,
  7.         array(
  8.             "tiktok" => array(
  9.                 'label' => __('TikTok', 'wc-frontend-manager') ,
  10.                 'type' => 'text',
  11.                 'class' => 'wcfm-text wcfm_ele',
  12.                 'label_class' => 'wcfm_title wcfm_ele',
  13.                 'value' => $tiktok,
  14.                 'placeholder' => __('TikTok Handler', 'wc-frontend-manager')
  15.             )
  16.         )
  17.     );
  18. }, 10, 2);
  19.  
  20. add_filter('wcfm_profile_social_types', function($types) {
  21.     return array_merge(
  22.         $types,
  23.         ['tiktok' => 'tiktok',]
  24.     );
  25. });
  26.  
  27. add_action('wcfmmp_store_after_social', function($vendor_id) {
  28.     ?>
  29.     <style>
  30.         .store-tiktok-logo{
  31.             display: block;
  32.             margin-top: 50%;
  33.             transform: translateY(-50%);
  34.         }
  35.         .store-tiktok-logo svg {
  36.             display: block;
  37.             margin: 0 auto;
  38.             width: 15px;
  39.         }
  40.         .store-tiktok-logo svg path {
  41.             fill: #17a2b8;
  42.         }
  43.     </style>
  44.     <?php
  45.     $store_info = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
  46.     if( isset( $store_info['social']['tiktok'] ) && !empty( $store_info['social']['tiktok'] ) ) { ?>
  47.         <li><a href="<?php echo wcfmmp_generate_social_url( $store_info['social']['tiktok'], 'tiktok' ); ?>" class="store-tiktok-logo" target="_blank">
  48.         <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2859 3333" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd"><path d="M2081 0c55 473 319 755 778 785v532c-266 26-499-61-770-225v995c0 1264-1378 1659-1932 753-356-583-138-1606 1004-1647v561c-87 14-180 36-265 65-254 86-398 247-358 531 77 544 1075 705 992-358V1h551z"></path></svg>
  49.     </a></li>
  50.     <?php }
  51. });
  52.  
  53. add_filter('wcfm_social_url', function($social_handle, $social) {
  54.     if( $social == 'tiktok' && strpos( $social_handle, 'tiktok' ) === false) {
  55.         $social_handle = 'https://tiktok.com/' . $social_handle;
  56.     }
  57.     return $social_handle;
  58. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement