About Club osCommerce

Showcasing osCommerce…the good, the bad and the ugly!

Follow osc_pro on Twitter

Facebook "LIKE" on your osCommerce shop

Written By Gary on Apr 28 2010 · Comments (6) Follow osc_pro on Twitter

Jan asks;

possible to put the new like button on osc

Yep, and it's super simple, using this quick and dirty code.

Step 1: Add this code to your header, footer, or wherever you want the like button to show;

PHP:
  1. <fb:like
  2.       href="<?php echo HTTP_SERVER . $_SERVER['REQUEST_URI']; ?>"
  3.       layout="standard"
  4.       show_faces="true"
  5.       width="<?php echo BOX_WIDTH-30; ?>"
  6.       action="like"
  7.       font="trebuchet ms"
  8.       colorscheme="light"></fb:like>

Step 2: Get yourself an Application ID from here.

Step 3: Add this code to the bottom of either /includes/footer.php (pre rc3) or includes/template_bottom.php (rc3), making sure to substitute "your app id" with your actual app id;

PHP:
  1. <div id="fb-root"></div>
  2. <script src="http://connect.facebook.net/en_US/all.js"></script>
  3. <script>
  4.   FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
  5.   FB.Event.subscribe('auth.sessionChange', function(response) {
  6.     if (response.session) {
  7.       // A user has logged in, and a new cookie has been saved
  8.     } else {
  9.       // The user has logged out, and the cookie has been cleared
  10.     }
  11.   });
  12. </script>

Done.

Code needs to be cleaned up for real use, but this should give you enough of an idea to be able to do what you need to do.


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive - and you get a link from my homepage to your site. Cheers!


6 Comments

  1. This code works great other than one thing. It doesn't show up when used in IE. Works fine in Chrome though. Any thoughts?

    Comment by Jason — April 29, 2010 @ 11:14 pm


  2. Please make sure to attribute my posts with a working URL. Thanks ;)

    IE requires the js code to be placed the opposite way around. IE, instead of in the footer, hav e it in the header.

    Comment by Gary — May 4, 2010 @ 2:18 pm


  3. Strange…I tried that already and still for some reason it doesnt show up but I did notice that it causes IE to give an error regarding a runtime error when that code is placed in the header.

    Comment by Jason — May 4, 2010 @ 2:32 pm


  4. Danke – funktioniert wunderbar

    Comment by mKd — April 7, 2011 @ 8:56 am


  5. so very confused just got my OsC site in August I just don't know WHERE the facebook code goes how do I get to the header is it in the index.php? Do I have to have a special program to open this? I am really a newbie would appreciate any guidance I have been searching in the forums and online and I am just as confused as ever.

    Comment by Diana — November 5, 2011 @ 3:50 am


  6. 1 page in oscommerce can be made of many files. Take the example of "product_info.php";

    includes/template_top.php
    includes/header.php
    product_info.php
    includes/footer.php
    includes/template_bottom.php
    a language file
    any other files that these call
    images
    javascript files
    and more

    Suggest that you need to get straight in your mind how oscommerce hangs together. In general, header edits are done in template_top or header.php

    Any type of text editor will do, eg notepad, ultra-edit. Do NOT use any type os wysiwyg editor such as dreamweaver or frontpage.

    Comment by Gary — November 7, 2011 @ 11:11 pm


Leave a comment

RSS feed for comments on this post

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!