Skip to content
Public Ticket #19801

Social sharing modification

Conversation thread

PenciDesign Supporter replied

Staff Reply

Hi,

Unfortunately, this code doesn't work on Product Quickview because this content can't run after the ajax content loading.

We'll consider adding more JS hooks in the future update to make the custom code work after the quick view popup shows.

Regards,
PenciDesign.


Maxivillus replied

Customer Reply

Last question: how to make this code work in section 'quick product view'?

Maxivillus replied

Customer Reply

Finally correct code :)

jQuery(document).ready(function($) {
let sometext = '<a href="' + document.baseURI + '#" title="Copy link to Clipboard" alt="Copy link to Clipboard" class="copy_to_clipboard post-share-item post-share-copy"><i class="penci-faicon fa fa-copy"></i></a>';
$('.single-product-share .list-posts-share').append(sometext);
$(".copy_to_clipboard").click(function(e) {
e.preventDefault();
var copyText = $(this).attr('href');
document.addEventListener('copy', function(e) {
e.clipboardData.setData('text/plain', copyText);
e.preventDefault();
}, true);
document.execCommand('copy');  
   //console.log('copied text : ', copyText);
   //alert('Copied link: ' + copyText);
$(this).hide(600);
$(this).show(600);
});
});

Maxivillus replied

Customer Reply

Correct code for using in codesnippets:

jQuery(document).ready(function($) {
$('.list-posts-share').append('<a href="#" class="copy_to_clipboard post-share-item post-share-copy"><i class="penci-faicon fa fa-copy"></i></a>');
$(".copy_to_clipboard").click(function(e) {
    e.preventDefault();
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(this).attr('href')).select();
    document.execCommand("copy");
    $temp.remove();
    alert("Copied the text ");
});
});

Maxivillus replied

Customer Reply

This code will work on woocommerce products?

PenciDesign Supporter replied

Staff Reply

Hi,

Here is a full code about your request:

<script type="text/javascript">
$('.tags-share-box.center-box .post-share, .tags-share-box.hide-tags.page-share .post-share').append('<a href="#" class="copy_to_clipboard post-share-item post-share-copy"><i class="penci-faicon fa fa-copy"></i></a>');
$(".copy_to_clipboard").click(function(e) {
    e.preventDefault();
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(this).attr('href')).select();
    document.execCommand("copy");
    $temp.remove();
    alert("Copied the text ");
})
</script>

You can paste it at Appearance → Customize → Footer → General → Add Custom HTML code before close </body> tag / Google Analytics Code

Regards,
PenciDesign.



Maxivillus started the conversation

Conversation Start

Is it possible to add to 'Like Posts & Social Sharing' 'Copy to clipboard' feature?

Or may be i can add this feature by below code?

$(".copy_to_clipboard").click(function (e) {
                    e.preventDefault();
                    var $temp = $("<input>");
                    $("body").append($temp);
                    $temp.val($(this).attr('href')).select();
                    document.execCommand("copy");
                    $temp.remove();
                    alert("Copied the text ");
            })

Want to join this conversation or access attachments? Sign in first.