plugins - Woocommerce functions in custom class, avoid errors

How do I call Woocommerce functions in a custom class?I have the following class method which is getting called on a cro

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

相关推荐

  • plugins - Woocommerce functions in custom class, avoid errors

    How do I call Woocommerce functions in a custom class?I have the following class method which is getting called on a cro

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信