1

I'm trying to hidden or remove the price on each variable products inside dropdown menu on a single product page. Please see image attached below.

I believe here is the codes that needs to be edited. Any help is appreciated. Thanks in advance.

<?php do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<div class="cart-form-wrapper clearfix">
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo $post->ID; ?>" data-product_variations="<?php echo esc_attr( json_encode( $available_variations ) ) ?>">
<?php if ( ! empty( $available_variations ) ) : ?>
    <table class="variations" cellspacing="0">
        <tbody>
            <?php $loop = 0; foreach ( $attributes as $name => $options ) : $loop++; ?>
                <tr>
                    <td class="label"><label for="<?php echo sanitize_title($name); ?>"><?php echo wc_attribute_label( $name ); ?></label></td>
                    <td class="value"><select id="<?php echo esc_attr( sanitize_title( $name ) ); ?>" name="attribute_<?php echo sanitize_title( $name ); ?>">
                        <option value=""><?php echo __( 'Choose an option', 'woocommerce' ) ?>&hellip;</option>
                        <?php
                            if ( is_array( $options ) ) {

                                if ( isset( $_REQUEST[ 'attribute_' . sanitize_title( $name ) ] ) ) {
                                    $selected_value = $_REQUEST[ 'attribute_' . sanitize_title( $name ) ];
                                } elseif ( isset( $selected_attributes[ sanitize_title( $name ) ] ) ) {
                                    $selected_value = $selected_attributes[ sanitize_title( $name ) ];
                                } else {
                                    $selected_value = '';
                                }

                                // Get terms if this is a taxonomy - ordered
                                if ( taxonomy_exists( $name ) ) {

                                    $terms = wc_get_product_terms( $post->ID, $name, array( 'fields' => 'all' ) );

                                    foreach ( $terms as $term ) {
                                        if ( ! in_array( $term->slug, $options ) ) {
                                            continue;
                                        }
                                        echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $term->slug ), false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';
                                    }

                                } else {

                                    foreach ( $options as $option ) {
                                        echo '<option value="' . esc_attr( sanitize_title( $option ) ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
                                    }

                                }
                            }
                        ?>
                    </select> <?php
                        /*if ( sizeof($attributes) == $loop )
                            echo '<a class="reset_variations" href="#reset">' . __( 'Clear selection', 'woocommerce' ) . '</a>';*/
                    ?></td>
                </tr>
            <?php endforeach;?>
        </tbody>
    </table>
1

By using hook

remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price',10);

or CSS

span.price
{
    display: none !important;
}

*Tag May be different as per your theme.

Thanks, Vee

0

You find this code on your code (shared above):

echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $term->slug ), false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';

And replace that by this code:

echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $term->slug ), false ) . '>' . $term->name . '</option>';

And this: You need find this code:

echo '<option value="' . esc_attr( sanitize_title( $option ) ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';

And replace that by this code:

echo '<option value="' . esc_attr( sanitize_title( $option ) ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '>' . $option . '</option>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.