I am developing a plugin which is supposed to auto-fill the attributes text field.

There is a URL text field where user enters URL, on focus out I trigger a AJAX call through which I am able to save the data but I am looking to accomplish here is to show the saved data on highlighted fields as well.

enter image description here

I am using following code in a hook to display:

if( function_exists( 'wc_get_attribute_taxonomies' ) && ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) ) {

    $defaults = array();
    $name = wc_attribute_taxonomy_name( $tax->attribute_name );
    foreach ( $attribute_taxonomies as $key=>$tax ) {
                $defaults[ $name ] = array (
                    'name' => $name,
                    'value' => 'thisTextShouldAppearInHighlightedFieldsOfScreenShot',
                    'position' => $key+1,
                    'is_visible' => 1,
                    'is_variation' => 1,
                    'is_taxonomy' => 1,

            update_post_meta( $post->ID , '_product_attributes', $defaults );

Any help would be greatly appreciated!


I am assuming the ID of that text filed, is url-field here is the JS code

$("#url-field").keyup(function(event) {
     var url_val=$("#url-field").val();
            url: ajaxurl,
            data: {
                namefiled : namehere,
                postid : postidhereYouCangetItIHope  
               alert("Success, you can remove me :-) ");

Here comes PHP, put this in functions.php

function use_someprefix_update_url(){
    $defaults = array();
    $defaults[ $_POST['namefiled'] ] = array (
                    'name' => $_POST['namefiled'],
                    'value' => $_POST['search_string'],
     update_post_meta( $_POST['postid'] , '_product_attributes', $defaults );

Also this Hook also :

add_action('wp_ajax_use_someprefix_update_url', 'use_someprefix_update_url');

P.S : You have to do validation stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.