WooCommerce issue with display PHP of custom field data
one text
I got this example for another Stack post]1. It was to add a barcode field to a WooCommerce product. The code worked in creating it, but the code to display it was another story. Threw a boolean error instead. Due to the call on member function 'get_meta'. This is the code from that post:
$product = wc_get_product( $product_id );
$product->get_meta( '_variable_billing' );
What would be proper code to eliminate the error? Here's the rest of the code from that post:
//Add barcode to the product inventory tab
add_action('woocommerce_product_options_inventory_product_data','add_barcode');
function add_barcode(){
global $woocommerce,$post;
woocommerce_wp_text_input(
array(
'id' => '_barcode',
'label' => __('Barcode','woocommerce'),
'placeholder' => 'Scan Barcode',
'desc_tip' => 'true',
'description' => __('Scan barcode.','woocommerce')
));
}
//Save Barcode Field
function add_barcode_save($post_id){
if(isset($_POST['_barcode'])){
update_post_meta($post_id,'_barcode',sanitize_text_field($_POST['_barcode']));
}else{
delete_meta_data($post_id,'_barcode',sanitize_text_field($_POST['_barcode']));
}
}
add_action('woocommerce_process_product_meta','add_barcode_save');
//Set POS Custom Code
function pos_barcode_field(){return '_barcode';}
add_filter('woocommerce_pos_barcode_meta_key','pos_barcode_field');
Source