How do I call Woocommerce functions in a custom class?
I have the following class method which is getting called on a cron job action
here is the code which fires my cron action
register_activation_hook(__FILE__, array('Ratings\Admin\MailJobs', 'activateMailJobs'));
and here is the hole class
namespace Ratings\Admin;
use Ratings\Email\CronMails as Mailer;
/**
* Class MailJobs
* @package Ratings\Admin
*/
class MailJobs
{
private $options;
/**
* MailJobs constructor.
*/
public function __construct()
{
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('ausg_daily_event', array($this, 'dailyAusgMails'));
$this->dailyAusgMails();
}
}
public function init()
{
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('ausg_daily_event', array($this, 'dailyAusgMails'));
}
}
/**
* activate Mail CronJobs
*/
public function activateMailJobs()
{
if (!wp_next_scheduled( 'ausg_daily_event')) {
wp_schedule_event(strtotime('23:59:00'), 'daily', 'ausg_daily_event');
}
}
/**
* deactivate Mail CronJobs
*/
protected function deactivateMailJobs()
{
wp_clear_scheduled_hook('ausg_daily_event');
}
/**
* send Mails on CronJob
*/
protected function dailyAusgMails()
{
add_action( 'woocommerce_after_register_post_type', array($this, 'getPaidOrders') );
}
/**
* @return \stdClass|\WC_Order[]
*/
public function getPaidOrders()
{
/**
* $orders = $this->getPaidOrders();
var_dump($orders);
die;
if($orders) {
foreach ($orders as $order) {
Mailer::send();
}
}
*/
$targetDate = strtotime('-3 days');
$targetDateObject = date('Y-m-d', $targetDate);
$args = array(
'limit' => -1,
'status' => array( 'wc-completed' ),
'type' => array( 'shop_order' ),
//'date_paid' => $targetDateObject . '...' . $targetDateObject
);
$orders = wc_get_orders( $args );
//var_dump(count($orders));
//wp_die();
return $orders;
}
}
which fails with the following error Fatal error: Uncaught Error: Call to undefined function Ratings\Admin\wc_get_orders() ...
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745353502a4623980.html
评论列表(0条)