Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 宇REST API输出销售价格错误_Wordpress_Api_Rest_Woocommerce - Fatal编程技术网

Wordpress 宇REST API输出销售价格错误

Wordpress 宇REST API输出销售价格错误,wordpress,api,rest,woocommerce,Wordpress,Api,Rest,Woocommerce,我遇到了很大的麻烦,因为在现场我刚刚发现我们的API有奇怪的输出,因此无法将产品与我们的ERP和CRM同步。我认为问题出在这段代码中,但我不知道如何保存它,因为它在frotnend上工作,但从API Json输出中排除它 //PROCENT SPARET PÅ SIMPLE PRODUCT add_filter( 'woocommerce_format_sale_price', 'woocommerce_custom_sales_price', 10, 3 ); function woocomm

我遇到了很大的麻烦,因为在现场我刚刚发现我们的API有奇怪的输出,因此无法将产品与我们的ERP和CRM同步。我认为问题出在这段代码中,但我不知道如何保存它,因为它在frotnend上工作,但从API Json输出中排除它

//PROCENT SPARET PÅ SIMPLE PRODUCT
add_filter( 'woocommerce_format_sale_price', 'woocommerce_custom_sales_price', 10, 3 );
function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) {
// Getting the clean numeric prices (without html and currency)
$_reg_price = floatval( strip_tags($regular_price) );
$_sale_price = floatval( strip_tags($sale_price) );

// Percentage calculation and text
$percentage = round( ( $_reg_price - $_sale_price ) / $_reg_price * 100 ).'%';
$percentage_txt = '(' . __('-', 'woocommerce' ) . $percentage . ')';

$formatted_regular_price = is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price;
$formatted_sale_price    = is_numeric( $sale_price )    ? wc_price( $sale_price )    : $sale_price;

echo '<del>' . $formatted_regular_price . '</del> <ins>' . $formatted_sale_price ."<span class='percentage_save'>". $percentage_txt . "</span>".'</ins>';
}
//PROCENT SPARET PÅSIMPLE乘积
添加过滤器(“woocommerce\u格式\u销售价格”,“woocommerce\u自定义\u销售价格”,10,3);
功能商业\自定义\销售\价格($price、$常规\价格、$sale\价格){
//获取干净的数字价格(无html和货币)
$\u reg\u price=floatval(带标签($regular\u price));
$_sale_price=floatval(带标签($sale_price));
//百分比计算和文本
$percentage=四舍五入($注册价格-$销售价格)/$注册价格*100)。'%';
$percentage_txt='('.'percentage.'('-','woocommerce').$percentage');
$format_uregular\u price=是数字($regular\u price)?wc_uprice($regular\u price):$regular\u price;
$formatted_sale_price=是否为数字($sale_price)?wc_price($sale_price):$sale_price;
回显“.$FORMATED\ U REQUAL\ U price.”.$FORMATED\ U sale\ U price.”.“$PERCENTION\ U txt.”;
}
这里可以看到输出中的问题

有人知道如何快速解决这个问题吗?提前谢谢

/* you can user this hook function for above issue */

  add_filter('woocommerce_product_get_sale_price', 'custom_price_func', 10, 2 );

  function custom_price_func( $price, $product){
     /* write your stuff here */
     return $price;
  }