Answer the question
In order to leave comments, you need to log in
Adding Custom Wordpress/Woocommerce Fields?
Added a field before the price that would look like
functions.php
add_action( 'woocommerce_product_options_general_product_data', 'art_woo_add_custom_fields' );
function art_woo_add_custom_fields() {
global $product, $post;
echo '<div class="options_group">';
woocommerce_wp_select( array(
'id' => '_select',
'label' => 'Значение перед ценой',
'options' => array(
'' => __( 'нет', 'woocommerce' ),
'от' => __( 'от', 'woocommerce' ),
),
) );
echo '</div>';
}
add_action( 'woocommerce_process_product_meta', 'art_woo_custom_fields_save', 10 );
function art_woo_custom_fields_save( $post_id ) {
$woocommerce_select = $_POST['_select'];
if ( $woocommerce_select ) {
update_post_meta( $post_id, '_select', esc_attr( $woocommerce_select ) );
}else {
delete_post_meta( $post_id, '_select');
}
}
add_action( 'woocommerce_get_price_suffix', 'art_get_select_before_add_card' );
function art_get_select_before_add_card() {
global $post;
echo '<span class="price_suffix">';
echo get_post_meta( $post->ID, '_select', true );
echo '</span>';
}
...
'от1' => __( 'от2', 'woocommerce' ),
...
Answer the question
In order to leave comments, you need to log in
We display the value before the price.
Here in one echo will not work?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question