palsushobhan

Vendor Phone Elementor specific

Jun 3rd, 2021 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action('wcfm_after_product_catalog_enquiry_button', function() {
  2.     global $product;
  3.     if( is_product() && $product && method_exists( $product, 'get_id' ) ) {
  4.         $product_id = $product->get_id();
  5.         $store_id = wcfm_get_vendor_id_by_post( $product_id );
  6.         $store_user = wcfmmp_get_store( $store_id );
  7.         $store_info = $store_user->get_shop_info();
  8.         $phone = $store_user->get_phone();
  9.         if( $phone && ( $store_info['store_hide_phone'] == 'no' ) && wcfm_vendor_has_capability( $store_user->get_id(), 'vendor_phone' ) ) {
  10.             echo "<a href='tel:{$phone}' class='wcfm_vendor_phone wcfm_chat_now_button' data-number='{$phone}'><span class='wcfmfa fa-phone'></span>&nbsp;&nbsp;<span class='add_enquiry_label'>Call Dispensary</span></a>";
  11.         }
  12.     }
  13. });
  14.  
  15. add_action( 'wcfmmp_store_after_follow_me', function($store_id) {
  16.     echo do_shortcode("[wcfmmp_vendor_phone id='{$store_id}']");
  17. });
  18.  
  19. add_shortcode('wcfmmp_vendor_phone', function($attr) {
  20.     global $post, $WCFM;
  21.     $vendor_id = '';
  22.     if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) {
  23.         $vendor_id = absint($attr['id']);
  24.     }elseif (  wcfm_is_store_page() ) {
  25.         $wcfm_store_url = get_option( 'wcfm_store_url', 'store' );
  26.         $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
  27.         if ( !empty( $store_name ) ) {
  28.             $store_user = get_user_by( 'slug', $store_name );
  29.             $vendor_id = $store_user->ID;
  30.         }
  31.     }elseif( is_product() ) {
  32.         $vendor_id = $post->post_author;
  33.     }
  34.     if( !$vendor_id && is_single() && $post && is_object( $post ) && wcfm_is_vendor( $post->post_author ) ) {
  35.         $vendor_id = $post->post_author;
  36.     }
  37.     if(!$vendor_id) return;
  38.     $store_user = wcfmmp_get_store( $vendor_id );
  39.     $phone = $WCFM->wcfm_vendor_support->wcfm_vendor_has_capability( $vendor_id, 'vendor_phone' ) ? $store_user->get_phone() : '';
  40.     if($phone) {
  41.         ?>
  42.         <style>
  43.         #wcfmmp-store-phone-wrapper {
  44.             text-align: center;
  45.         }
  46.         #wcfmmp-store-phone-wrapper .elementor-button {
  47.             font-size: 24px;
  48.             background-color: #46BBFF;
  49.             border-radius: 10px 10px 10px 10px;
  50.         }
  51.         #wcfmmp-store-phone-wrapper .elementor-button:hover,
  52.         #wcfmmp-store-phone-wrapper .elementor-button:focus {
  53.             background-color: #FFA600;
  54.         }
  55.         </style>
  56.         <div id="wcfmmp-store-phone-wrapper" class="elementor-button-wrapper">
  57.             <a class="elementor-button elementor-size-sm" title="<?php _e( 'Phone', 'wc-frontend-manager-ultimate' ); ?>" href="<?php echo "tel:{$phone}"; ?>">
  58.                 <span class="elementor-button-content-wrapper">
  59.                     <span class="elementor-button-icon elementor-align-icon-left">
  60.                         <i aria-hidden="true" class="fas fa-phone-square"></i>         
  61.                     </span>
  62.                     <span class="elementor-button-text">Call Dispensary</span>
  63.                 </span>
  64.             </a>
  65.         </div>
  66.         <?php
  67.     }
  68. });
Add Comment
Please, Sign In to add comment