[Resolved] woocommerce variation selector

Home Forums Support woocommerce variation selector

This topic contains 13 replies, has 2 voices, and was last updated by  Leo 2 months, 1 week ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1205224

    Diederick

    Hi,

    Since the corona virus bought me some time to adjust my website something has drawn my attention.
    On a page of a product that has variation I have multiple or single selectors.
    Now when I select a variation in the dropdownbox the images change.
    But the price stays the same.
    This only change when I click outside the dropdownbox.
    Or lose the focus of the dropdownbox element.
    Can this be resolved?

    #1206181

    Leo Customer Support

    Hi there,

    This is controlled by WooCommerce and it should work by default:
    https://gpsites.co/prime/product/v-neck-t-shirt/

    Any chance you can disable all plugins except GP Premium to eliminate conflicts from other plugins first?

    Let me know 🙂

    #1206214

    Diederick

    Hmmm thought so but this is a live website can’t really disable everything.
    DOn’t have a test environment for this woocommerce website.
    I’ll see what i can do.

    #1206457

    Leo Customer Support

    Yup a testing site would definitely be helpful.

    #1207720

    Diederick

    Alright just made a staging site to test this.
    Disabled everything except woocommerce, wpml and GP plugins.
    An it still happens.

    #1207732

    Leo Customer Support

    Can you activate a twenty series theme and see if the same issue exists there?

    Let me know 🙂

    #1207804

    Diederick

    Oke seems like the functionality was changed by a script.
    So it probably will be that…
    Now I need to figure out how to do it.
    Thanks for helping me locating it.

    If you by any change know any tips for this.
    Seems like the price range is changed instead of the popup that appears underneath.
    (if from former webmaster)

    /*
    |——————————————————
    | Woocommerce: Change Variable price
    |——————————————————
    */

    // Utility function to get the default variation (if it exist)
    function get_default_variation( $product ){
    $attributes_count = count($product->get_variation_attributes());
    $default_attributes = $product->get_default_attributes();
    // If no default variation exist we exit
    if( $attributes_count != count($default_attributes) )
    return false;

    // Loop through available variations
    foreach( $product->get_available_variations() as $variation ){
    $found = true;
    // Loop through variation attributes
    foreach( $variation[‘attributes’] as $key => $value ){
    $taxonomy = str_replace( ‘attribute_’, ”, $key );
    // Searching for a matching variation as default
    if( isset($default_attributes[$taxonomy]) && $default_attributes[$taxonomy] != $value ){
    $found = false;
    break;
    }
    }
    // If we get the default variation
    if( $found ) {
    $default_variaton = $variation;
    break;
    }
    // If not we continue
    else {
    continue;
    }
    }
    return isset($default_variaton) ? $default_variaton : false;
    }

    add_action( ‘woocommerce_before_single_product’, ‘move_variations_single_price’, 5 );
    function move_variations_single_price(){
    global $product, $post;

    if ( $product->is_type( ‘variable’ ) ) {
    // removing the variations price for variable products
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );

    // Change location and inserting back the variations price
    add_action( ‘woocommerce_single_product_summary’, ‘replace_variation_single_price’, 20 );
    }
    else{
    // reorder
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
    add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 20 );
    }
    }

    function replace_variation_single_price(){
    global $product;

    // Main Price
    $prices = array( $product->get_variation_price( ‘min’, true ), $product->get_variation_price( ‘max’, true ) );
    $active_price = $prices[0] !== $prices[1] ? sprintf( __( ‘From: %1$s’, ‘woocommerce’ ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    // Sale Price
    $prices = array( $product->get_variation_regular_price( ‘min’, true ), $product->get_variation_regular_price( ‘max’, true ) );
    sort( $prices );
    $regular_price = $prices[0] !== $prices[1] ? sprintf( __( ‘From: %1$s’, ‘woocommerce’ ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    if ( $active_price !== $regular_price && $product->is_on_sale() ) {
    $price = ‘‘ . $regular_price . $product->get_price_suffix() . ‘ <ins>’ . $active_price . $product->get_price_suffix() . ‘</ins>’;
    } else {
    $price = $regular_price;
    }

    // When a default variation is set for the variable product
    if( get_default_variation( $product ) ) {
    $default_variaton = get_default_variation( $product );
    if( ! empty($default_variaton[‘price_html’]) ){
    $price_html = $default_variaton[‘price_html’];
    } else {
    if ( ! $product->is_on_sale() )
    $price_html = $price = wc_price($default_variaton[‘display_price’]);
    else
    $price_html = $price;
    }
    $availiability = $default_variaton[‘availability_html’];
    } else {
    $price_html = $price;
    $availiability = ”;
    }
    // Styles ?>
    <style>
    div.woocommerce-variation-price,
    div.woocommerce-variation-availability,
    div.hidden-variable-price {
    height: 0px !important;
    overflow:hidden;
    position:relative;
    line-height: 0px !important;
    font-size: 0% !important;
    }
    </style>
    <?php // Jquery ?>
    <script>
    jQuery(document).ready(function($) {
    var a = ‘div.wc-availability’, p = ‘p.price’;

    $(‘select’).blur( function(){
    if( ” != $(‘input.variation_id’).val() ){
    if($(a).html() != ” ) $(a).html(”);
    $(p).html($(‘div.woocommerce-variation-price > span.price’).html());
    $(a).html($(‘div.woocommerce-variation-availability’).html());
    } else {
    if($(a).html() != ” ) $(a).html(”);
    $(p).html($(‘div.hidden-variable-price’).html());
    }
    });
    });
    </script>
    <?php

    echo ‘<p class=”price”>’.$price_html.'</p>

    ‘.$availiability.’
    ‘.$price.’

    ‘;
    }

    #1207815

    Leo Customer Support

    Unfortunately I’m not familiar with that script. Where did you get it from?

    #1207828

    Diederick

    Former webmaster, who did not complete the website so I’m trying to complete it.
    Maybe I need to find other script or way to achive this.
    Or maybe you have an idea?
    Goal is to have one place where the price is displayed (so both the range when nothing is selected as the official price when something is selected)

    #1207841

    Leo Customer Support

    Unfortunately I don’t.

    You’d need to check with WooCommerce’ support to see if they are able to point you in the right direction.

    #1207845

    Diederick

    oke thanks for the help!

    #1207849

    Leo Customer Support

    No problem!

    Sorry I couldn’t be more helpful.

    #1207857

    Diederick

    For those who are intrested in the solution, found this on stackoverflow

    #1207881

    Leo Customer Support
Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.