I’m going to use Google books embedded viewer in my website which runs using WordPress CMS and Woocommerce plugin.
My idea is that one Woocommerce attribute for each product (here a book) be assigned to relevant book Google books ID (something like 0738531367), then using a method, this string be inserted to viewer script which simplest form of it follows,
<script type="text/javascript" src="http://books.google.com/books/previewlib.js"></script>
<script type="text/javascript">
GBS_insertEmbeddedViewer('4rghAwAAQBAJ',600,500);
</script>
Now, how can I extract this string (attribute) from Woocommerce and put it in the viewer script?
More Specific Explanation
This is a book page (a WooCommerce product page).
The book this page offers, has been given an attribute with the value of Google Books ID. It can be found at the lowest row of “٠شخصات کتاب” tab.
After inserting this ID into the above code and putting the whole modified code in book page HTML code, the famous Google Books Embedded Viewer corresponding to this book, appeared in the “تÙضÛØ Ùاشر” tab.
But this process is time-consuming and practically impossible when I’m faced with huge number of books to be added.
It is quite simple to embed the Viewer code in the WooCommerce (or theme) TEMPLATE page ONCE. So, for each books the only effort is to defining the so-called book ID in an predefined attribute.
After all, one task remains: transferring this ID to the Viewer code. I think it can be handled using a WordPress hook, php function or the like. Unfortunately searching the net yielded no results (including Google Books Support Forum and WordPress support directory).
It’s possible to integrate into WC product meta box (also, see docs), but I’ll show how to do it with a normal meta box.
Then, in your template, just retrieve the meta data: