- Обычная цена
- Цена со скидкой
- Суперцена продажи
И все это должно быть не путаться с переменными продуктами и использовать только простые продукты.
Вот мой код:
Код: Выделить всё
/**
* Function to render UI in Admin Product add/edit page
*/
function show_custom_price_admin() {
global $thepostid;
woocommerce_wp_text_input(
array(
'id' => 'custom_price',
'name' => '_custom_price',
'value' => get_post_meta( $thepostid, '_custom_price', true ),
'class' => 'wc_input_price short',
'label' => __( 'Custom Price ($)', 'vg' ),
)
);
}
add_action( 'woocommerce_product_options_pricing', 'show_custom_price_admin' );
/**
* Function to update custom price Admin Product add/edit page
*
* @param int $post_id Product's post id.
*/
function process_product_custom_data( $post_id ) {
$product = wc_get_product( $post_id );
$product->update_meta_data(
'_custom_price',
wc_clean( wp_unslash( filter_input( INPUT_POST, '_custom_price' ) ) )
);
$product->save();
}
add_action( 'woocommerce_process_product_meta', 'process_product_custom_data' );
/**
* Function to show custom price front end page
*/
function show_custom_price_frontend() {
global $post;
$custom_price = get_post_meta( $post->ID, '_custom_price', true );
if ( $custom_price ) {
$custom_price = wc_price( $custom_price );
printf( '
%s
', $custom_price );
}
}
add_action( 'woocommerce_before_add_to_cart_form', 'show_custom_price_frontend' );
И все это не должно портиться переменные продукты и быть только для простых продуктов.
Подробнее здесь: https://stackoverflow.com/questions/791 ... woocommerc