我正在一个销售珠宝产品的门户网站上。汇率计算取决于每日更新的黄金/白银市场汇率。 我有要计算的公式。 产品费率=金属费率+制作费+税金
每日金属费率变化 我想要实现一些功能,以便通过更新金属费率来更新所有产品费率。
有可用的内置功能插件吗? 谢谢。
答案 0 :(得分:1)
您可以在function.php中使用它
首先创建价格更新功能
<?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();
}
现在您需要做的就是在wordpress中设置cron作业,您可以使用动作钩子来完成
add_action( 'is_add_every_day', 'update_product_price' );
安排尚未执行的操作
if ( ! wp_next_scheduled( 'is_add_every_day' ) ) {
wp_schedule_event( time(), 'every_day', 'is_add_every_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;
}
答案 1 :(得分:0)
Product import-export for WooCommerce插件可让您轻松地批量更新产品价格。确切地说,它提供了用定义的值更新产品的特定值的规定。例如,要将值5与商店中所有产品的价格相加,只需指定“ price + 5”即可将总价格加5(通过评估字段功能)。该插件还可以使用Cron提供产品的自动导入和导出。