Add Social Media Sharing Buttons Under Shopping Cart

[ad_1]

Hi everyone! I'm hoping someone can please help me with this.

I'm trying to add custom social media buttons under the "add to cart" button in my product pages. The social buttons are currently showing under our" product description". This is the code that I am using:

function add_social_share_buttons($content) {
    // Get the current page URL
    $url = esc_url(get_permalink());

    // Get the current page title
    $title = urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8'));

    // Create an array of social networks and their respective sharing URLs
    $social_networks = array(
        'Facebook' => 'https://www.facebook.com/sharer/sharer.php?u=' . $url,
        'Twitter' => 'https://twitter.com/intent/tweet?url=' . $url . '&text=' . $title,
        'LinkedIn' => 'https://www.linkedin.com/shareArticle?url=' . $url . '&title=' . $title,
        'Pinterest' => 'https://pinterest.com/pin/create/button/?url=' . $url . '&description=' . $title,
    );

    // Initialize the share buttons HTML
    $share_buttons = '<div class="social-share-buttons">';

    // Loop through the social networks and generate the share buttons HTML
    foreach ($social_networks as $network => $share_url) {
        $share_buttons .= '<a href="' . $share_url . '" target="_blank" rel="noopener">' . $network . '</a>';
    }

    // Close the share buttons HTML
    $share_buttons .= '</div>';

    // Append the share buttons HTML to the content
    $content .= $share_buttons;

    return $content;
}

// Add the social share buttons after the content
add_filter('the_content', 'add_social_share_buttons');

Thank you!

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer