• I would like to dynamically add a value to a custom attribute called “M/s per Dollar”. The value would take the product attribute (Speed), i.e, 8 M/s, and divide it by the product price, i.e., $2. This would leave the value to be 4 M/s/$, in the new field. I would like to do this for multiple products.

    essentially

    Poduct_attribute_SpeedperDollarprice = Product_attribute_Speed / Product_attribute_DollarPrice

Viewing 1 replies (of 1 total)
  • I got to this point… Copy and pasted from: https://wordpress.stackexchange.com/posts/238656

    I would like to generate a value for a WooCommerce product attribute, in this case spd (Speed per Dollar). The $speed is static and the price changes from time to time. I would like the value of the spd attribute to change according to the $price automatically.

        add_filter( 'woocommerce_attribute', 'SPD');
        function SPD(){
            global $product;
            $id = $product->id;
            $speed = $product->id , 'speed';
            $price = $product->price;
            $spd = ('$speed' / '$price');
        
            return $product->id , 'spd' = $spd
        }

    This is what i have so far, but It’s been a while since i wooked with hooks and functions for wordpress. any help is appreciated.

    • This reply was modified 8 years, 6 months ago by theweedwizard.
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Attribute Value Function’ is closed to new replies.