I would like to add custom price suffix based on custom field. I tried to combine a few ready-made codes on functions.php.
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields()
{
global $woocommerce, $post;
echo '<div class="product_custom_field">';
woocommerce_wp_text_input(
array(
'id' => '_custom_product_text_field',
'label' => __('Taksit:', 'woocommerce'),
)
);
echo '</div>';
}
function woocommerce_product_custom_fields_save($post_id)
{
$woocommerce_custom_product_text_field = $_POST['_custom_product_text_field'];
if (!empty($woocommerce_custom_product_text_field))
update_post_meta($post_id, '_custom_product_text_field', esc_attr($woocommerce_custom_product_text_field));
}
add_filter( 'woocommerce_get_price_suffix', 'price_taksit_ekle', 99, 4 );
function price_taksit_ekle( $html, $product, $price, $qty ){
$html = get_post_meta($post->ID, '_custom_product_text_field', true);
return $html;
}
However this results in the following notice: Attempt to read property "ID" on null.
Any advice?