Поддержка WooCommerce Цена вариации по умолчанию (поменять местами блоки)

  • Есть код который выставляет цену вариации товара по умолчанию.
    Он рабочий, только теперь у меня цена под вариацией, а нужно вернуть над)

    add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 );
    add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 );
    function custom_price_format( $price, $product ) {
    
    // 1. Variable products
    if( $product->is_type('variable') ){
    
    // Searching for the default variation
    $default_attributes = $product->get_default_attributes();
    // Loop through available variations
    foreach($product->get_available_variations() as $variation){
    $found = true; // Initializing
    // 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;
    }
    }
    // When it's found we set it and we stop the main loop
    if( $found ) {
    $default_variaton = $variation;
    break;
    } // If not we continue
    else {
    continue;
    }
    }
    // Get the default variation prices or if not set the variable product min prices
    $regular_price = isset($default_variaton) ? $default_variaton['display_price']: $product->get_variation_regular_price( 'min', true );
    $sale_price = isset($default_variaton) ? $default_variaton['display_regular_price']: $product->get_variation_sale_price( 'min', true );
    }
    // 2. Other products types
    else {
    $regular_price = $product->get_regular_price();
    $sale_price    = $product->get_sale_price();
    }
    
    // Formatting the price
    if ( $regular_price !== $sale_price && $product->is_on_sale()) {
    // Percentage calculation and text
    $percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
    
    $price = '<del>' . wc_price($regular_price) . '</del> <ins>' . wc_price($sale_price) . $percentage_txt . '</ins>';
    }
    return $price;
    }
    

    Пробовал remove_action и через js prepand. Но чет не аллеша.

    • Тема изменена 4 года, 11 месяцев назад пользователем jaaz.

    Страница, с которой нужна помощь: [войдите, чтобы увидеть ссылку]

Просмотр 1 ответа (всего 1)
  • Вроде получилось через appendTO, но теперь у меня на странице вариантативного товара две цены…

Просмотр 1 ответа (всего 1)
  • Тема «Цена вариации по умолчанию (поменять местами блоки)» закрыта для новых ответов.