【问题标题】:woocommerce custom admin tab breaks variationswoocommerce 自定义管理选项卡打破了变化
【发布时间】:2015-09-03 10:47:57
【问题描述】:

我在 woocommerce 产品管理选项卡中添加了从自定义帖子类型中进行选择的功能,该功能具有本教程中使用的功能http://www.remicorson.com/mastering-woocommerce-products-custom-fields/

所以我添加了一个自定义字段

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

现在函数看起来像这样

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;
    }

问题在于,在将代码上传到服务器时,此函数会破坏变体窗口,它只显示默认的“添加变体消息”

控制台没有显示错误。

我猜这与 ajax 请求有关,但无法弄清楚究竟是什么,我试图将 get 函数移到其他文件等中,但没有运气。

woocommerce插件版本为2.2.8

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    好的,所以我已经弄清楚了,解决方法是使用带有 $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;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多