Skip to content

Instantly share code, notes, and snippets.

@ledbagholberton
Forked from anonymous/plugins.php
Created June 30, 2020 05:14
Show Gist options
  • Save ledbagholberton/9a0c58964b7d56b33914563f211c5e2c to your computer and use it in GitHub Desktop.
Save ledbagholberton/9a0c58964b7d56b33914563f211c5e2c to your computer and use it in GitHub Desktop.
Add extra info to WooCommerce product
<?php
/**
* Plugin Name: Pharmacy
* Plugin URI: http://domain.com
* Description: Add extra info for pharmacy products
* Author: Your name
* Author URI: http:// domain.com
* Version: 1.0
*/
add_filter( 'rwmb_meta_boxes', 'pharmacy_meta_boxes' );
function pharmacy_meta_boxes( $meta_boxes )
{
$meta_boxes[] = array(
'title' => __( 'Extra Product Info', 'pharmacy' ),
'post_types' => 'product',
'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' ),
),
),
),
array(
'id' => 'specification',
'name' => __( 'Specification', 'pharmacy' ),
'type' => 'text',
),
array(
'id' => 'manufacturer',
'name' => __( 'Manufacturer', 'pharmacy' ),
'type' => 'text',
),
array(
'id' => 'distributor',
'name' => __( 'Distributor', 'pharmacy' ),
'type' => 'text',
),
array(
'id' => 'expiry_date',
'name' => __( 'Expiry date', 'pharmacy' ),
'type' => 'date',
),
),
);
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>";
}
if ( $meta = rwmb_meta( 'specification' ) )
{
echo '<strong>' . __( 'Specification:', 'pharmacy' ) . "</strong> $meta<br>";
}
if ( $meta = rwmb_meta( 'manufacturer' ) )
{
echo '<strong>' . __( 'Manufacturer:', 'pharmacy' ) . "</strong> $meta<br>";
}
if ( $meta = rwmb_meta( 'distributor' ) )
{
echo '<strong>' . __( 'Distributor:', 'pharmacy' ) . "</strong> $meta<br>";
}
if ( $meta = rwmb_meta( 'expiry_date' ) )
{
echo '<strong>' . __( 'Expiry date:', 'pharmacy' ) . "</strong> $meta<br>";
}
}
@naurejalam
Copy link

Hi,
I am trying to use above meta WC code for my need but not able to display on my single product page.

Actually I am trying to add two product meta exactly like SKU. Similar to SKU is my priority, because as we know we can upload bulk product and display SKU via .CSV file in single go. So that I want to add below to meta just similar to SKU

  1. Manufacturer: Company Name
  2. Part Number: 123456789

Please guide me to get enable these two option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment