Last active
December 4, 2020 11:51
-
-
Save outrank-james/a8d2151e538c22bd8f8890b91a328687 to your computer and use it in GitHub Desktop.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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