Support » Plugin: WooCommerce » Extreme difficulty with variable products

  • jharper01

    (@jharper01)


    Hi all, I am trying to help set up Woocommerce for a photographer friend. Their website will serve primarily as a portfolio but visitors will also be able to order photo prints. As the primary function of the site isn’t a store, it’s best that there is a single Woocommerce product, ‘Order photo prints’, from which the user can select the ‘photograph’ and ‘size’ (these are the two attributes I’ve created).

    The values of ‘photograph’ are: Photograph 1, Photograph 2.
    The values of ‘size’ are: A0, A1, A2, A3, A4.

    The size value should affect product price, weight and dimensions. The photograph value should affect the product image. The photograph and size values taken together should only be used to determine whether the product is in stock (not all photographs will be available in all sizes).

    But I can’t set it up this way. In the variations tab: ‘Photograph 1, A4’ overrides ‘Any photograph.. A4’ and ‘Photograph 1.. Any size’. In other words a variation using both form values overrides variations of single form values, even if certain fields (price, product image etc) aren’t set in the variation with both form values.

    The only way I can see this working is by setting the product image, weight, dimensions, AND price in ‘Photograph 1, A0’, ‘Photograph 1, A1’, ‘Photograph 1, A2’ … etc. This is very cumbersome and awkward. Is there a way to make the values I set for the individual sizes and photographs override the values for each photograph/size combination, with the exception of stock status?

    Hopefully I’ve communicated the issue clearly.

    • This topic was modified 4 years ago by jharper01.
Viewing 2 replies - 1 through 2 (of 2 total)
  • anphira

    (@anphira)

    @jharper01 there are some photography themes and plugins which are designed for photographers selling prints. That might work better for your solution.

    As far as how Woo works with variations: a specific value will ALWAYS override a group value. So “any photo, size A4” is supposed to be overridden by “photo 1, size A4”. The “photo 1, size A4” is more specific, so should override.

    If you want things to get rather fancy and programmatically set certain values, then you’ll need to hook into some of the PHP functions. There are PHP functions which run on every save.

    For example, here is a function I wrote which won’t allow a product to be published unless a featured image is set. Similar types of functions can be written to automatically set values, but you need to know PHP or hire someone who does.

    /***********************************
     * Require image to publish product
     ***********************************/
    function on_all_status_transitions( $new_status, $old_status, $post ) {
    
        /* If new status is publish and post type is product, then require featured image */
        if ( $new_status == 'publish' && !empty($post->ID) && in_array( $post->post_type, array( 'product') ) ) {
            if( ! has_post_thumbnail($post) ) {
                $post->post_status = 'draft';
    
                // unhook this function so it doesn't loop infinitely
                remove_action('transition_post_status',  'on_all_status_transitions' );
    
                wp_update_post($post);
    
                // re-hook this function
                add_action('transition_post_status',  'on_all_status_transitions', 10, 3 );
            }
        }
    }
    add_action(  'transition_post_status',  'on_all_status_transitions', 10, 3 );
    gyulai.zoltan

    (@gyulaizoltan)

    Hi use https://codecanyon.net/item/woocommerce-extra-product-options/7908619

    this offloads all these variables to a template.
    So later on if you change prices or add sizes etc, you only edit the template once.

    I am not related to the dev but this saved my life 🙂

    let me know if you liked it
    Zoltan

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Extreme difficulty with variable products’ is closed to new replies.