Snippets

Visser Labs Adding static Product fields to the Products export type

Updated by Michael Visser

File functions.php Modified

  • Ignore whitespace
  • Hide word diff
     return $fields;
 
 }
-add_filters( 'woo_ce_product_fields', 'custom_woo_ce_extend_product_fields' );
+add_filter( 'woo_ce_product_fields', 'custom_woo_ce_extend_product_fields' );
 
 function custom_woo_ce_extend_product_item( $product, $product_id ) {
 
     return $product;
 
 }
-add_filters( 'woo_ce_product_item', 'custom_woo_ce_extend_product_item', 10, 2 );
+add_filter( 'woo_ce_product_item', 'custom_woo_ce_extend_product_item', 10, 2 );
 ?>
Updated by Michael Visser

File functions.php Modified

  • Ignore whitespace
  • Hide word diff
     return $product;
 
 }
-add_filter( 'woo_ce_product_item', 'custom_woo_ce_extend_product_item', 10, 2 );
+add_filters( 'woo_ce_product_item', 'custom_woo_ce_extend_product_item', 10, 2 );
 ?>
Updated by Michael Visser

File functions.php Modified

  • Ignore whitespace
  • Hide word diff
 
     $fields[] = array(
         'name' => 'static_field',
-        'label' => __( 'Static Field', 'woo_ce' )
+        'label' => __( 'Static Field', 'woo_ce' ),
+        'hover' => __( 'Static Field within functions.php', 'woo_ce' )
     );
     return $fields;
 
Created by Michael Visser

File functions.php Added

  • Ignore whitespace
  • Hide word diff
+<?php
+function custom_woo_ce_extend_product_fields( $fields ) {
+
+    $fields[] = array(
+        'name' => 'static_field',
+        'label' => __( 'Static Field', 'woo_ce' )
+    );
+    return $fields;
+
+}
+add_filters( 'woo_ce_product_fields', 'custom_woo_ce_extend_product_fields' );
+
+function custom_woo_ce_extend_product_item( $product, $product_id ) {
+
+    $product->static_field = 'Static value';
+    return $product;
+
+}
+add_filter( 'woo_ce_product_item', 'custom_woo_ce_extend_product_item', 10, 2 );
+?>