有没有一种方法使用API​​网址设立产品实时价格? [英] Is there is a way to set up live prices of products using an api url?

查看:159
本文介绍了有没有一种方法使用API​​网址设立产品实时价格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来这个论坛。我目前工作的一个新的项目,这需要根据从API网址的最新价格定价的产品。这可能与Word preSS?我一直在使用Woocommerce插件创建网站:

I am new to this forum. I am currently working on a new project, which requires the products to be priced according to the latest pricing from an API url. Is this possible with WordPress? I have created the site using Woocommerce plugin:

的https://word$p$pss.org/plugins/woocommerce/

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

应该是很简单的,你可以使用 woocommerce_before_calculate_totals 行动挂钩覆盖产品的价格。

Should be quite straight forward, you can use woocommerce_before_calculate_totals action hook to override the product price.

add_action( 'woocommerce_before_calculate_totals', 'custom_price' );

function custom_price( $cart ) {

    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

        $_product = $cart_item['data'];

        // call the API here and override product price
        $_product->price = $custom_price;        

    }
}

这篇关于有没有一种方法使用API​​网址设立产品实时价格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