Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 13:00 9:00 – 13:00 9:00 – 13:00 8:00 – 12:00 8:00 – 12:00 -
- 14:00 – 17:00 14:00 – 18:00 14:00 – 18:00 13:00 – 17:00 13:00 – 17:00 -

Supporter timezone: Europe/Zagreb (GMT+02:00)

This topic contains 8 replies, has 2 voices.

Last updated by Bruno Kos 1 year, 4 months ago.

Assisted by: Bruno Kos.

Author Posts
April 24, 2024 at 3:47 pm #15561664

dawidZ-5

I'm creating and updating products variations using the woocommerce api, but I cannot set a custom price for the given currency.
My request body:
```
{
"regular_price": "200",
"manage_stock": true,
"stock_status": "instock",
"stock_quantity": "1000",
"image": {
"id": 34300
},
"custom_prices": {
"PLN": {
"regular_price": 100
}
},
"attributes": [
{
"id": 4,
"name": "Color",
"slug": "pa_attribute-1",
"option": "Dark beige"
}
],
"meta_data": [
{
"key": "_product_image_gallery",
"value": "26330,35520,26240,31080"
}
]
}
```

April 25, 2024 at 8:13 am #15563855

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Thank you for contacting WPML support!

Your code does look correct to me, not sure what is missing.

Can you perhaps record a video using tool such as hidden link to show us once you hit the request and whether the prices got changed in the backend and frontend?

Is there any error message that shows up indicating that the request has failed?

Also if you try something like:

{
  "regular_price": "55.00"
}

Does it work even for the original product?

Regards,
Bruno Kos

April 25, 2024 at 10:11 am #15564641

dawidZ-5

Hi,
I tested this with a simple product by sending a PUT request to the endpoint /wp-json/wc/v3/products/36276, and it doesn't work either.

with this body:
{
"regular_price": "201",
"manage_stock": true,
"stock_status": "instock",
"stock_quantity": "1000",
"custom_prices": {
"PLN": {
"regular_price": 100
}
}
}
I also tried sending custom_prices.PLN.regular_price as a string instead of int

I can successfully update any value except custom_prices, there is a meta key _wcml_custom_prices_status in the output and it is always value 0

I have enabled multicurrency in WPML and can set a custom price manually, but not through the api.

April 25, 2024 at 11:56 am #15565351

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

Would you be willing to provide me with WordPress and FTP credentials so I could investigate the issue directly?

Also, can you install a plugin such as hidden link or tell me where can I run this request in your site? Also tell me for which product.

You could even record a video using tool such as hidden link to show us how are you doing it.

https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

I marked your next reply as private so that you can safely add credentials.

April 26, 2024 at 7:51 am #15568340

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

Can you tell me if you can reproduce this issue here:
hidden link

I've installed hidden link, let me know if not possible to reproduce it here.

April 26, 2024 at 10:28 am #15570094

dawidZ-5

I added the EUR currency and then added a test product.
Then in postman I made a PUT request with body
{
"regular_price": "202",
"manage_stock": true,
"stock_status": "instock",
"stock_quantity": "1000",
"custom_prices": {
"EUR": {
"regular_price": 100
}
}
}

and it didn't work here either

April 26, 2024 at 12:09 pm #15570506

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

Escalated to 2nd Tier, I will keep you posted.

May 3, 2024 at 1:58 pm #15591653

dawidZ-5

Any update on this?

May 6, 2024 at 5:02 am #15594994

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

We found this to be a bug in WPML but we have no fix for it yet.

But you can try this workaround:

1. Set the custom field `_wcml_custom_prices_status` to `1` to enable custom prices for the product.
2. Define the prices in USD if EUR is the default currency and USD is secondary. Use the keys `_regular_price_USD`, `_sale_price_USD`, and `_price_USD` for regular, sale, and actual prices respectively.
3. Send your product data. Ensure your request includes meta data for prices in different currencies.

use Automattic\WooCommerce\Client;

$wc = new Client( $url, $key, $secret, $options );

$data = [
    'name' => 'REST Product with custom prices',
    'type' => 'simple',
    'description' => 'Test Product for REST',
    'regular_price' => '10',
    'sale_price' => '5',
    'lang' => 'en',
    'meta_data' => [
        [
            'key' => '_wcml_custom_prices_status',
            'value' => '1',
        ],
        [
            'key' => '_regular_price_USD',
            'value' => '8',
        ],
        [
            'key' => '_sale_price_USD',
            'value' => '4',
        ],
        [
            'key' => '_price_USD',
            'value' => '4',
        ],
    ]
];

var_dump( $wc->post( 'products', $data ) );