本地的woocommerce rest api产品映像

时间:2018-12-13 13:34:02

标签: php wordpress rest woocommerce

我有一个woocommerce网站(https://example.com),我需要在localhost(xampp)上使用我的wordpress来控制该网站的产品... 我可以使用woocommerce的剩余api创建产品,但是我无法为此产品设置图片。每次我使用剩余api发送创建产品请求时,都会收到此错误:

stdClass对象([代码] => woocommerce_product_image_upload_error [消息] =>获取远程图像http://localhost/wordpress/wp-content/uploads/2018/08/6550-min.jpg时出错。错误:未提供有效的URL。。[数据] => stdClass对象([状态] => 400))

我该如何解决?

1 个答案:

答案 0 :(得分:0)

Wordpress拒绝对其他主机的呼叫。 即使位于同一台计算机上,Localhost还是与example.com不同的主机。

您可以使用http_request_host_is_external过滤器允许localhost:

add_filter( 'http_request_host_is_external', 'allow_localhost', 10, 3 );
function allow_localhost( $allow, $host, $url ) {
  if ( $host == 'localhost' ) {
    $allow = true;
  }
  return $allow;
}

您应该在主题的functions.php中添加以上代码。