woocommerce_add_cart_item_data return internal server error
-
Hey,
i want to add a custom price with woocommerce_add_cart_item_data, when i then use a mutation like:
mutation MyMutation {
addToCart(input: {productId: 24, extraData: "100"}) {
cartItem {
product {
node {
id
}
}
extraData {
id
}
}
}
}i get a internal server error with: “Cannot use a scalar value as an array”
my plugin code looks like:
function add_width_data_field_to_product($cart_item_data, $product_id, $variation_id) { $writeToFile = fopen("cartdata.txt", "w"); fwrite($writeToFile, "test"); fclose($writeToFile); $product = wc_get_product($product_id); $price = $product->get_price(); $cart_item_data["calculatedPrice"] = $price * 2; return $cart_item_data; } add_filter('woocommerce_add_cart_item_data', 'add_width_data_field_to_product', 10, 3);
It would be really nice if someone has a hint, what I make wrong here.
kindly,
felix
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘woocommerce_add_cart_item_data return internal server error’ is closed to new replies.