Maged Mohamed
Maged Mohamed

Reputation: 561

Change payment gateway data sent to product description

I have a payment gateway for woocommerce, but in the product name of the products in the payment gateway dashboard the product name is received right as the code below.

Product name: Apple AirPods Description: Wireless device used to bla bla

What i receive: Apple AirPods

What i want: want to show the product description next to the product name with w dash - between them as below;

Apple AirPods - Wireless device used to bla bla

The code that sends the product name only and works fine here is it:

/**
     * Process the payment and return the result.
     * @param  int $order_id
     * @return array
     */
    public function process_payment($order_id) {
        $order = wc_get_order($order_id);
        $order_items = array();
        //get order items date(DateTime::ISO8601)
        $time_stamp = time() + $this->payment_expiry * 60 * 60;
        foreach ($order->get_items() as $item) {
            $product = $item->get_product();
            $item_data ['itemId'] = $product->get_sku() ? $product->get_sku() : $item->get_product_id();
            $item_data ['description'] = $product->get_name();
            $item_data ['quantity'] = $item->get_quantity();
            $item_data ['price'] = wc_format_decimal($product->get_price(), 2);
            $order_items[] = $item_data;
        }
        //send request to fawry to create charge
        $chargeRequest = array(
            'merchantRefNum' => $order_id,
            'merchantCode' => $this->merchant_code,
            'customerProfileId' => $order->get_customer_id(),
            'customerMobile' => $order->get_billing_phone(),
            'customerEmail' => $order->get_billing_email(),
            'paymentMethod' => "PAYATFAWRY",
            'amount' => WC()->cart->total,
            'currencyCode' => $order->get_currency(),
            "description" => $this->description,
            'chargeItems' => $order_items,
            'paymentExpiry' => date('c', $time_stamp),
            'signature' => hash('sha256', $this->merchant_code . $order_id . $order->get_customer_id() . 'PAYATFAWRY' . WC()->cart->total . $this->secure_key),
        );

Upvotes: 0

Views: 153

Answers (1)

RobertC
RobertC

Reputation: 590

Change this line, and it should give the desired effect I believe.

$item_data ['description'] = $product->get_name();

To this

$item_data ['description'] = $product->get_name() . " - " . $product->get_description();

Upvotes: 1

Related Questions