# Order Management

### **ccb\_after\_create\_order**

This is a hook that creates a post with a post meta after creating an order and being triggered.&#x20;

**Parameters:**

* **$order\_data(Array)**
* **$payment\_data(Array)**

**Example:**

```php
add_action('ccb_after_create_order', 'create_post_after_order_created', 30, 2);

function create_post_after_order_created($order_data, $payment_data){
    // Check if the order_data or payment_data contains the necessary information
    if(isset($order_data['calc_id']) && isset($payment_data['total'])){
        // Customize the post title based on the order data
        $post_title = 'New Post for Calc ID ' . $order_data['calc_id'];

        // Create a new post
        $post_data = array(
            'post_title' => $post_title, // Set the post title
            'post_content' => 'This post is related to calculator ID ' . $order_data['calc_id'] . ' for total amount' . $payment_data['total'], // Set the post content
            'post_status' => 'publish', // You can set the post status as per your requirement
            'post_author' => 1, // Set the post author ID
            'post_type' => 'post', // Set the post type
        );

        // Insert the post into the database
        $post_id = wp_insert_post($post_data);

        // Check if the post was successfully created
        if($post_id){
         // You can perform additional actions here if needed
         // For example, you can update post meta data or perform any other tasks
	      update_post_meta($post_id, 'order_data', $order_data);
            update_post_meta($post_id, 'payment_data', $payment_data);
        }
    }
}
```

### **ccb\_orders\_list\_query**&#x20;

This is a hook for filtering orders in the admin. This hook allows you to change which orders will be loaded in the dashboard.

**Parameters:**

* **$args(Array).**

**Example:**

```php
add_filter('ccb_orders_list_query', 'filter_admin_orders', 10, 1);

function filter_admin_orders( $args ){
$default_calc_ids = array(217, 234, 243);
$order_by = 'ASC';
$offset = 0;
$limit = 4;
    $args = array(
        'payment_method' => 'paypal',
        'payment_status' => 'pending',
        'calc_ids'       => $default_calc_ids,
        'orderBy'        => 'total',
        'sorting'        => 'ASC',
        'limit'          => (int) $limit,
        'offset'         => (int) $offset,
    );

    return $args;
}
```

### **ccb\_orders\_before\_create**&#x20;

This hook gives input data before the order is created

**Parameters:**&#x20;

* **$data(Array)**

**Example:**

```php
add_filter('ccb_orders_before_create', 'send_data_before_creating_order', 10, 1);
function send_data_before_creating_order( $data ) {
 if($data['order_data']['calc_id'] == 408){ //replace 408 with the id of the calculator 
    $args = array();
    if($data['payment_data']['type'] == 'paypal'){
      	$args['data']['status'] = $data['payment_data']['status']; //Change data according to your needs
		if($data['payment_data']['total'] > 200){
			$args['data']['currency'] = $data['payment_data']['currency']; //change 'data['total']' 
			$response = wp_remote_post('https://webhook.site/b6d9f12f-71a5-40ca-8769-3e15023ee537', array('body' => $args));
			$body = wp_remote_retrieve_body( $response );
		}
    if ( is_wp_error( $response ) || is_wp_error( $body ) ) {
      	$errors[] = 'There was an error occurred after sening a request';
	  	return $errors;
    }
  }
 }
}
```

### **ccb\_show\_delete\_order**&#x20;

This is a hook to hide the delete order button

**Parameters:**

* **$show(bool)**

**Example:**

```php
add_filter( 'ccb_show_delete_order', 'ccb_maybe_hide_button', 10, 1);
function ccb_maybe_hide_button( $show ) {
  $show = current_user_can('administrator');
  return $show;
}
```

### **ccb\_show\_change\_status**

This is a hook to hide the button to change the order status

**Parameters:**

* **$show(bool)**

**Example:**

```php
add_filter( 'ccb_show_delete_order', 'ccb_maybe_hide_button', 10, 1);
function ccb_maybe_hide_button( $show ) {
  $show = current_user_can('administrator');
  return $show;
}
```

### **ccb\_show\_bulk\_actions**&#x20;

This is a hook to hide all bulk action buttons in the Orders tab

**Parameters:**

* **$show(bool)**

**Example:**

```php
add_filter( 'ccb_show_change_status', 'ccb_maybe_hide_dropdown', 10, 1);
function ccb_maybe_hide_dropdown( $show ) {
	$show = current_user_can('administrator');
	return $show;
}
```

### **ccb\_after\_delete\_order**&#x20;

This is a hook to perform actions after deleting an order

**Parameters**:

* **$ids(Array)**

**Example:**

```php
add_filter( 'ccb_show_bulk_actions', 'ccb_maybe_hide_dropdown', 10, 1);
function ccb_maybe_hide_dropdown( $show ) {
	$show = current_user_can('administrator');
	return $show;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stylemixthemes.com/cost-calculator-builder/develeopers-guide/cost-calculator-hooks/order-management.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
