Home Forums WoodMart support forum Remove price from Tooltip

Remove price from Tooltip

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #42925

    miguel1876
    Participant

    Hi guys

    I added this code to show the variation price next to each variation.

    //Add prices to variations
    add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );
    
    function display_price_in_variation_option_name( $term ) {
    global $wpdb, $product;
    
    $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );
    
    $term_slug = ( !empty( $result ) ) ? $result[0] : $term;
    
    $query = "SELECT postmeta.post_id AS product_id
    FROM {$wpdb->prefix}postmeta AS postmeta
    LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )
    WHERE postmeta.meta_key LIKE 'attribute_%'
    AND postmeta.meta_value = '$term_slug'
    AND products.post_parent = $product->id";
    
    $variation_id = $wpdb->get_col( $query );
    
    $parent = wp_get_post_parent_id( $variation_id[0] );
    
    if ( $parent > 0 ) {
    $_product = new WC_Product_Variation( $variation_id[0] );
    
    //this is where you can actually customize how the price is displayed
    return $term . ' <span>(' . woocommerce_price( $_product->get_price() ) . ')</span>';
    }
    return $term;
    
    }

    This works, however the price also appears in the tooltip. Do you have a solution to remove it? You can see in the code there is a span tag wrapping the price, so I could use that in the CSS to remove the price, however it appears that the HTML is stripped out of the Tooltip.
    I thought maybe this would allow HTML, but it didn’t work:

    <script type="text/javascript">
    jQuery(document).ready(function () {
    jQuery(".tooltip").tooltip({html:true});
    });
    </script>

    Please help.

    Thanks so much.

    #42946

    Artem Temos
    Keymaster

    Hi,

    You can try to modify this tooltips initialization code in the file js/functions.js https://gyazo.com/10d6ca5e7fde48ab86fc8f1278db9ac1
    There, you can try to change some parameters or strip unnecessary HTML code somehow. Sorry, but we don’t have a working solution for this.

    Regards

    #42970

    miguel1876
    Participant

    Hi

    Thanks but it doesn’t work.

    What if we wrap the code in an if statement with a conditional tag for a specific attribute (variation)?

    #42986

    Artem Temos
    Keymaster

    Sorry, but we don’t have such customizations tips since it is out of our theme support scope.

Viewing 4 posts - 1 through 4 (of 4 total)