| CARVIEW |
Toolset Forms Commerce API Hooks
Toolset Forms Commerce is an add-on plugin for Forms, to enable payments via e-commerce plugins, when submitting forms.
This add-on can be used to build functionality that requires special conditions (involving payments) in order to create/edit posts and custom post types. Toolset Forms Commerce covers most needed functionality out-of-the-box, however for extra fine-tuning or customization the following API hooks are available. The hooks are related to actions after a form is submitted and/or the purchase order changes status (completed/cancelled/refunded).
Reference
- cred_commerce_add_product_to_cart
- cred_commerce_after_add_to_cart
- cred_commerce_after_order_completed
- cred_commerce_after_payment_cancelled
- cred_commerce_after_payment_completed
- cred_commerce_after_payment_refunded
- cred_commerce_after_send_notifications
- cred_commerce_before_add_to_cart
- cred_commerce_form_action
- Description
Filter that allows to dynamically alter the product associated with a CRED Commerce form, when adding to cart.
- Arguments
-
$product_id: ID of the product associated with the form and payment.$form_id: ID of the CRED Commerce form that the customer used.$post_id: ID of the post that was created or edited with the form.
- Output
More Usage examples
- Example
-
add_filter( 'cred_commerce_add_product_to_cart', 'my_hook', 10, 3 ); function my_hook( $product_id, $form_id, $post_id ) { if ( $post_id == 123 ) { $product_id = 345; } return $product_id; }
- Description
Action to be executed after a product for a CRED Commerce form is added to customer cart.
- Arguments
-
$form_id. The current CRED Commerce form that is accessed.$post_id. The ID of the post created or edited with the current CRED Commerce form.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_after_add_to_cart', 'my_hook', 10, 2 ); function my_hook( $form_id, $post_id ) { //some code here }
- Description
Action to be executed after WooCommerce order status is set to completed.
- Arguments
-
$datais an associative array that holds various information related to the order, with such structure:$data => array( 'user_id' => $user_id, 'transaction_id' => $transaction_id, 'extra_data' => array( array( 'cred_product_id' => $product_id, 'cred_form_id' => $form_id, 'cred_post_id' => $post_id, ... ) ), ... );Note: There may be other elements present in the array. These are internal to CRED Commerce and their presence or format is not guaranteed.
$user_id: ID of the user that placed the order.$transaction_id: ID of the WooCommerce order associated with the buying process.$product_id: ID of the product associated with the form and payment.$form_id: ID of the CRED Commerce form that the customer used.$post_id: ID of the post that was created or edited with the form.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_after_order_completed', 'my_hook', 10, 1 ); function my_hook( $data ) { //some code here }
- Description
Action to be executed after the purchase is cancelled.
- Arguments
-
$datais an associative array that holds various information related to the purchase, with such structure:$data = array( 'extra_data' => array( 'cred_form_id' => $form_id, 'cred_post_id' => $post_id, 'cred_product_id' => $product_id ... ), ... )Note: There may be other elements present in the array. These are internal to CRED Commerce and their presence or format is not guaranteed.
$form_id: ID of the CRED Commerce form that the customer used.$post_id: ID of the post that was created or edited with the form.$product_id: ID of the product that was associated with the form and payment.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_after_payment_cancelled', 'my_hook', 10, 1 ); function my_hook( $data ) { //some code here }
- Description
Action to be executed after the purchase is completed successfully.
- Arguments
-
$datais an associative array that holds various information related to the purchase, with such structure:$data = array( 'extra_data' => array( 'cred_form_id' => $form_id, 'cred_post_id' => $post_id, 'cred_product_id' => $product_id ... ), ... )Note: There may be other elements present in the array. These are internal to CRED Commerce and their presence or format is not guaranteed.
$form_id: ID of the CRED Commerce form that the customer used.$post_id: ID of the post that was created or edited with the form.$product_id: ID of the product that was associated with the form and payment.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_after_payment_completed', 'my_hook', 10, 1 ); function my_hook( $data ) { //some code here }
- Description
Action to be executed after the purchase is refunded to the client.
- Arguments
-
$datais an associative array that holds various information related to the purchase, with such structure:$data = array( 'extra_data' => array( 'cred_form_id' => $form_id, 'cred_post_id' => $post_id, 'cred_product_id' => $product_id ... ), ... )Note: There may be other elements present in the array. These are internal to CRED Commerce and their presence or format is not guaranteed.
$form_id: ID of the CRED Commerce form that the customer used.$post_id: ID of the post that was created or edited with the form.$product_id: ID of the product that was associated with the form and payment.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_after_payment_refunded', 'my_hook', 10, 1 ); function my_hook( $data ) { //some code here }
- Description
Action to be executed after the notification has been sent and on order status change.
- Arguments
-
$datais an associative array that holds various information related to the notidication, with such structure:$data => array( 'order_id' => $order_id, 'previous_status' => $previous_status, 'new_status' => $new_status, 'cred_meta '=> array( array( 'cred_product_id' => $product_id, 'cred_form_id' => $form_id, 'cred_post_id' => $post_id, ) ) );Note: There may be other elements present in the array. These are internal to CRED Commerce and their presence or format is not guaranteed.
$order_id: ID of the WooCommerce order associated with the buying process.$previous_status: The initial status of the order.$new_status: The new status of the order. It can take one of the following values:pending,failed,processing,completed,on-hold,cancelled,refunded.$product_id: ID of the product associated with the form and payment.$form_id: ID of the CRED Commerce form that the customer used.$post_id: ID of the post that was created or edited with the form.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_after_send_notifications', 'my_hook', 10, 1 ); function my_hook( $data ) { //some code here }
- Description
Action to be executed before a product for a CRED Commerce form is added to customer cart.
- Arguments
-
$form_id. The current CRED Commerce form that is accessed.$post_id. The ID of the post created or edited with the current CRED Commerce form.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_before_add_to_cart', 'my_hook', 10, 2 ); function my_hook( $form_id, $post_id ) { //some code here }
- Description
Action to be executed after CRED Commerce form has been submitted.
- Arguments
-
$action. The form action according to form settings.$form_id. The current form that is accessed.$post_id. The ID of the post created or edited with the current form.$form_data. The form data (form type, post type), similarly to CRED hooks.$is_ajax. Whether it is an AJAX form.
- Output
More Usage examples
- Example
-
add_action( 'cred_commerce_form_action', 'my_hook', 10, 4 ); function my_hook( $action, $form_id, $post_id, $form_data ) { if ( $post_id == 123 ) { wp_redirect( 'https://domain.com/my/page' ); exit(); } }