狠狠撸

狠狠撸Share a Scribd company logo
Advanced Customization:
Custom Fields
CustomizeWoo.com
"Custom Field"
"Custom Fields (post meta, metadata)
allow you to store additional
information with each WordPress post.
They can then be displayed/used
anywhere"
CustomizeWoo.com
WC Product = WP Post + CF
CustomizeWoo.com
Some WC Product Custom Fields!
CustomizeWoo.com
● '_visibility'
● '_sku'
● '_price'
● '_regular_price'
● '_sale_price'
● '_sale_price_dates_from'
● '_sale_price_dates_to'
● 'total_sales'
● '_tax_status'
● '_tax_class'
● '_manage_stock'
● '_stock'
● '_stock_status'
● '_backorders'
● '_low_stock_amount'
● '_sold_individually'
● '_weight'
● '_length'
Custom Fields Benefits
CustomizeWoo.com
● Target specific post/product ID (conditional
behavior)
● Store information forever
● Use it or return it to screen
whenever/wherever you like: alter
behaviour (price) or add data (e.g. RRP)
(1a) Add Custom Field Manually
CustomizeWoo.com
(1b) Add Custom Field By Code
CustomizeWoo.com
update_post_meta( $post_id, $meta_key, $meta_value );
update_post_meta( 456, 'packaging_weight', '2' );
(codex.wordpress.org/Function_Reference/update_post_meta)
(2) Get Custom Field By Code
CustomizeWoo.com
get_post_meta( $post_id, $meta_key, $single = false );
echo get_post_meta( 456, 'packaging_weight', true );
echo get_post_meta( 789, 'total_sales', true );
echo get_post_meta( 123, '_regular_price', true );
echo $product->get_regular_price();
(developer.wordpress.org/reference/functions/get_post_meta/)
Custom Fields Workflow
CustomizeWoo.com
1. Project specs e.g. "Display packaging weight
@ product ID = 556"
2. Add custom field name=>value @ product ID
= 556
3. Get post meta and return it to the screen

More Related Content

WooCommerce: Custom Fields

  • 2. "Custom Field" "Custom Fields (post meta, metadata) allow you to store additional information with each WordPress post. They can then be displayed/used anywhere" CustomizeWoo.com
  • 3. WC Product = WP Post + CF CustomizeWoo.com
  • 4. Some WC Product Custom Fields! CustomizeWoo.com ● '_visibility' ● '_sku' ● '_price' ● '_regular_price' ● '_sale_price' ● '_sale_price_dates_from' ● '_sale_price_dates_to' ● 'total_sales' ● '_tax_status' ● '_tax_class' ● '_manage_stock' ● '_stock' ● '_stock_status' ● '_backorders' ● '_low_stock_amount' ● '_sold_individually' ● '_weight' ● '_length'
  • 5. Custom Fields Benefits CustomizeWoo.com ● Target specific post/product ID (conditional behavior) ● Store information forever ● Use it or return it to screen whenever/wherever you like: alter behaviour (price) or add data (e.g. RRP)
  • 6. (1a) Add Custom Field Manually CustomizeWoo.com
  • 7. (1b) Add Custom Field By Code CustomizeWoo.com update_post_meta( $post_id, $meta_key, $meta_value ); update_post_meta( 456, 'packaging_weight', '2' ); (codex.wordpress.org/Function_Reference/update_post_meta)
  • 8. (2) Get Custom Field By Code CustomizeWoo.com get_post_meta( $post_id, $meta_key, $single = false ); echo get_post_meta( 456, 'packaging_weight', true ); echo get_post_meta( 789, 'total_sales', true ); echo get_post_meta( 123, '_regular_price', true ); echo $product->get_regular_price(); (developer.wordpress.org/reference/functions/get_post_meta/)
  • 9. Custom Fields Workflow CustomizeWoo.com 1. Project specs e.g. "Display packaging weight @ product ID = 556" 2. Add custom field name=>value @ product ID = 556 3. Get post meta and return it to the screen