Php 获取订单项目中的订单项目Id

Php 获取订单项目中的订单项目Id,php,wordpress,woocommerce,orders,array-key,Php,Wordpress,Woocommerce,Orders,Array Key,使用WooCommerce,我尝试更改订单项目的下载URL。最初我使用的是订单ID,但每个订单只允许一次订阅。因此,我需要客户能够购买多个订阅 以下是我目前拥有的代码: if ( !class_exists( 'pl_wcdf_extention' ) ) { class pl_wcdf_extention { public function __construct() { add_filter( 'woocommerce_order_get

使用WooCommerce,我尝试更改订单项目的下载URL。最初我使用的是订单ID,但每个订单只允许一次订阅。因此,我需要客户能够购买多个订阅

以下是我目前拥有的代码:

if ( !class_exists( 'pl_wcdf_extention' ) ) {

    class pl_wcdf_extention {

        public function __construct() {

            add_filter( 'woocommerce_order_get_downloadable_items', array( $this, 'download_link' ), 10, 2 );

            add_filter( 'woocommerce_customer_get_downloadable_products', array( $this, 'download_link' ), 10, 1 );
        }

        public function download_link( $downloads, $order = null ) {

            $download_url_base = 'https://xxxx.com/';

            // retrieve Order ID from Download array

            $order_id = $downloads [0]['order_id'];

            // retrieve Order data

            $order = wc_get_order( $order_id );

            // retrieve Order Items 

            $order_item = $order->get_items();

            // retrieve first Order Item ID

            $order_item_id = $order_item [0][order_item_id];

            foreach ( $downloads as $download ) {

                $download['download_url'] = $download_url_base . "xxxx-" . $order_item_id . ".svg";

                $tag_item = array(
                    '--native-libs-dir' => '/home/Lib/',
                    '--type' => 'template0001style1',
                    '--data'=> $order_item_id,
                    '--join' => 'horizontal',
                    '--output-file' => '/home/public_html/xxxx-' . $order_item_id . '.svg'
                );

                $args = "";

                foreach ($tag_item as $k=>$v) {
                    $args .= " $k " . " $v ";
                }

                shell_exec("/home/Python-2.7.14/Python-3.6.3/python /home/Lib/generate-code.py $args");
            }

            return $downloads;
        }
    }
}

if ( class_exists( 'pl_wcdf_extention' ) ) {

    if ( ! defined( 'ABSPATH' ) ) {
        exit; // Exit if accessed directly
    }

    global $wpdb;

    define( 'PL_WCDFE_DIR_PATH', plugin_dir_path( __FILE__ ) );
    define( 'PL_WCDFE_PLUGIN_FILE', __FILE__ );

    new pl_wcdf_extention();

}
一切正常,但我无法获取订单项目ID


任何帮助都将不胜感激。

要从WC\u order\u item对象检索订单项目id,请使用get\u id()方法

因此,在脚本中,应替换此部分:

// retrieve first Order Item ID
$order_item_id = $order_item [0][order_item_id];
为此:

//检索第一个订单项目ID
$order_item_id=$order_item[0]->get_id()