Adding PayPal buttons to K2

March 26, 2010

How may PayPal best be integrated with the excellent K2 content construction component? To my knowledge, there is not, as I write this, a Joomla! plugin available that allows PayPal buttons to be added to K2 content items. Here are a few possible solutions:

Solution 1: Add a PayPal extra field
This is the most obvious fix: simply add an extra field of type textarea in the K2 administrator backend. This may then be filled for each product item with the appropriate PayPal button code. But K2 strips out from these extra fields the PayPal form code. So to get this solution working you would have to hack K2 to stop the tag stripping. Not a nice solution.

Solution 2: Add PayPal code to each product description
Just add PayPal button code at the bottom of each K2 product description (within the content tab of the K2 item editor). Easy, right? The problem is that WYSIWYG editors tend to mutilate that code. So you’ll lose PayPal buttons whenever a user edits K2 products using a WYSIWYG editor.

Solution 3: Add PayPal code within separate modules
This is a possibility if each of your K2 products is a separate item in one of your menus. You may then create a custom HTML module for each product and add into those modules the PayPal button code suitable to each product. Assign each module to the appropriate product menu item and you’re done: navigating to a product via that menu will show the product alongside its PayPal button. But if anyone navigates to your K2 product other than via that menu (e.g. via the search module), they won’t see the associated PayPal module. Hardly a perfect solution.

Solution 4: Embed PayPal code as a video item
Click on the video tab when editing a K2 item and you’ll see a sub-tab titled “Use video embed code”. Add your PayPal button code there and it won’t get stripped out. You’ll need to play around with the CSS in order to get things looking good (you can remove the “Video” heading using .itemVideoBlock h3{display: none;}), but this seems to me to be a fairly good solution, most particularly if you don’t embed videos into your K2 product pages. You can see this solution implemented at Peter's Safety Solutions, a motorcycle safety equipment site to which I recently added PayPal buttons.