New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Product Variation visible if Price is Blank #5137

Closed
MadSpaniard opened this Issue Mar 15, 2014 · 6 comments

Comments

Projects
None yet
3 participants
@MadSpaniard
Copy link

MadSpaniard commented Mar 15, 2014

In WC 2.1.5 individual product variations are not visible (i.e. drop-down variation selections don't appear) if the variation price is blank. Shouldn't these be visible by default?

I tried adding the following snippet to functions.php which includes Call for Price similar to Mike Jolley's code (https://gist.github.com/mikejolley/1597957). However, this also make Add to Cart appear, which fails when clicked because the product is not purchaseable.

Is there a way to make the product variations visible but without the Add to Cart button?

/* Make Variation Visible */
add_filter('woocommerce_variation_is_visible', 'product_variation_always_shown', 10, 2);
function product_variation_always_shown($is_visible, $id){
    return true;
}

/* Display "Call for Price" instead of empty price */
add_filter('woocommerce_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variable_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variation_empty_price_html', 'custom_call_for_price');
function custom_call_for_price() {
     return 'Call for Pice';
}
@mikejolley

This comment has been minimized.

Copy link
Member

mikejolley commented Mar 17, 2014

The filter should be woocommerce_variation_empty_price_html but a patch is also needed.

@MadSpaniard

This comment has been minimized.

Copy link

MadSpaniard commented Mar 17, 2014

Thanks Mike, I tried the filter you suggest (woocommerce_variation_empty_price_html) instead of 'woocommerce_variation_is_visible', however then I'm back to where I started, which is that the variations where price is blank are no longer visible, meaning the variation selection drop-down field will not display any selection values for variations where price=blank.

@mikejolley

This comment has been minimized.

Copy link
Member

mikejolley commented Mar 17, 2014

You need both + the above commits.

@MadSpaniard

This comment has been minimized.

Copy link

MadSpaniard commented Mar 17, 2014

Mike - the filter you suggest (woocommerce_variation_empty_price_html) already appears in the snippet I mentioned with a call to 'custom_call_for_price'. Are you suggesting ALSO adding an additional filter on 'woocommerce_variation_empty_price_html' with a call to 'product_variation_always_shown'?

Sorry for the confusion. Here's the snippet again, note how 'woocommerce_variation_empty_price_html' is already at the bottom - are you suggesting ALSO adding it at the top?

/* Make Variation Visible */
add_filter('woocommerce_variation_is_visible', 'product_variation_always_shown', 10, 2);
function product_variation_always_shown($is_visible, $id){
    return true;
}
/* Display "Call for Price" instead of empty price */
add_filter('woocommerce_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variable_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variation_empty_price_html', 'custom_call_for_price');
function custom_call_for_price() {
     return 'Call for Pice';
}

mikejolley added a commit that referenced this issue Mar 20, 2014

@MadSpaniard

This comment has been minimized.

Copy link

MadSpaniard commented Mar 27, 2014

Hello Mike - I installed your excellent patch in WC2.1.6, and everything seems to work great. I now have product variations which are visible and selectable even when price=empty, and I also have the "Call for Price" displayed on variations where price is empty, and the Add to Cart is not shown for these empty-price items.

I'm far from being an expert, so I'm unsure of how to use your suggestion of is_purchaseable, but I've included the following in functions.php and this, plus your patch in WC2.1.6, seems to work perfectly together to produce the results I noted above, which is what I was hoping for:

/* Display Variation Selections on variable products with empty price */
add_filter('woocommerce_variation_is_visible', 'product_variation_always_shown', 10, 2);
function product_variation_always_shown($is_visible, $id){
    return true;
}
/* Display price = "Coming Soon" on products with empty price */
add_filter('woocommerce_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variable_empty_price_html', 'custom_call_for_price');
add_filter('woocommerce_variation_empty_price_html', 'custom_call_for_price');
function custom_call_for_price() {
     return 'Coming Soon';
}

Thanks for your help, best regards.

@vlapo

This comment has been minimized.

Copy link

vlapo commented Nov 24, 2014

Hi Mike,
We have a problem based on this commit. We have variable product with one variation (next two will be added later). We iterate over all available variations (in this case one variation) and this variation have 'html_price' set to empty string. Is that correct behavior?
Thnx for replay.
VlaPo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment