WordPress WooCommerce get_sign_up_fee based on available variations
-
I am using some custom logics to show or hide variations in variable products using this hook
woocommerce_get_children
https://stackoverflow.com/a/67804835/6829420 and its working fine as per my expectations.However, I am having wrong ‘Sign Up Fee’ in the variable product page because its keep getting the values from one of my hidden variations. Here below is my try and what I have done so far.
add_filter( ‘woocommerce_subscriptions_product_price_string’, ‘subscr_product_price_string’, 10, 3 );
function subscr_product_price_string( $subscription_string, $product, $include ){if (is_admin() || (! $product->is_type( ‘variable-subscription’ ))) return $subscription_string;
if ( $include[‘sign_up_fee’] && $product->get_sign_up_fee( $product ) > 0 ) {
$available_variations = $product->get_available_variations();
echo count($available_variations);echo $product->get_sign_up_fee();
exit;
//echo $prices = get_price_sign_up_fee($product);
exit;
}`Say for example, I have 3 variations “Blue, Yellow and Green” and I have hide “Blue” and go to variation product page.
Then If I do this,
$available_variations = $product->get_available_variations();
echo count($available_variations);Then its showing 2 but my
echo $product->get_sign_up_fee();
keep getting value from “Blue” which has the lowest value but this is wrong value.Can someone guide me how can I get sign up values based on my available variations only.
I have already updated default **From** value using below code with
woocommerce_variable_price_html
hook and its working fine as its getting value based on available variations.function updateFromDefaultValue($price, $product) {
$prefix = sprintf(‘%s: ‘, __(‘From’, ‘iconic’));
$min_price_regular = $product->get_variation_regular_price(‘min’, true);
$min_price_sale = $product->get_variation_sale_price(‘min’, true);
$max_price = $product->get_variation_price(‘max’, true);
$min_price = $product->get_variation_price(‘min’, true);
$price = ($min_price_sale == $min_price_regular) ?
wc_price($min_price_regular) :
‘‘ . wc_price($min_price_regular) . ‘‘ . ‘‘ . wc_price($min_price_sale) . ‘‘;return ($min_price == $max_price) ?
$price :
sprintf(‘%s%s’, $prefix, $price);
}add_filter(‘woocommerce_variable_price_html’, ‘updateFromDefaultValue’, 10, 2);
Thanks
- This topic was modified 3 years, 7 months ago by .
- This topic was modified 3 years, 7 months ago by .
- This topic was modified 3 years, 7 months ago by .
- This topic was modified 3 years, 7 months ago by .
- This topic was modified 3 years, 7 months ago by .
- This topic was modified 3 years, 7 months ago by .
- The topic ‘WordPress WooCommerce get_sign_up_fee based on available variations’ is closed to new replies.