WC_Order::has_downloadable_item PHP Method

has_downloadable_item() public method

Returns true if the order contains a downloadable product.
public has_downloadable_item ( ) : boolean
return boolean
    public function has_downloadable_item()
    {
        foreach ($this->get_items() as $item) {
            if ($item->is_type('line_item') && ($product = $item->get_product()) && $product->is_downloadable() && $product->has_file()) {
                return true;
            }
        }
        return false;
    }

Usage Example

        /**
         * Verify a successful Payment!
         * */
        function check_alphabank_response()
        {
            global $woocommerce;
            global $wpdb;
            //if (( preg_match( '/success/i', $_SERVER['REQUEST_URI'] ) && preg_match( '/alphabank/i', $_SERVER['REQUEST_URI'] ) )) {
            //			$merchantreference= $_GET['MerchantReference'];
            $post_data_array = array();
            if (isset($_POST['mid'])) {
                $post_data_array[0] = $_POST['mid'];
            }
            if (isset($_POST['orderid'])) {
                $post_data_array[1] = $_POST['orderid'];
            }
            if (isset($_POST['status'])) {
                $post_data_array[2] = $_POST['status'];
            }
            if (isset($_POST['orderAmount'])) {
                $post_data_array[3] = $_POST['orderAmount'];
            }
            if (isset($_POST['currency'])) {
                $post_data_array[4] = $_POST['currency'];
            }
            if (isset($_POST['paymentTotal'])) {
                $post_data_array[5] = $_POST['paymentTotal'];
            }
            if (isset($_POST['message'])) {
                $post_data_array[6] = $_POST['message'];
            }
            if (isset($_POST['riskScore'])) {
                $post_data_array[7] = $_POST['riskScore'];
            }
            if (isset($_POST['payMethod'])) {
                $post_data_array[8] = $_POST['payMethod'];
            }
            if (isset($_POST['txId'])) {
                $post_data_array[9] = $_POST['txId'];
            }
            if (isset($_POST['paymentRef'])) {
                $post_data_array[10] = $_POST['paymentRef'];
            }
            $post_data_array[11] = $_POST['digest'];
            $post_DIGEST = $_POST['digest'];
            $post_data = implode("", $post_data_array);
            $digest = base64_encode(sha1(utf8_encode($post_data), true));
            if ($this->mode == "yes") {
                //test mode
                $post_url = 'https://alpha.test.modirum.com/vpos/shophandlermpi';
            } else {
                //live mode
                $post_url = 'https://www.alphaecommerce.gr/vpos/shophandlermpi';
            }
            //
            $ttquery = 'SELECT *
				FROM `' . $wpdb->prefix . 'alphabank_transactions`
				WHERE `orderid` = "' . $_POST['orderid'] . '";';
            $ref = $wpdb->get_results($ttquery);
            $merchantreference = $_GET['MerchantReference'];
            $orderid = $ref['0']->orderid;
            $order = new WC_Order($orderid);
            //$order = $_POST['orderid'];
            if ($_POST['status'] == 'AUTHORIZED' || $_POST['status'] == 'CAPTURED') {
                //verified - successful payment
                //complete order
                if ($order->status == 'processing') {
                    $order->add_order_note(__('Payment Via alphabank<br />Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id);
                    //Add customer order note
                    $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />alphabank Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id, 1);
                    // Reduce stock levels
                    $order->reduce_order_stock();
                    // Empty cart
                    WC()->cart->empty_cart();
                    $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-alphabank-payment-gateway');
                    $message_type = 'success';
                } else {
                    if ($order->has_downloadable_item()) {
                        //Update order status
                        $order->update_status('completed', __('Payment received, your order is now complete.', 'woocommerce-alphabank-payment-gateway'));
                        //Add admin order note
                        $order->add_order_note(__('Payment Via alphabank Payment Gateway<br />Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id);
                        //Add customer order note
                        $order->add_order_note(__('Payment Received.<br />Your order is now complete.<br />alphabank Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id, 1);
                        $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is now complete.', 'woocommerce-alphabank-payment-gateway');
                        $message_type = 'success';
                    } else {
                        //Update order status
                        $order->update_status('processing', __('Payment received, your order is currently being processed.', 'woocommerce-alphabank-payment-gateway'));
                        //Add admin order note
                        $order->add_order_note(__('Payment Via alphabank Payment Gateway<br />Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id);
                        //Add customer order note
                        $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />alphabank Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id, 1);
                        $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-alphabank-payment-gateway');
                        $message_type = 'success';
                    }
                    $alphabank_message = array('message' => $message, 'message_type' => $message_type);
                    update_post_meta($order_id, '_alphabank_message', $alphabank_message);
                    // Reduce stock levels
                    $order->reduce_order_stock();
                    // Empty cart
                    WC()->cart->empty_cart();
                }
            } elseif ($_POST['status'] == 'CANCELED') {
                //payment has failed - retry
                $message = __('Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-alphabank-payment-gateway');
                $message_type = 'error';
                $alphabank_message = array('message' => $message, 'message_type' => $message_type);
                update_post_meta($order_id, '_alphabank_message', $pb_message);
                //Update the order status
                $order->update_status('failed', '');
                $checkout_url = $woocommerce->cart->get_checkout_url();
                wp_redirect($checkout_url);
                exit;
            }
            //			elseif ($_POST['status'] == 'CANCELED')
            //			{//an error occurred
            //						$message = __('Thank you for shopping with us. <br />However, an error occurred and the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-alphabank-payment-gateway');
            //						$message_type = 'error';
            //						$alphabank_message = array(
            //							'message' => $message,
            //							'message_type' => $message_type
            //						);
            //						update_post_meta($order_id, '_alphabank_message', $pb_message);
            //						//Update the order status
            //						$order->update_status('failed', '');
            //						$checkout_url = $woocommerce->cart->get_checkout_url();
            //						wp_redirect($checkout_url);
            //						exit;
            //			}
            //$this->redirect_page_id = "https://donate.ellak.gr/".get_page_link($this->get_option('redirect_page_id'));
            if ($this->redirect_page_id == "-1") {
                $redirect_url = $this->get_return_url($order);
            } else {
                $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id);
                //For wooCoomerce 2.0
                $redirect_url = add_query_arg(array('msg' => urlencode($this->msg['message']), 'type' => $this->msg['class']), $redirect_url);
            }
            wp_redirect($redirect_url);
            //exit;
            //}
            //		 if(isset($_GET['alphabank'])&& ($_GET['alphabank']==='cancel')) {
            //
            $checkout_url = $woocommerce->cart->get_checkout_url();
            wp_redirect($checkout_url);
            exit;
            //
            //}
        }
All Usage Examples Of WC_Order::has_downloadable_item
WC_Order