pop out
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: [WooCommerce] WC Rest API overrides wp_termmeta meta valueMeta key is added either in admin
add_action( 'created_product_cat', 'save_custom_taxonomy_image', 10, 2 ); function save_custom_taxonomy_image ( $term_id, $tt_id ) { if( isset( $_POST['brand_image'] ) && '' !== $_POST['brand_image'] ){ $image = $_POST['brand_image']; add_term_meta( $term_id, 'brand_image', $image, true ); } }Or by REST API
add_action('rest_api_init', 'register_rest_field_for_custom_taxonomy_location'); function register_rest_field_for_custom_taxonomy_location() { register_rest_field( 'product_cat', 'brand_image', array( 'get_callback' => 'brand_image_get_term_meta_field', 'update_callback' => 'brand_image_update_term_meta_field', 'schema' => null)); } //WRITE function brand_image_update_term_meta_field( $value, $object, $field_name ) { if ( ! $value ) { return; } $id = (int) $object->term_id; $upload = wc_rest_upload_image_from_url( esc_url_raw( $value['src'] ) ); if ( is_wp_error( $upload ) ) { return $upload; } $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); return update_term_meta( $id, 'brand_image', $image_id ); } //READ function brand_image_get_term_meta_field( $object, $field_name, $request ) { $meta = get_term_meta( $object[ 'id' ], $field_name, true); $results = array( 'id' => $meta, 'src' => wp_get_attachment_url($meta) ); return $results; }Forum: Plugins
In reply to: [WooCommerce] Hand Picked products: Critical errorFound the plugin responsible for it.
WP Extended Search causes this issue.- This reply was modified 5 years, 2 months ago by pop out.
Viewing 2 replies - 1 through 2 (of 2 total)