- This topic has 13 replies, 2 voices, and was last updated 3 years, 8 months ago by
Leo.
-
AuthorPosts
-
March 22, 2020 at 6:42 am #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?March 22, 2020 at 8:47 am #1206181Leo
StaffCustomer SupportHi 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 π
March 22, 2020 at 9:00 am #1206214Diederick
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.March 22, 2020 at 11:36 am #1206457Leo
StaffCustomer SupportYup a testing site would definitely be helpful.
March 23, 2020 at 10:05 am #1207720Diederick
Alright just made a staging site to test this.
Disabled everything except woocommerce, wpml and GP plugins.
An it still happens.March 23, 2020 at 10:21 am #1207732Leo
StaffCustomer SupportCan you activate a twenty series theme and see if the same issue exists there?
Let me know π
March 23, 2020 at 11:34 am #1207804Diederick
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>
<?phpecho ‘<p class=”price”>’.$price_html.'</p>
‘.$availiability.’‘.$price.’‘;
}March 23, 2020 at 11:56 am #1207815Leo
StaffCustomer SupportUnfortunately I’m not familiar with that script. Where did you get it from?
March 23, 2020 at 12:05 pm #1207828Diederick
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)March 23, 2020 at 12:22 pm #1207841Leo
StaffCustomer SupportUnfortunately I don’t.
You’d need to check with WooCommerce’ support to see if they are able to point you in the right direction.
March 23, 2020 at 12:25 pm #1207845Diederick
oke thanks for the help!
March 23, 2020 at 12:29 pm #1207849Leo
StaffCustomer SupportNo problem!
Sorry I couldn’t be more helpful.
March 23, 2020 at 12:44 pm #1207857Diederick
For those who are intrested in the solution, found this on stackoverflow
March 23, 2020 at 1:18 pm #1207881Leo
StaffCustomer SupportThanks for sharing!
-
AuthorPosts
- You must be logged in to reply to this topic.