简体   繁体   English

woocommerce定制管理选项卡打破了变化

[英]woocommerce custom admin tab breaks variations

I've added the ability to choose from custom post types in the woocommerce product admin tabs with a function as used in this tutorial http://www.remicorson.com/mastering-woocommerce-products-custom-fields/ 我已经添加了在woocommerce产品管理选项卡中从自定义帖子类型中进行选择的功能,该功能具有本教程中使用的功能http://www.remicorson.com/mastering-woocommerce-products-custom-fields/

so I've added a custom field 所以我添加了一个自定义字段

 woocommerce_wp_select(
   array(
     'id'      => '_circuit',
     'label'   => __( 'choose circuit', 'woocommerce' ),
     'options' => get_circuits_as_array()
         )
     );

now the function looks like this 现在函数看起来像这样

function get_circuits_as_array(){
      $args = array( 'post_type' => 'top', 'posts_per_page' => -1,    'post_status'=>'published' );
      $loop = new WP_Query( $args );
      $circuits = array('0'=>'--wybierz opcję--');
      while ( $loop->have_posts() ) : $loop->the_post();
     setup_postdata( $post );
      $circuits[get_the_id()] = get_the_title();
      endwhile;
      wp_reset_query();
      return $circuits;
    }

The problem is that while uploading the code to the server this function breaks the variations window it shows only the default "add variations message" 问题是,在将代码上传到服务器时,此功能会破坏版本窗口,它仅显示默认的“添加版本消息”

在此处输入图片说明

The console shows no errors. 控制台未显示任何错误。

I guess this has something to do with ajax requests but cant figure out exactly what, I've tries to move the get function in other files etc. but no luck. 我猜想这与ajax请求有关,但无法弄清楚到底是什么,我试图将get函数移到其他文件中,等等,但是没有运气。

The woocommerce plugin version is 2.2.8 woocommerce插件版本为2.2.8

OK so I've figured this out and the workaround is to use a foreach loop with $loop->posts as the array 好的,所以我已经弄清楚了,解决方法是使用带有$ loop-> posts作为数组的foreach循环

function get_circuits_as_array(){
      $args = array( 'post_type' => 'top', 'posts_per_page' => -1, 'post_status'=>'published' );
      $loop = new WP_Query( $args );
      $circuits = array('0'=>'--wybierz opcję--');
      foreach ($loop->posts as $circuit) {
        $circuits[$circuit->ID] = $circuit->post_title;
      }
      wp_reset_query();
      return $circuits;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM