在产品名称旁边发送支付网关woocommerce产品说明

时间:2019-12-23 14:22:21

标签: php wordpress woocommerce

我要发送

function getProductsJson($order,$options) {
    $stupid_mode = $options['stupid_mode'];
        $items=$order->get_items();
        $arr = [];
        foreach ($items as $item) {
            $data = $item->get_data();

            $arr[] = [
                'productSKU' => $data['product_id'],
                'description' => $data['name'],
                'quantity' => $data['quantity'],
                'price' => $data['total'] / $data['quantity'],
            ];
    }
}

在此部分:

'description' => $data['name'],

我希望它在产品名称旁边发送产品说明,如下所示:

产品名称-产品说明

如何实现呢?

最好的问候

1 个答案:

答案 0 :(得分:1)

如果您需要将产品描述保存在$ content中,则可以通过Product_ID获得它,然后将其添加到您的数组中:

function getProductsJson($order,$options) {
  $stupid_mode = $options['stupid_mode'];
  $items=$order->get_items();
  $arr = [];
  foreach ( $items as $item ) {
    $data = $item->get_data();
    $product_description = get_post( $data['product_id'] )->post_content;
    $arr[] = [
            'productSKU' => $data['product_id'],
            'name' => $data['name'],
            'description' => $product_description,
            'quantity' => $data['quantity'],
            'price' => $data['total'] / $data['quantity'],
    ];
  }
}

或者,如果您需要内置的woocommerce产品描述,请尝试以下操作:

function getProductsJson($order,$options) {
  $stupid_mode = $options['stupid_mode'];
  $items=$order->get_items();
  $arr = [];
  foreach ( $items as $item ) {
    $data = $item->get_data();
    $product_instance = wc_get_product( $data['product_id'] );
    $product_full_description = $product_instance->get_description();
    $product_short_description = $product_instance->get_short_description();
    $arr[] = [
            'productSKU' => $data['product_id'],
            'name' => $data['name'], // or $data['description']
            'description' => $product_full_description, // or $product_short_description
            'quantity' => $data['quantity'],
            'price' => $data['total'] / $data['quantity'],
    ];
  }
}