Advertisement
palsushobhan

affiliate-link-copier-on-product-page

Apr 21st, 2022
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. add_action( 'woocommerce_single_product_summary', function () {
  2.     global $product;
  3.     if (wcfm_is_affiliate()) {
  4.         if (method_exists($product, 'get_id')) {
  5.             $product_id = $product->get_id();
  6.             $affiliate_id = get_current_user_id();
  7.             $affiliate_url = wcfm_get_affiliate_url($affiliate_id, get_permalink($product_id));
  8.         ?>
  9.         <div class="wcfm-clearfix"></div>
  10.         <div class="store_info_parallal" style="margin-right: 10px; margin-bottom: 10px;">
  11.             <i class="wcfmfa fa-link fa-xs" aria-hidden="true"></i>
  12.             <span class="afcode" data-aurl="<?php echo $affiliate_url; ?>"><b>1% ortaqlı məhsul</b>&nbsp;&nbsp;<i style="color:#8802ff;cursor:pointer;" title="Sıxaraq Kopyala və Paylaş" class="fas fa-share-alt"></i></span>
  13.         </div>
  14.         <div class="wcfm-clearfix"></div>
  15.         <script>
  16.             jQuery(document).ready(function($) {
  17.                 $("span.afcode").on("click", function(e) {
  18.                     e.preventDefault();
  19.                     var $temp = $("<input>");
  20.                     $("body").append($temp);
  21.                     $temp.val($(this).data("aurl")).select();
  22.                     document.execCommand("copy");
  23.                     $temp.remove();
  24.                     alert("Product affiliate url copied!");
  25.                 });
  26.             });
  27.         </script>
  28.         <?php
  29.         }
  30.     }
  31. }, 6 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement