1. Home
  2. Miscellaneous Hooks & Filters present across different features

Miscellaneous Hooks & Filters present across different features

How can I change the email recipient for recovery emails?

Hook
wcap_send_recovery_email_to

Usage:

add_filter( 'wcap_send_recovery_email_to', 'wcap_change_recipient', 10, 1 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function wcap_change_recipient( $user_email ) {
     $user_email = '[email protected],[email protected]'; // Comma separated multiple email addresses.
     return $user_email;
}
add_filter( 'wcap_send_recovery_email_to', 'wcap_change_recipient', 10, 1 );

How can I add a new column on the Abandoned Orders tab of our plugin?

Hook
wcap_abandoned_orders_columns

Use the below code to add a new column:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function wcap_add_test_column( $columns ) {
    $columns['test_column'] = __( 'New Test Column', 'woocommerce-ac' );
    return $columns;
}
add_filter( 'wcap_abandoned_orders_columns', 'wcap_add_test_column', 10, 1 );

Edit an existing column name

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function wcap_edit_actions_column( $columns ) {
    $columns['wcap_actions'] = __( 'More Actions', 'woocommerce-ac' ); // Change the name from Actions to More Actions.
    return $columns;
}
add_filter( 'wcap_abandoned_orders_columns', 'wcap_edit_actions_column', 10, 1 );

Edit an existing column name

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function add_col() {
    ?>

wcap_abandoned_orders_column_default

Add data to be displayed for a new column:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function wcap_new_test_data( $value, $abandoned_data, $column_name ) {
	if ( 'test_column' === $column_name ) {
		$value = $abandoned_data->id . __( 'Custom data for the cart', 'woocommerce-ac' );
	}
	return $value;
}
add_filter( 'wcap_abandoned_orders_column_default', 'wcap_new_test_data', 10, 3 );

Edit data displayed for an existing column:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function wcap_edit_actions_data( $value, $abandoned_data, $column_name ) {
	if ( 'wcap_actions' === $column_name ) {
		$value .= __( 'Perform more actions', 'woocommerce-ac' );
	}
	return $value;
}
add_filter( 'wcap_abandoned_orders_column_default', 'wcap_edit_actions_data', 10, 3 );

From version 9.x the below 2 filters need to be used to display data to the new columns added using wcap_abandoned_orders_header_html hook

Send the data to VueJS before it renders:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function change_render_obj( $return_obj, $i, $cart_id ) {

	global $wpdb;

	$user_type = $wpdb->get_var(
		$wpdb->prepare(
			'SELECT user_type FROM ' . WCAP_ABANDONED_CART_HISTORY_TABLE . ' WHERE id = %d',
			(int) $cart_id
		)
	);

	$return_obj->user_type = $user_type;
	return $return_obj;
}
add_filter( 'wcap_abandoned_orders_data_object', 'change_render_obj', 10, 3 );

Display it on the front end rows

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function display_data() {
	?>

 

{{row.user_type}}

 

<?php }
add_action( ‘wcap_abandoned_orders_row_html’, ‘display_data’ );

How can I modify the coupon details (such as meta value, description etc.) for any unique coupons created by the plugin?

The plugin allows us the ability to create unique coupons for different sources such as ATC popups, email reminders and so on. The below filter can be used for the same.

The available values for modification are:

array(
	'post_content'     // Coupon Description
	'post_status'      // Coupon Status
	'post_author'      // Author
	'post_type'        => 'shop_coupon' // Ideally should not be modified. Setting to any other value will result in the coupon not being displayed in WooCommerce > Marketing > Coupons list.
	'post_expiry_date' // Expiry timestamp.
	'meta_input'       // Coupon Meta values. Details provided in the array below.
)
array(
	'discount_type'        
	'coupon_amount'        
	'minimum_amount'       
	'maximum_amount'       
	'individual_use'       
	'free_shipping'        
	'product_ids'          
	'exclude_product_ids'  
	'usage_limit'          
	'usage_limit_per_user' 
	'date_expires'         
	'apply_before_tax'     
	'exclude_sale_items'   
	'product_categories'           
	'exclude_product_categories'   
);

For example, by default unique coupons created by the plugin are enabled for individual use. If the site admin chooses to override this, the custom code needed would be:

Usage:

add_filter( 'wcap_cron_before_shop_coupon_create', change_individual_use, 10, 1 );

Example:

/**
* Add this code snippet in the "functions.php" file of your currently active theme.
*/
function change_individual_use( $coupon_details ) {
        $coupon_details['meta_input']['individual_use'] = 'no';
        return $coupon_details;
}
add_filter( 'wcap_cron_before_shop_coupon_create', change_individual_use, 10, 1 );

JS: Function to sort the object based on a specific key.

Example:

var mergecode = [{text: 'b'},{text: 'a'},{text: 'b'}];
mergecode.sort( dynamicSort("text") );
function dynamicSort(property) {
    var sortOrder = 1;

    if(property[0] === "-") {
        sortOrder = -1;
        property = property.substr(1);
    }

    return function (a,b) {
        if(sortOrder == -1){
            return b[property].localeCompare(a[property]);
        }else{
            return a[property].localeCompare(b[property]);
        }        
    }
}

How to add extra data in the WooCommerce session?

Hook
wcap_guest_cart_history_before_insert

Usage:

add_filter( 'wcap_guest_cart_history_before_insert', 'save_name', 10, 1 );

Example:

function save_name( $data ) {
	if ( isset( $_POST['billing_first_name'] ) ) {
		$data['billing_first_name'] = sanitize_text_field( wp_unslash( $_POST['billing_first_name'] ) );
	}
	if ( isset( $_POST['billing_last_name'] ) ) {
		$data['billing_last_name'] = sanitize_text_field( wp_unslash( $_POST['billing_last_name'] ) );
	}
	WC()->session->set( 'wcap_checkout_data', $data );
	return $data;
}
add_filter( 'wcap_guest_cart_history_before_insert', 'save_name', 10, 1 );

How to populate the data saved in WooCommerce session in the fields at Checkout?

Hook
woocommerce_checkout_fields

Usage:

add_filter( 'woocommerce_checkout_fields' , 'override_checkout_email_field' );

Example:

function override_checkout_email_field( $fields ) {
    $data = WC()->session->get('wcap_checkout_data');
  
    foreach( $data as $key => $value){
		if( !empty( $data[$key])){
			$_POST[$key] =   $data[$key];
		}		 
	}
    
    return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'override_checkout_email_field' );

How to disable network check for WooCommerce plugin status for multi site installations?

Hook
wcap_do_network_check

Usage:

add_filter( 'wcap_do_network_check', 'disable_wc_check_for_network', 10, 1 );

Example:

function disable_wc_check_for_network( $check )  {
     return false;
}
add_filter( 'wcap_do_network_check', 'disable_wc_check_for_network', 10, 1 );

How to send reminder SMS only during specific hours?

Hook
wcap_send_sms_hours

Usage:

add_filter( 'wcap_send_sms_hours', 'setup_sms_hours', 10, 1 );

Example:

function setup_sms_hours( $hours )  {
     $hours['start'] = '08:00';
     $hours['end']   = '20:00';
     return $hours;
}
add_filter( 'wcap_send_sms_hours', 'setup_sms_hours', 10, 1 );
Was this article helpful to you? Yes No

How can we help?