• Resolved James

    (@outrankjames)


    Hi All,

    There is an issue with compatibility with 3rd party plugin such as WPLister (eBay/Amazon), where as orders placed via these do not link directly to a product, so the following code crashes when completing an order

    foreach ($items as $row) {
                    $productmeta = wc_get_product($row['product_id']);
                    $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'];
                            }
                        }
                    }

    Basically you would need to add some error checking into $productmeta to make sure that a product is found before proceeding – i.e.

    foreach ($items as $row) {
                    $productmeta = wc_get_product($row['product_id']);
                    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,
                            );
                        }
                    }
                }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter James

    (@outrankjames)

    Latest update and this error check has not been entered into the code.

    Added within woocommerce-reviews.php (after line 323)

    `if(isset($productmeta)){

    Closing } on line 348

    Thread Starter James

    (@outrankjames)

    Update fix for this one

    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);
                }
            }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Issue With Plugin with WP Lister’ is closed to new replies.