admin管理员组

文章数量:1134588

I wrote WC plugin (Integration). I want to create in my plugin a file with the following content:

require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
$WC_Some_Integration->simple_redirect($_POST);

And send POST requests to this file. But I don't know, how I can get instance of my integration, in other words, I don't know what I must will wrote instead WC_Some_Integration (what to assign to this variable).

Tell me, pls, how do I do the above? Or is it the only way out to use static methods (functions)? It does not suit me too much.

I wrote WC plugin (Integration). I want to create in my plugin a file with the following content:

require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
$WC_Some_Integration->simple_redirect($_POST);

And send POST requests to this file. But I don't know, how I can get instance of my integration, in other words, I don't know what I must will wrote instead WC_Some_Integration (what to assign to this variable).

Tell me, pls, how do I do the above? Or is it the only way out to use static methods (functions)? It does not suit me too much.

Share Improve this question asked Jul 25, 2017 at 9:18 Stanislav BelichenkoStanislav Belichenko 1951 silver badge9 bronze badges 4
  • 1 Is this for AJAX? The correct way to handle AJAX in WordPress is to send request to the admin-ajax.php file, and hook your code into it. Read more here. – Jacob Peattie Commented Jul 25, 2017 at 9:47
  • @JacobPeattie I know about, thx, but this is for action attrribute in the <form></form>. – Stanislav Belichenko Commented Jul 25, 2017 at 9:51
  • You can just POST to the homepage, and then add a hook to template_redirect. In your callback, check the $_POST variable for your form's field. If it exists, do your thing, otherwise do nothing. – Jacob Peattie Commented Jul 25, 2017 at 10:02
  • @JacobPeattie sorry man, but I'm not interested in all the options for processing requests from forms or anythere else. I'm wondering how I can get a instance of the integration object. – Stanislav Belichenko Commented Jul 25, 2017 at 10:08
Add a comment  | 

1 Answer 1

Reset to default 0

You can get the integration instance using the integrations object from the global WooCommerce object:

WC()->integrations->integrations['id-of-the-integration']

where 'id-of-the-integration' is the $id field of the integration class, like 'maxmind_geolocation'.

With WC() you can get most collections of instances attached to WooCommerce.

本文标签: How to get woocommerce integration instance