Support

Account

Forum Replies Created

  • Calculate the new price including tax

    $new_price = $price * (1 + $tax_rate / 100);

    OR change the price

    $price *= 1 + $tax_rate / 100; // in your case 1 + 20/100 = 1.2

    Taxes may vary from product to product. You can get actual tax rate from Woo.

  • Wrote an answer, but it disappeared. I’ll write again.

    I have checked on my project. Everything works. I will write how I do, compare with how you do.

    1. Create a group of fields (in my case for posts)
    2. Create a post. I fill in the created fields.
    3. open the page template for the post. I add the code

    
    $video = get_field('video_section');
    
    var_dump($video);
    

    4. I open the post and see this

    
    array(3) { ["video_link"]=> string(18) "https://my-link.com" ["video_header"]=> string(5) "Title" ["video_subheader"]=> string(8) "Subtitle" }
    

    What are you doing differently?

  • Hi!

    I have tested this on my project. Everything works. I will write as I did so that you can compare.

    1. Created a field Group of fields for the required post type (in my case for posts)
    2. Edited the post, filled in the data in the subfields
    3. In the template for the post added the code

    <? php $video = get_field('video_section');
    
    var_dump($video); ?>
    

    4. Go to the post page and see this

    
    array(3) { ["video_link"]=> string(18) "https://my-link.com" ["video_header"]=> string(5) "Title" ["video_subheader"]=> string(8) "Subtitle" }
    

    What are you doing differently?

  • It’s strange. I would try creating a new field group and checking. You should also pay attention to the field name. Try to replace it, there are conflicts with plugins.
    You can also check the database. Is there data for this group of fields.

  • Hi!

    Check data. What do you see?

    
    var_dump($video);
    
  • You’re welcome! 🙂

    The price per kilogram will be shown in the backend after viewing the product in the store. This is due to the field updating only after the update field function is launched, which will be launched during the loading of the product page.
    If you need to automatically calculate the price per kg in the admin panel, then you can use JS. This is a forum for ACF fields, so I wrote how to solve your problem with it.
    If you do it in the backend, you just write a script for calculating the price. You specify where to get the weight, where to get the price and where to insert the result.

  • Hi, Nayrod!

    Have you already created the ‘price_per_kilo’ field in the ACF fields for products?

    If you change files in the plugin folder itself, then after the update all edits will disappear. So you need a new folder in your theme folder.

    You need to create a new folder in your theme. Like this directory

    / wp-content / themes / your-child-theme / woocommerce / single-product /

    Copy the price.php template from the / wp-content / plugins / woocommerce / templates / single-product directory to your new folder (/ wp-content / themes / your-child-theme / woocommerce / single-product /)

    Open the price.php template and paste my code (don’t duplicate the global $product).

    If the code doesn’t work try this. Оpen the product in the admin panel. An empty “price_per_kilo” field that you created at the beginning should appear. Make sure the price and weight (in delivery) are specified. Save the product. Go to the front-end of the product page, the code should work.

    If there are any mistakes, write down which ones. Write down, step by step, what you are doing and in which files.

    It works in my local project. Good luck!

  • Hi!

    For example

    1. Create an ACF field (price_per_kilo) for Product.

    2. In Woo template use something like this

    
    global $product;
    
    $price = $product->get_price();
    
    $weight = $product->get_weight();
    
    $id = $product->get_id();
    
    $value = 1000 * $price / $weight;
    
    update_field('price_per_kilo', $value, $id); // this code updates data for this field
    
    the_field('price_per_kilo', $product->$id ); //show price per kilo
    
    
  • I made a typo. Correct use of the function

    
    get_term_link( $term, $taxonomy = '' ); // $term is the term object, ID, or slug whose link will be retrieved
    

    In this case, ‘featured_page_link’ should return an ID (integer) or object term.

  • Please tell more about the problem.

    Which type of ACF field are you using.

    Do you use the code where the post number is already defined? May be it’ll be work (you need to add post id)

    
    the_term_link( get_field( 'featured_page_link', $post_id ) );
    
  • Hi Nayrod!

    You can do this with the update_field function.

    https://www.advancedcustomfields.com/resources/update_field/

    update_field($selector, $value, [$post_id]);

    $selector is your price/per kilo field name
    $value is calculated price
    $post_id is current product ID

    You can use a function in your function.php file to calculate the price ($value).

  • Hi, Jeremy!

    You don’t need to use an ID because you are using a loop and get the current post every time.
    But you need to change the value of the href attribute like this

    
    $the_query = new WP_Query( $args );
      if ( $the_query->have_posts() ) : 
     
        while ( $the_query->have_posts() ) : $the_query->the_post(); 
           $url = parse_url( get_field( 'vibe_url') );
           $btn_url = $url['host'] . $url['path'];
        ?>
        <a class="wp-block-button__link" href="<?php the_field('vibe_url'); ?>"><?php echo $btn_url; ?></a>
        <?php endwhile; ?>
      <?php endif;
    
    wp_reset_postdata(); // reset query
    

    And don’t forget reset your query to avoid errors in future queries.

    Let me know if it works correctly or not.

  • Hi!

    I think you can use this

    
    $url = parse_url( get_field( 'vibe_url') );
    $btn_url = $url['host'] . $url['path'];
    
    
  • Hello! Thank John so so so much! Everything works as it should!

  • Thank! I was just looking for this! Just can’t understand how to correctly insert this code into my code? Can you tell me please?

Viewing 18 posts - 1 through 18 (of 18 total)