• Resolved mittultechnobrave

    (@mittultechnobrave)


    I am using some custom logics to show or hide variations in variable products using this hookwoocommerce_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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Thu P. a11n

    (@thup90)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution to your problem! If you have further questions, please feel free to open a new topic.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress WooCommerce get_sign_up_fee based on available variations’ is closed to new replies.