using woocommerce api locally - wordpress

I'm creating a wordpress plugin that communicates with woocommerce installed on the same wordpress site. I noticed that the rest api requires ssl to use, but it seems like ssl locally is not possible and oauth is a pain in the ass.
Is there a way to develop for woocommerce locally without having ssl that doesn't use oauth?

I would recommend beginning by throwing out the idea of calling back to a local site over any HTTP/S protocol. That is almost never the right decision.
Instead, woocommerce has extended the WordPress hook/filter system into themselves: https://docs.woocommerce.com/document/introduction-to-hooks-actions-and-filters/. This allows you to inject/extend yourself throughout woocommerce without making a cludgy callback system. I don't know what you want/need to do, but I can guarantee the hooks should probably get you all the functionality you will need.
If you truly do need to make API calls back. You basically won't be able to develop locally (without a lot of effort setting up a local server environment). Instead set up a development environment on a separate server.
I assumed this is a mostly php plugin running on the server. If instead this will be serving a lot of javascript to the frontend, then you will have to use the REST API, and you will have to get some development server up with ssl.
Update: based on comment below expounding on purpose. I assume you figured out to add the 'sales goal' information as post meta to the woocommerce product. Here's a quick introduction to post meta if you need it: https://dsgnwrks.pro/how-to/what-is-post-meta-an-intro-to-wordpress-custom-fields/. This would be the best practice for adding information to the products.
For the proportion of sales to the goal. You will first need a function to get the total sales to date on this product. Here is a gist that hooks into woocommerce_single_product_summary and gets the post_meta total_sales on the current product. You should be able to use a similar scheme to get both total_sales and your sales_goal post meta and then just display the ratio in whatever way you choose.
Note: You may need to attach to a different hook. Or you may even need to get the current product a different way (maybe specified by the widget?) to get ahold of the post_meta.

Related

Separate plugins or one giant plugin on WP

I’m building a WP plugin to enhance a website, and come to an interrogation with the workflow.
Basically, I have to create a custom post type, assorted with several custom taxonomies, which will be used/displayed on the frontend and backend, and create a backend section in order to interact with our CRM, and Supabase via their respective APIs (service centralisation).
All of the second part is only intended to be used/displayed on the admin section, to logged users.
However, when creating/saving a custom post type, or when viewing it from the frontend, I have to make a GET request to the CRM to fetch some data and store it in JSON somewhere (24h cache).
That I can do.
At the moment, I worked on the CPT part, and made a class to interact with the CRM, with credentials stored in wp_options. I now have to work on the backend part.
My question is: what are the best practices here? Keep it in a single plugin or divide into several plugins?
And if I divide, how should I turn it? 2 plugins, one for the CPT and one for the backend? Or go even deeper, and get the CRM and Supabase their own simple plugin, and call their methods to make my requests?
I am short of ideas here, so if you encountered this situation, could you enlighten me?

I'm trying to implement external REST APIs in my wordpress website. Can anybody have idea how to do it (whether with a plugin or with programming)

I tried to use one plugin called "WP Data Sync". I am also going through its documentation/ support for the same. I am also having wpbakery page builder in my website. So is there any way that we sync with that also?
Note - We have to sync data in the form of images, image gallery, events listing, and the blog posts.
Did you check out WP Data Syncs website at https://wpdatasync.com/ and create an account to check out an API key?
I'm not sure about all APIs, but the ones I've used in the past would require me to register with the API's website, get issued an API key and maybe even designate the key to a specific website (your WordPress site in this case) for security reasons. After that, you would then go to your WP site and setup the API there via WP DataSyncs plugin.
I hope I understood your question and that this helps.

Display products from Woocommerce in external application

I have a question about integration e.g. Woocommerce with external app.
What is the best and safe method to accomplish this goal?
Woocommerce has REST API but it might be quite vulnerable and will not show anything (products etc.) to non logged user(which is understandable).
Only safe idea that's comes to my mind is creating scripts inside WordPress and access them via AJAX but I'm worrying about performance of this method.
Maybe there is a right way that I'm not familiar with?
For that purpose, you should create an API from scratch of the wordpress database. wordpress databse has all of you need in a good way and only some php codes needed to create and execute the API. then in you app with AJAX you should access that.
this link may help you:
https://developer.okta.com/blog/2019/03/08/simple-rest-api-php
The right way is likely creating your own API if you don't want to use Woocommence's one. That means you make a plan of what you need to expose, all the routes and start building the API. I warmly recommend the book by Phil Sturgeon - Build APIs you won't hate. The author is also a co-founder of https://phptherightway.com/ so it's quite reputable.

