Last year, I created a moneyless check-out system with the help of Toolset and it's technical staff.
I have been testing the site with PHP 7 and things seem to get a little buggy. Also, I am not sure how to update the custom code so that it works with the new post-relationship.
Here is the custom codes that was developed last year and I made them plugins
<?php
/*
Plugin Name: CUCCR Membership System / Add-on for WP Types
*/
//Save Member name as post title.
add_action('cred_save_data','func_custom_post_title', 10, 2);
function func_custom_post_title($post_id,$form_data) {
$arr = array(18, 17); // here you can add more CRED form IDs
if (in_array($form_data['id'], $arr)) {
$type = get_post_meta($post_id, 'wpcf-member-type', true);
$title = '';
if ($type == 'individual') {
$firstname = get_post_meta($post_id, 'wpcf-member-first-name', true);
$lastname = get_post_meta($post_id, 'wpcf-member-last-name', true);
$title = $firstname. ' ' . $lastname;
}
if ($type == 'group') {
$groupname = get_post_meta($post_id, 'wpcf-member-group-name', true);
$title = $groupname;
}
if($title){
$slug = sanitize_title($title);
$args = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => $slug
);
wp_update_post($args);
}
}
}
<?php
/*
Plugin Name: CUCCR Member Stats / Add-on for WP Types
*/
//Calculate membership fields
function count_numeric_custom_field_func( $atts ) {
global $wpdb;
extract( shortcode_atts( array(
'field' => '',
'cpt' => '',
'decimals' => 2,
'format_decimals' => 2,
), $atts ) );
$count = $wpdb->get_var( $wpdb->prepare(
"
SELECT SUM(CAST(meta_value AS DECIMAL (15,{$decimals}))) as count
FROM $wpdb->posts p
INNER JOIN $wpdb->postmeta pm
ON p.id = pm.post_id
WHERE p.post_type = %s
AND p.post_status = 'publish'
AND meta_key = %s
",
$cpt,
$field
) );
if (empty($count)){
$count = 0;
}
return number_format($count, $format_decimals);
}
add_shortcode( 'count_numeric_custom_field', 'count_numeric_custom_field_func' );
<?php
/*
Plugin Name: CUCCR Check-in/Check-out System / Add-on for WP Types
Description: CUCCR Check-in/Check-out System
*/
//Save Check-in and Check-out Member name as post title.
add_action('cred_save_data','item_title');
function item_title($post_id, $form_data) {
$type = get_post_type($post_id);
if ($type == 'material-check-out') {
$parent_id = $_POST["_wpcf_belongs_member_id"];
$title = get_the_title($parent_id);
$slug = sanitize_title($title);
wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_status' => 'publish'));
}
if ($type == 'material-check-in') {
$parent_id = $_POST["_wpcf_belongs_member_id"];
$title = get_the_title($parent_id);
$slug = sanitize_title($title);
wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'post_status' => 'publish'));
}
}
Where do I need to make changes?
Thank you