如何在Woocommerce产品列表中添加Extra Product Meta?

时间:2017-11-27 06:06:03

标签: woocommerce

I want to add product meta like this

我想在我的Online Cosmetics Store中添加product meta,就像上面的屏幕截图一样。

此元数据存在于opencart网站shop4shops.in中。我想在我的Woocommerce商店中添加相同的元数据。

您的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我将为您提供有关如何为产品添加元数据的小型演示。

在function.php文件中

添加以下代码。

add_filter( 'rwmb_meta_boxes', 'pharmacy_meta_boxes' );

  function pharmacy_meta_boxes( $meta_boxes ) {
      $meta_boxes[] = array(
      'title'  => __( 'Extra Product Info', 'pharmacy' ),
      'fields' => array(
                        array(
                               'id' => 'unit',
                               'name' => __( 'Unit', 'pharmacy' ),
                               'type' => 'text',
                               'datalist' => array(
                                             'options' => array(
                                              __( 'Box', 'pharmacy' ),
                                              __( 'Blister pack', 'pharmacy' ),
                                              __( 'Packet', 'pharmacy' ),
                                              __( 'Bottle', 'pharmacy' ),
                                             ),
                             ), 
                        ),
                        array(
                               'id'   => 'dosage_form',
                               'name' => __( 'Dosage form', 'pharmacy' ),
                               'type' => 'text',
                               'datalist' => array(
                                             'options' => array(
                                             __( 'Capsule', 'pharmacy' ),
                                             __( 'Tablet', 'pharmacy' ),
                                             __( 'Liquid', 'pharmacy' ),
                                             __( 'Ointment', 'pharmacy' ),
                               ),
                            ),
                        ),
                   );

       return $meta_boxes;
 }

并在函数中保存元写入

add_action( 'woocommerce_product_meta_end', 'pharmacy_extra_info' );
  function pharmacy_extra_info()
     {
      if ( $meta = rwmb_meta( 'unit' ) )
        {
          echo '<strong>' . __( 'Unit:', 'pharmacy' ) . "</strong> $meta<br>";
        }
       if ( $meta = rwmb_meta( 'dosage_form' ) )
        {
           echo '<strong>' . __( 'Dosage form:', 'pharmacy' ) . "</strong> $meta<br>";
       }
 }

我希望以下代码可以帮助您在产品中添加元数据,并且可以像这样添加更多产品元素。

你也可以关注 this link

谢谢。

相关问题