Order Management
These hooks let developers customize Orders in the Cost Calculator.
ccb_after_create_order
This is a hook that creates a post with a post meta after creating an order and being triggered.
Parameters:
$order_data(Array)
$payment_data(Array)
Example:
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
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:
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
This hook gives input data before the order is created
Parameters:
$data(Array)
Example:
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
This is a hook to hide the delete order button
Parameters:
$show(bool)
Example:
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:
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
This is a hook to hide all bulk action buttons in the Orders tab
Parameters:
$show(bool)
Example:
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
This is a hook to perform actions after deleting an order
Parameters:
$ids(Array)
Example:
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;
}
Last updated
Was this helpful?