'publish', 'limit' => 500, 'orderby' => 'date', 'order' => 'DESC')); foreach ($products as $p) { $regular = $p->is_type('variable') ? $p->get_variation_regular_price('min') : $p->get_regular_price(); if ($regular === '' || $regular === null) { $regular = $p->get_price(); } if ($regular === '' || $regular === null) { continue; } $price = wc_get_price_including_tax($p, array('price' => (float) $regular)); $image = $p->get_image_id() ? wp_get_attachment_image_url($p->get_image_id(), 'large') : ''; $row = array( 'id' => (string) $p->get_id(), 'title' => wp_strip_all_tags($p->get_name()), 'price' => Adly_Shop_Api::money($price), 'url' => get_permalink($p->get_id()), 'in_stock' => $p->is_in_stock(), ); if ($image && strpos($image, 'https://') === 0) { $row['image_url'] = $image; } if ($p->is_on_sale() && $p->get_sale_price() !== '' && !$p->is_type('variable')) { // What the buyer pays now, and the regular price as the one crossed out $row['compare_at_price'] = $row['price']; $row['price'] = Adly_Shop_Api::money(wc_get_price_including_tax($p, array('price' => (float) $p->get_sale_price()))); } $rows[] = $row; } return $rows; } public static function sync() { if (!Adly_Shop_Settings::connected()) { return array('ok' => false); } $res = Adly_Shop_Api::post('/products', array('products' => self::rows()), 'secret', 30); if ($res['ok']) { Adly_Shop_Settings::merge(array('products_at' => time(), 'products_count' => isset($res['body']['count']) ? (int) $res['body']['count'] : 0)); } return $res; } }