skip to Main Content

I am working on a portal which sale jewelry products. The rate calculation is depend on Gold/silver market rate which update daily.
I have formula to calculate for example.
Product rate = Metal rate +making charges+tax

Metal rate change daily
I want implement functionality which allow me to update all product rates by updating metal rates.

is there any built-in feature , plugin available ?
Thank you.

2

Answers


  1. Product import-export for WooCommerce plugin allows you to bulk update product price effortlessly. To be precise, it gives provision to update a particular value of a product with a defined value. For example, to add a value 5 with the price of all products of your store, just specify “price+5” which adds 5 to the total price (via evaluation field functionality). The plugin is also equipped to provide automatic import and export of products using Cron.

    Login or Signup to reply.
  2. You can use this in function.php

    First create a function for price update

    <?php
    function update_product_price(){
    $args = array(
      'post_type' => 'product',
      'posts_per_page' => -1
    );
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
      while ( $loop->have_posts() ) : $loop->the_post();
        global $product;
        //get metal rate,making charge and tax
        $product_rate = $metal_rate + $making_charge + $tax;
        //update product price
        update_post_meta($product->get_id(), '_regular_price', (float)$product_rate);
        update_post_meta($product->get_id(), '_price', (float)$product_rate);
    
      endwhile;
    }
    wp_reset_query();
    }
    

    Now all you need to do is set cron job in wordpress you can do it using action hook

    add_action( 'is_add_every_day', 'update_product_price' );
    

    Schedule an action if it’s not already scheduled

    if ( ! wp_next_scheduled( 'is_add_every_day' ) ) {
        wp_schedule_event( time(), 'every_day', 'is_add_every_day' );
    }
    

    Add a new interval of day

    // See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
    add_filter( 'cron_schedules', 'is_add_every_day' );
    function isa_add_every_three_minutes( $schedules ) {
        $schedules['every_day'] = array(
                'interval'  => 24*60*60,
                'display'   => __( 'Every day', 'textdomain' )
        );
        return $schedules;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search