Skip Navigation

[Resolved] Woocommerce + CRED : adding a featured product with a CRED

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to set WooCommerce product as featured product using CRED form

Solution:
You can use CRED hook "cred_save_data" to set the WooCommerce product as a "featured" product.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/woocommerce-cred-adding-a-featured-product-with-a-cred/#post-631281

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Charlie 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#631256

Woocommerce + CRED
I am adding a simple product with a CRED form and looking for a way to set the Featured product flag. Is this possible using CRED API hook cred_save_data? If so, can you supply the code?

#631281

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

With WC 3.X.X featured product status is saved with hidden taxonomy product_visibility.

You should use following code:

add_action('cred_save_data','func_set_featured_product',10,2);
function func_set_featured_product($post_id,$form_data) {
    
if ($form_data['id']==9999) {
  
            $terms = array( 'featured' );
            wp_set_object_terms( $post_id, $terms, 'product_visibility' );

    }
}

Where:
- Replace '9999' with your CRED form ID

#631606

That worked a treat. Thank you, Minesh.