Wordpress XMLRPC advice needed

I have been tasked with creating an API for retrieving and adding content to Wordpress from a flash application and legacy CMS (non-PHP). My plan is to utilise the existing default xmlrpc endpoint and add any additional functionality by creating a plugin which hooks into xmlrpc_methods.
A previous attempt had been made by another developer based on the following code:
http://blog.5ubliminal.com/posts/remote-control-wordpress-blog-xmlrpc-api/
This code looks unwieldy and poorly documented to me and my preference would be to use this approach:
http://kovshenin.com/archives/custom-xml-rpc-methods-in-wordpress/
I would be grateful if anyone with experience in this area could confirm that:
I will be able to distinguish between separate blogs in an MU installation when both retrieving and posting data via XMLRPC
I will be able to retrieve and post to custom fields
writing a plugin is the way to go.
We do not have the option of using Wordpress 3 as it is still in Beta and we are under time pressure.
I would greatly appreciate appreciate any input / advice.
Many thanks,
I've worked with WordPress' XMLRPC system before (using a WP-Hive installation with multiple separate blogs similar to a WPMU set-up). The new approach you're using is definitely simpler and easier to implement (I tried the 5ubliminal one as well the first time).
Whether or not you can distinguish between separate blogs in a MU installation depends entirely on how you build your handler function. You can build it to distinguish the separate blogs, to only function on specific blogs, or to treat the entire system as a single WordPress site. It's all up to you.
By "handler function" I mean a custom function you define to handle XMLRPC requests that call a specific, custom method (not necessarily the default WordPress methods). For example, I use XMLRPC in all my plug-ins to report back installation progress and errors -
each plug-in makes an XMLRPC call to a custom handler (method) on my server.
Yes, you can retrieve and post to custom fields.
Absolutely writing a plug-in is the way to go. The only other options are to change core files (BAD idea) or to build it into your theme, in which case it could ONLY be used on MU sites using that theme. Build it as a site-wide MU plug-in that can be controlled on a site-by-site basis by the global admin.
Wordpress XMLRPC offers various functionalities which can be harvested easily. I have used IXR_Library to parse the XML requests/responses. Currently with very small piece of code i can easily posts, fetch, edit and delete Posts in Wordpress based blogs either self hosted or on wordpress.com sites.
http://www.hurricanesoftwares.com/wordpress-xmlrpc-posting-content-from-outside-wordpress-admin-panel/ (reference)
When you have multiple blogs hosted via MU you will need site ID of all those blogs which will become the first parameter for $params (in our case 0 should be replaced with site_id).
In the reference i gave above you will see the option to fetch and post to all created custom fields (unfortunately, you can't create custom fields on the fly from my script)
You are welcome to write a WP plugin to do all of this, be my guest and let me know if you need my help. I have used the same technique to post to blogger, tumblr, Wordpress and Posterous using their API's. I hope this helps.

Does Wp-Ecommerce works with LinkPoint gateway?

I have an online store working with osCommerce, actually works fine. But there is no integration with the store blog which is in Wordpress fortunatelly.
Now I've seen a new payment plugin for wordpress called Wp-Ecommerce , so i decided to migrate the whole store to wordpress since this can be treated like a CMS.
This plugin has really handy features like Meta Tag properties for each product in order to do SEO position for the store.
I've been reading about wp-ecommerce and searching through the web to find a chance to integrate it with LinkPoint, which is my client's store gateway. I must say this is an imperative requirement I have to do in order to migrate the whole site to Wordpress
Has anybody make this possible ? get wordpress working with LinkPoint ?
Looks like it currently only supports Authorize.Net. You may want to check out Shopp. The Linkpoint plug-in is not free but it is available.

Resources