Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bug fix for reviews.co.uk Woocommerce plugin, when WPLister integrated - products from eBay sales may not contain a sku, as they're not products from WooCommerce - this resolves that issue
public function processCompletedOrder($order_id)
{
update_post_meta($order_id, '_reviewscouk_status', 'processed');
$api_url = $this->getApiDomain();
$order = new WC_Order($order_id);
$items = $order->get_items();
$p = array();
foreach ($items as $row) {
$productmeta = wc_get_product($row['product_id']);
if ( ! $productmeta ) {
continue;
}
if(isset($productmeta)){
$sku = get_option('product_identifier') == 'id' ? $row['product_id'] : $productmeta->get_sku();
if ($productmeta->get_type() == 'variable' && get_option('use_parent_product') != 1) {
$available_variations = $productmeta->get_available_variations();
foreach ($available_variations as $variation) {
if ($variation['variation_id'] == $row['variation_id']) {
$sku = get_option('product_identifier') == 'id' ? $variation['variation_id'] : $variation['sku'];
}
}
}
$url = get_permalink($row['product_id']);
$attachment_url = wp_get_attachment_url(get_post_thumbnail_id($row['product_id']));
if (!(get_option('disable_reviews_per_product') == '1' && $productmeta->post->comment_status == 'closed')) {
$p[] = array(
'sku' => $sku,
'name' => $row['name'],
'image' => $attachment_url,
'pageUrl' => $url,
);
}
}
}
$country_code = 'GB';
if (isset($order->get_address()['country'])) {
$country_code = $order->get_address()['country'];
}
$data = array(
'order_id' => $order->get_order_number(),
'email' => $order->get_billing_email(),
'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
'source' => 'woocom',
'products' => $p,
'country_code' => $country_code,
);
if (get_option('api_key') != '' && get_option('store_id') != '' && get_option('send_product_review_invitation') == '1' && count($data['products']) > 0) {
$this->apiPost('product/invitation', $data);
}
if (get_option('api_key') != '' && get_option('store_id') != '' && get_option('send_merchant_review_invitation') == '1') {
$this->apiPost('merchant/invitation', $data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment