我将为您提供有关如何为产品添加元数据的小演示。
在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
谢谢。