Created
April 15, 2016 04:31
-
-
Save anonymous/6fe7b25b74b479d0b3415332c8c2e7c6 to your computer and use it in GitHub Desktop.
Add extra info to WooCommerce product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Please guide me to get enable these two option.