Support » Plugin: WooCommerce » Update variation price by variation id

  • oscarpo

    (@oscarpo)


    Hi,i tried to update sale price in variation by aviation id .

    i try the following code

    update_post_meta($variation_id,’_sale_price’,$variation_cost);

    it is working in backend but in frontend and cart it is not effecting.
    Also i noticed that ‘display_price’ is displaying on front end and cart .

    I have product id , variation id . How i can update the variation price ?

    Please help .

    https://wordpress.org/plugins/woocommerce/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Anand Shah

    (@anandamd)

    You haven’t mentioned which version of WooCommerce you’re using. There are 3 keys in the latest version

    _regular_price
    _sale_price
    _price

    _price is used to display the price on the frontend. So you need to update 2 meta keys _sale_price and _price

    oscarpo

    (@oscarpo)

    Hi, Thank you friend . We are using WooCommerce 2.5.5 . What about ‘display_price’?

    oscarpo

    (@oscarpo)

    Is there any functions to update variation price and variation quantity by variation id?

    Other wise we need to update each post_meta manually . it consist of many
    for example

    _regular_price
    _sale_price
    _price
    display_price
    _min_variation_price
    _max_variation_price
    _min_variation_regular_price
    _max_variation_regular_price
    _min_variation_sale_price
    _max_variation_sale_price

    etc .

    oscarpo

    (@oscarpo)

    Also i notice that out of stock variation is not getting the code .

    for example
    ` $args=array(
    ‘post_type’ => ‘product’,
    ‘post_status’ => ‘publish’,
    ‘p’ =>$_POST[‘givenid’]
    );
    while($loop->have_posts()): $loop->the_post();
    $product_id=$_POST[‘givenid’];
    $product=wc_get_product($product_id);
    if( $product->is_type( ‘variable’ ) ){
    $variations_all = $product->get_available_variations($product);
    }
    endwhile;`

    Here $variation_all contains the variation details of instock item .

    How to get all the variation details whether it is instock or outofstock ?

    Plugin Author Mike Jolley

    (@mikejolley)

    display_price is not core. The min/max prices are not needed.

    Set the postmeta for _regular_price, _sale_price, _price only. _price should equal the current , active price (sale price if on sale).

    Anand Shah

    (@anandamd)

    Yes you’ll have to handle all those post meta manually. Have look at the code here to see how WooCommerce handles it : https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-product-variable.php#L726

    Ensure that in WooCommerce settings “Hide out of stock items” is not checked to get all items whether instock or outofstock.

    oscarpo

    (@oscarpo)

    Thank you all . but How to get all the variation details whether it is instock or outofstock ?

    Plugin Author Mike Jolley

    (@mikejolley)

    How about instead of using PHP code, you use our API? https://woothemes.github.io/woocommerce-rest-api-docs/

    oscarpo

    (@oscarpo)

    But i need to get the details in product loop , that’s why i am asking is this . Please help to solve this .

    Plugin Author Mike Jolley

    (@mikejolley)

    Edit:

    Solved. Need to delete transients…

    https://wordpress.org/support/topic/adding-a-product-variation-via-function-attributes-do-not-show-on-frontend/
    https://github.com/woocommerce/woocommerce/blob/master/includes/data-stores/class-wc-product-data-store-cpt.php#L644

    Hello

    I am having the same problem. I can also see the price on backend but nothing changed on frontend

    here is the code

    update_post_meta( $prod_id, ‘_regular_price’, ‘351’ );
    update_post_meta( $prod_id, ‘_sale_price’, ’91’ );
    update_post_meta( $prod_id, ‘_price’, ’91’ );

    Woocommerce 2.6.13
    WP 4.7.1

    The price will show on frontend if i save from admin…

    Is there any other place i need to sync those data?

    Cheers

    • This reply was modified 1 year, 3 months ago by  daknightteam. Reason: I found the answers
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Update variation price by variation id’ is closed to new replies.