// SELECT ATTRIBUTE // ?> <label class="field"><b><?php _e('Attribute', 'woocommerce-molds'); ?> :</b> <select name="attribute" onchange="this.form.submit()" id="selected_attribute"> <option value="default"><?php _e('Select an attribute', 'woocommerce-molds'); ?> </option> <?php ## Let's get the product id as it will be useful later ## $the_id = $mold->pm_get_product_id(); ## Let's do the same for the mold attribute, if it's already defined, we'll need it ## $the_attribute = $mold->pm_get_mold_attribute(); ## We already got the product name temporary registered, if it's user value we can get the linked attributes ## if ($the_name != "Product") { global $wpdb; // We connect to the DB to get the attributes $rows = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM " . $wpdb->prefix . "postmeta WHERE meta_key = '_product_attributes' AND post_id = '%d'", $the_id)); // Check for errors if (!$rows) { echo 'Could not run query: ' . mysql_error(); } // Let's foreach this data foreach ($rows as $row) { $attributes = maybe_unserialize($row->meta_value); foreach ($attributes as $attribute) { $attribute_name = $attribute['name']; ## If an attribute has already been selected we keep it selected ##