• Hi,

    what are your hooks for updating post meta, i need it to replicate this function for wcfm when adding/updating product/s. I couldn’t find them.

    -this is for single product update and there is one for quick save.

    
    add_action('woocommerce_process_product_meta', 'woo_calc_my_discount', 99);
    function woo_calc_my_discount( $product_id ) {
    $_product = wc_get_product( $product_id );
    $regular = (float) $_product->get_regular_price();
    $sale = (float) $_product->get_sale_price();
    	
    if (!empty($sale)) {
    $discount = round( 100 - ( $sale / $regular * 100), 2 );
    update_post_meta( $product_id, '_discount_amount', $discount );
    }
    }
    

    We use this to pull products by percentage of discount.

    Thank you

    • This topic was modified 3 years, 10 months ago by levelupsa.
    • This topic was modified 3 years, 10 months ago by Yui. Reason: please use CODE button for code formatting
  • The topic ‘Hooks for updating post meta’ is closed to new replies.