Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用订单id';的逗号分隔字符串访问WooCommerce订阅数据;s_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 使用订单id';的逗号分隔字符串访问WooCommerce订阅数据;s

Php 使用订单id';的逗号分隔字符串访问WooCommerce订阅数据;s,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,尝试使用wcs\u get\u subscriptions函数检索订阅信息以创建可打印标签 我让插件将querystring中以逗号分隔的订单id列表传递到脚本中,但我不确定如何将id字符串传递到函数中 $subscriptions = wcs_get_subscriptions(array( 'subscriptions_per_page' => -1, 'subscription_status' => array('active'),

尝试使用
wcs\u get\u subscriptions
函数检索订阅信息以创建可打印标签

我让插件将querystring中以逗号分隔的订单id列表传递到脚本中,但我不确定如何将id字符串传递到函数中

$subscriptions = wcs_get_subscriptions(array( 'subscriptions_per_page' => -1,
                'subscription_status' => array('active'), 
                'post_id' => array(123,456,789) ));
foreach($subscriptions as $sub){ 
     echo $sub->get_shipping_city(); 
}

简言之,您不能使用
wcs\u获取订阅
功能:

不幸的是,
wcs\u get\u subscriptions
函数当前不允许为
order\u id
参数设置数组。查看函数的源代码,它只接受一个数值(“用于创建订阅的shop_order post/WC_order对象的post ID”),然后在返回ID列表的
get_posts
调用中将其用作
post_父对象;然后,它对每个数组运行wcs_get_订阅,以创建返回的最终数组。它在不允许获取所有参数方面有一定的局限性

wcs\u get\u subscriptions
功能的源代码可在此处找到:

满足您需要的替代解决方案:

您可以将
wcs\u get\u subscriptions
使用的其他类似参数与
post\u parent\u in
参数匹配使用:

“post\u parent\u in”(数组)包含要查询的父页面ID的数组 来自的子页面

下面是一个例子:

/**
 * Get an array of WooCommerce subscriptions in form of post_id => WC_Subscription.
 * Basically returns what wcs_get_subcriptions does, but allows supplying
 * additional arguments to get_posts.
 * @param array $get_post_args Additional arguments for get_posts function in WordPress
 * @return array Subscription details in post_id => WC_Subscription form.
 */
function get_wcs_subscription_posts($get_post_args){
  // Find array of post IDs for WooCommerce Subscriptions.
  $get_post_args = wp_parse_args( $get_post_args, array(
    'post_type' => 'shop_subscription',
    'post_status' => array('active'),
    'posts_per_page' => -1,
    'order' => 'DESC',
    'fields' => 'ids',
    'orderby' => 'date'
  ));
  $subscription_post_ids = get_posts( $get_post_args );

  // Create array of subscriptions in form of post_id => WC_Subscription
  $subscriptions = array();
  foreach ( $subscription_post_ids as $post_id ) {
    $subscriptions[ $post_id ] = wcs_get_subscription( $post_id );
  }
  return $subscriptions;
}

get_wcs_subscription_posts(array(
    'post_parent__in' => array(123, 456, 789)
));
如果您有订阅ID而不是订单ID,您也可以在
中使用
post\u。希望有帮助