Woocommerce REST API not considering discounts and coupons

In your coupon_lines array, each item in the array needs 2 properties: code (the coupon code itself) and amount, which is either a flat fee (eg 50.00 off) or a discount (eg 10% off). Your structure ends up looking like: “coupon_lines”: [ { “code”: “MYCODE1”, “amount”: “10.00” }, { “code”: “MYCODE2”, “amount”: “25.00” } ] … Read more

wp_insert_user if user exists

When updating a user with: $user_id = wp_update_user( $userdata ); you need to have the user ID set within $userdata. Also make sure to validate the $user_id output of wp_update_user() as it can be either an integer or an instance of WP_Error, before using it in update_user_meta(). One can use is_wp_error( $user_id ) to check … Read more

Update Custom Post Type Metadata Wp Rest API

If you’re supplying the request data/body like so, which is an array of metadata: { metadata: { wishlist_array: “add this”, foo: “bar baz” } } and you want to update only the wishlist_array metadata, then you could do: // In your case, $field_value is the `metadata` value and $data is a WP_Post object. ‘update_callback’ => … Read more

wordpress api make 2 custom post type with single request

Please write function for get post by title function get_page_by_post_title( $page_title, $output = OBJECT, $post_type=”page” ) { global $wpdb; $sql = $wpdb->prepare( ” SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = %s ORDER BY ID DESC “, $page_title, $post_type ); $page = $wpdb->get_var( $sql ); if ( $page ) { return get_post( … Read more