Skip to content
Advertisement

woocommerce_wp_select options array from product attribute terms

I am trying to create a drop down list box in woocommerce but have it populated with data from the database.

I have the majority of the code working but the portion to populate the list box is killing me. This is what I have so far.

JavaScript

This should pull information from the “ATTRIBUTES” section in WooCommerce. I created a Breed Attribute and put a few dog breeds in there.

Any direction is greatly appreciated!

I know the ‘options’ section on the array is totally wrong but I put it there so you would know what I am trying to accomplish.

Advertisement

Answer

I have revisited your code a bit. The main problem was in the select <option> array.

You will see in the code the changes:

JavaScript

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested in WooCommerce 3+ and works. You will get something similar to this (with your breeds):

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement