Saltar navegación

[Resuelto] Cred commerce with a product define by a custom field

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Cred commerce with a product define by a custom field

Solution:
To set the product ID using the custom field - you should use the CRED generic field to add the product ID.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/cred-commerce-with-a-product-define-by-a-custom-field/#post-627605

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_add_product_to_cart

This support ticket is created hace 6 años, 10 meses. 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)

Etiquetado: 

Este tema contiene 8 respuestas, tiene 3 mensajes.

Última actualización por Pat hace 6 años, 9 meses.

Asistido por: Minesh.

Autor
Mensajes
#627050

Pat

Hello,

I have created a Cred commerce. Inside this Cred, I have a custom field where I have the post ID of the product to link with the Cred commerce.

But currently, this custom field is numerical and is not recognized by the mecanism inside the Cred (The form specifies the product according to the value of this custom field: ). Nothing appears in the select box.

How can I use a numerical field to define the product ID to link with ?

Regards
Pat

#627189
CRED-commerce1.JPG

Dear Pat,

How do you setup the numerical custom field? How do you put it into CRED form?

The CRED commerce option " The form specifies the product according to the value of this custom field" only work for the custom select field created with Types plugin, for example, you can try this:

1) Make sure you are using the latest version of Types + CRED + CRED commerce plugins

2) Create a custom select field with Types plugin, each option value is a product ID

3) Put it into CRED form, and try again, I have tried it in my localhost, it works fine, see screenshot CRED-commerce1.JPG

#627208

Pat

Hi Luo,

Thanks for your return.
What you propose in working fine. That means if I have a select or radio field inmy Cred, it is recognized and can serve to define the product linked to the Cred form.

My issue isthat the field I want to use for defining the product is a numerical field. So, either there is a possibility to use it or I will need to change its format and replace it by a select field for example. I would prefer to keep the numerical field as I need to manage the numerical content of this field in another part of the site.

Let me know
Regards
Pat

#627214

As you can see, there isn't such a built-in feature within CRED commerce, if you agree, we can take it as a feature request, our developers will evaluate it.

#627223

Pat

Hi Luo,

I just tried to change my custom field type (put it in SELECT) and insert this custom field inside my Cred :

<div class="form-group">
<label>Inscription Product ID</label>
[cred_field field='inscription-product-id' post='inscription' value='' urlparam='' select_text='[wpv-post-id]' class='form-control' output='bootstrap']
</div>
The field "inscription-product-id" is a SELECT field and is integrated in the custom fields manages by the postype "inscription".

Even with this, the custom field does not appear in the potential field proposed by the Cred commerce (On the text "Select a custom field" is present.
SO, I changed again the type and replace by a radio field. Then this field is now recognized by Cred commerce, but I cannot affect the [post-id] to this field (when I'm in the frontend, then only "select option 1 is displayed).

So, is there a way to be able to make this :
- place a custom field into Cred
- the field should be recognized by Cred commerce as the ID of the linked product
- the field should be able to be populated by [post-id] inside the Cred

Let me know
Regards
Pat

#627605

There isn't such a built-in feature within CRED commerce, in your case, it is not needed to use a custom field.

I suggest you try with the CRED commerce filter "cred_commerce_after_add_to_cart" hook to change the product ID in cart, here are detail steps:
1) Add a generic hidden field in your CRED form, to pass the product ID to CRED form:

[cred_generic_field field='my-product-id' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

There you can setup the target product ID to what you want.

2) The CRED commerce option, choose "Always this product, regardless of form inputs:" , choose a default product, any one you want, we will change it in step 3)

3) Add below codes into your theme/functions.php:


add_filter( 'cred_commerce_add_product_to_cart', 'my_hook', 10, 3 );
function my_hook( $product_id, $form_id, $post_id ) {
    if ( $form_id == 123 && isset($_POST['my-product-id']) ) {
        $product_id = $_POST['my-product-id'];
    }
    return $product_id;
}

Please replace 123 with your CRED form ID, and test again

More help:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_add_product_to_cart

#628168

Pat

Hi Lui
Thanks for your proposais
I'm out of the office currently and back next week-end
I will test all that at that time and come back to you if any issue
Regards
Pat

#628273

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Luo is on vacation. This is Minesh here and I'll try to help you further.

Let me know if you need further assistance.

#629606

Pat

Hi Luo,

Just tested and that's fully working. Many thanks for your help
Regards
Pat