Добавление поле в админке
add_action( 'woocommerce_product_options_pricing', 'custom_woocommerce_product_options_pricing' );
function custom_woocommerce_product_options_pricing() {
$price_index = '_custom_price';
woocommerce_wp_text_input(
array(
'id' => $price_index,
'value' => get_post_meta( get_the_ID(), $price_index, true ),
'data_type' => 'price',
'label' => __( 'Custom price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')'
)
);
}
add_action( 'woocommerce_admin_process_product_object', 'custom_woocommerce_admin_process_product_object', 10, 1 );
function custom_woocommerce_admin_process_product_object( $product ) {
$price_index = '_custom_price';
$price = wc_clean( wp_unslash( $_POST[ $price_index ] ) );
update_post_meta( $product->get_id(), $price_index, $price );
}
Вывод в шаблоне
$price_index = '_custom_price';
echo wc_price( get_post_meta( get_the_ID(), $price_index, true ) );