【问题标题】:Change payment gateway data sent to product description更改发送到产品描述的支付网关数据
【发布时间】:2020-02-04 03:22:37
【问题描述】:

我有一个用于 woocommerce 的支付网关,但在支付网关仪表板中的产品产品名称中,收到​​的产品名称如下所示。

产品名称:Apple AirPods 描述:用于bla bla的无线设备

我收到的是:Apple AirPods

我想要什么:想在产品名称旁边显示产品描述,并在它们之间用 w 破折号 - 如下所示;

Apple AirPods - 用于 bla bla 的无线设备

仅发送产品名称并在此处正常工作的代码是它:

/**
     * 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),
        );

【问题讨论】:

    标签: php wordpress woocommerce payment-gateway


    【解决方案1】:

    更改此行,我相信它应该会产生预期的效果。

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

    到这里

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

    【讨论】:

    • 似乎是正确的答案,但我测试了它,但它仍然不起作用,名称只出现。
    • @MagedMohamed 你知道 API 是否还在寻找其他字段吗?也许是一个名称字段?
    • 没有,但我认为问题出在前面的一行:$item_data ['itemId'] = $product->get_sku() ? $product->get_sku() : $item->get_product_id(); 它会影响$product->get_name() 的值
    • 你能不能把它作为第一行只获取没有sku的产品ID,然后在第二行获取产品描述,看看会发生什么。
    • 啊,然后是“ID”。 $item_data ['itemId'] = $product->get_sku() ? $product->get_sku() : $item->get_product_id() . " - " . $product->get_description();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    相关资源
    最近更新 更多