Reputation: 141
Well, the problem is here. I created a local project to create a product in Woocommerce mounted in wordpress on a remote server. My local project code is this one
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
function creaProd(){
$precio = $_POST['Total'];
$imagen = $_POST['Imagen'];
$descrip = $_POST['Descripcion'];
$tipo = $_POST['Tipo'];
$woocommerce = new Client(
'http://example.com',
'ck_sdfsdfsdfsfdxxx',
'cs_sdfsdfsfsdfaxxx',
[
'wp_api' => true,
'version' => 'wc/v1',
]
);
$data = [
'name' => $tipo,
'type' => 'simple',
'regular_price' => $precio,
'description' => $descrip,
'short_description' => $descrip,
'categories' => [
[
'id' => 9
],
[
'id' => 14
]
],
'images' => [
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
'position' => 0
],
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
'position' => 1
]
]
];
print_r($woocommerce->post('products', $data));
}
creaProd();
And evertything works fine, the problem is, that I have tried a bunch of things, but I just don't get to create the product working in the wordpress project.
I put it in the wp-includes folder and the wp-content, but didn't work.
I tried to call an ajax to example.com/wp-includes/myFile.php
but I can't reach it, I can reach files like example.com/wp-includes/option.php
and all the files already there, but if I upload that one, I just can't, and I don't know where to put the vendor folder either.
Which is the right way to integrate this project to my real site in Wordpress?
Hope someone knows how to do this. Thanks.
Upvotes: 0
Views: 879
Reputation: 11
[Note to reviewer I am the same person as user 8256950. When I tried to create a login for 8256950 it create a new login 8262086 instead. Don't know why but I do destroy all cookies daily.]
Your project is a REST client which is usually run from a different server. It is not part of the WordPress server and I would put its files in its own directory. It is not a plugin. It is also not AJAX. (No JavaScript is used in the REST client to REST server communication but of course the client can be invoked by Javascript.)
Concerning your specific problem reaching files it would be helpful if you provided the Network log from your browser. On Chrome 'More tools' -> 'Developer tools' -> 'Network'. Look for the request for you file and see if there is an error message.
Upvotes: 1
Reputation: 178
I think the best way to integrate third party libraries into Wordpress is creating your own plugins (This for me is the best option, cause you can use other API Wordpress even security stuff like if a user is login or have the right permissions). they are simple to create and they can be enabled through the Wordpress dashboard admin.
Here is some post about it:
How to create plugin - Wordpress Documentation
in this article you can find how to write a plugin in Wordpress from the official documentation
Upvotes: 2