Skip Navigation

[Resolved] Integrating WooCommerce Name Your Price Extenstion into CRED

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

Problem:

The issue here is that the user wanted to use the Name your Price plugin with our Toolset forms when users submit their own customised payment.

Solution:

The solution for this can be seen below.
https://toolset.com/forums/topic/integrating-woocommerce-name-your-price-extenstion-into-cred/#post-1090318

This support ticket is created 6 years, 4 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Shane 6 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#1089547

J S
woocommerce-name-your-price.jpg

Hi,

I created a site using your Classifieds site as a starting point. One change I am trying to make is to allow an option for people buying an ad to name their price. To do this, I want to use the Woo Commerce Name Your Price Extension. I've already set up the product and it works itself but it doesn't seem to work using the [woocommerce_checkout] shortcode. Is there another shortcode to use so that the variables can be selected and passed along?

I've read about the integration here: https://toolset.com/forums/topic/cred-woocommerce-and-name-your-price/

But the above post is from 2 years ago. I think this should be included in Toolset as others are asking for this as well.

I can provide you with a copy of the Woo Commerce Name Your Price Extension for testing purposes if neeeded, it is attached as a jpg, just rename to zip.

#1090318

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

We are mainly focused on supporting the Woocommerce core at the moment but you will need to open a feature request ticket in order for this to be added.

The plugin you suggests allows the user to suggest the price of the product they want to purchase correct? So you essentially want them to be able to name the price of the ad they are creating with Toolset Forms.

Have you tried this hook here ?

function es_donation_amount($post_id, $form_data) {
    // if a specific form
    if ($form_data['id']==FORM_ID) {
       $new_price = get_post_meta($post_id, 'CUSTOM_FIELD', true);
       $old_price = get_post_meta(PRODUCT_ID, '_regular_price', true);
       update_post_meta(PRODUCT_ID, '_price', $new_price, $old_price);
       update_post_meta(PRODUCT_ID '_regular_price', $new_price, $old_price);
    }
}
add_action('cred_before_save_data', 'es_donation_amount', 10, 2);
#1090345

J S

Hi,

Yes, well sort of, the Name Your Price Extension for Woocommerce allows users to checkout with whatever price they choose to pay. Hee is more info: https://docs.woocommerce.com/document/name-your-price/?_ga=2.97384600.669888449.1534949198-1430469594.1534949198

No I have not tried the hook you suggest. Can you give me a little more advice on how to implement it? I'm using the Snappy Snippets Plugin to implement any php changes but any instructions on exactly what else I'd need to do would be helpful.

Thanks

#1090399

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Based on this code all that is to change the values.

function es_donation_amount($post_id, $form_data) {
    // if a specific form
    if ($form_data['id']==FORM_ID) {
       $new_price = get_post_meta($post_id, 'CUSTOM_FIELD', true);
       $old_price = get_post_meta(PRODUCT_ID, '_regular_price', true);
       update_post_meta(PRODUCT_ID, '_price', $new_price, $old_price);
       update_post_meta(PRODUCT_ID '_regular_price', $new_price, $old_price);
    }
}
add_action('cred_before_save_data', 'es_donation_amount', 10, 2);

So where you see PRODUCT_ID you need to set it to the ID of the product that you are using. Secondly CUSTOM_FIELD needs to be the slug of the custom field that you will be using for the users to enter the price the of the item.

Thanks,
Shane