Product Meta Fields module

Learn more about the Product Meta Fields module.

Digital River requires products to have certain fields that are not present in the WooCommerce product. Add these fields to the WC_Product by using the concept of meta fields by using the ProductMetaFields module.

Add a new field to the metabox

To add a new field to the metabox:

  1. Grab the Field array from the filter: add_filter( 'digitalriver.meta_fields', 'filter_method' )

  2. Pass the array as the first argument to filter_method().

  3. Add or remove fields from the array and then return it.

Product Meta Fields Methods

Product Meta Fields class

This class acts as the module's entry point.

Method

Args, Returns, and Descriptions

name

Arg: -

Return: string

Description: Returns the name of the module

__construct

Arg: MetaFieldsContainer $container

Return: void

Description: Constructs the object by passing in the dependencies

init

Arg: -

Return: void

Description: Initializes the module, register necessary hooks, and defines the fields

admin_enqueue_scripts

Arg: String $hook_suffix

Return: void

Description: Enqueue the scripts and stylesheets in the admin_enqueue_scripts hook

woocommerce_product_data_tabs

Arg: array $product_data_tabs

Return: array

Description: Add a new tab to enter the Digital River product details in the product create/edit page.

woocommerce_product_data_panels

Arg: -

Return: void

Description: Renders HTML of Digital River tab under the WooCommerce Product Data metabox

woocommerce_admin_process_product_object

Arg: WC_Product $product

Return: void

Description: Saves the digitalriver meta values in metadata when a product is saved/created

field

Arg: String $key

Return: Field

Description: Gets a field name as an argument and returns the field object

Meta Fields Container class

This class acts as a Dependency Injection container for providing dependencies to classes present in the ProductMetaFields module.

Method

Args, Returns, and Descriptions

__construct

Arg: PimpleContainer

Return: void

Description: Accepts a Dependency Injection container as an argument and assigns it to a container attribute

define_services

Arg: -

Return: void

Description: Defines all the classes present within the module

Field interface

The interface must be implemented by all the meta fields.

Method

Args, Returns, and Descriptions

meta_key

Arg: -

Return: string

Description: Returns the meta key

render

Arg: -

Return: void

Description: Renders the meta field to the metabox

value

Arg: int $post_id

Return: mixed

Description: Retrieves meta value of the post with id $post_id

save

Arg: int $post_id, mixed $value

Return: void

Description: Saves the meta value to the post

Field classes

This module has the following field classes:

Field class

Description

CountryOfOrigin

The CountryOfOrigin field refers to the location where the product originated. The CountryOfOrigin is a two-letter Alpha-2 country code as described in the ISO 3166 international standard. Here is a list of country codes.

ECCN

Exports Control Classification Number (ECCN). A list of pre-approved ECCNs is found here.

HSCode

Read more here about the Harmonized Commodity Description and Coding System (HS Code).

TaxCode

See a list of supported tax codes here.

Last updated