• Resolved devfenstru

    (@devfenstru)


    I am using a woocommerce to create a catalogue of products.
    I wanna change the price due to my custom fields value.
    On Front-end i will use JS + JQ and overwrite the container.
    But to add this price and overwrite the default price i need your help.
    I found a hook called ‘woocommerce_before_calculate_totals’. There i can overwrite the price. But i will need the fields values.

    Question #1: Can i acces the $_POST in this hook?
    If not:
    Question #2: Do woocommerce have a hook for creating the $product global with the products to add into cart? Where i can access a $_POST or its array in another variable?

    Thnx in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • It would be simplier to edit the WooCommerce template files, and print out the custom field value.

    For example on single product page create an override file:
    /wp-content/themes/xxxxxx/woocommerce/single-product/price.php

    https://docs.woocommerce.com/document/template-structure/

    And change this:<p class="price"><?php echo $product->get_price_html(); ?></p>

    to this:
    <p class="price"><?php echo get_post_meta($post->ID, 'custom_field_name', true);?></p>

    You also need to edit the category archive page.

    • This reply was modified 7 years, 12 months ago by beamkiller.
    Thread Starter devfenstru

    (@devfenstru)

    You did not understand me. I need to transform simple product to a variable just adding the price via my script. That is not a problem. The problem is that i need to acess the $_POST fields in WC hook woocommerce_before_calculate_totals

    Thread Starter devfenstru

    (@devfenstru)

    [RESOLVE ANSWER] [THIS IS THE SOLUTION]

    Problem is resolved.

    You can access $_POST in woocommerce_before_calculate_totals action.

    • This reply was modified 7 years, 12 months ago by devfenstru.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Searchin for woocommerce api help’ is closed to new replies.