Help
-
i was given this snippet below by @ivan which works on my old theme for adding Bank name, bank account number and name on bank account. It works on my old theme but after i bought a more better theme and inserted same snippet on fresh wordpress installation. It did not work at all.
Find the code belowHi there,
please, try to add this custom code in the functions.php of your active theme:
add_filter('yith_wcaf_payment_email_required', '__return_false');
if ( defined( 'YITH_WCAF' ) ) {
if ( ! function_exists( 'yith_wcaf_get_extra_fields' ) ) {
function yith_wcaf_get_extra_fields() {
return array(
'bank_name' => array(
'type' => 'text',
'label' => __('Bank name', 'yith-woocommerce-affiliates'),
'mandatory' => true,
),
'bank_account_num' => array(
'type' => 'text',
'label' => __('Bank account number', 'yith-woocommerce-affiliates'),
'mandatory' => true,
),
'bank_account_name' => array(
'type' => 'text',
'label' => __('Bank account name', 'yith-woocommerce-affiliates'),
'mandatory' => true,
),
);
}
}if ( ! function_exists( 'yith_wcaf_add_custom_fields' ) ) {
function yith_wcaf_add_custom_fields( $user = false ) {
$yith_wcaf_additional_fields = yith_wcaf_get_extra_fields();$user_id = $user instanceof WP_User ? $user->ID : false;
$user_id = ( ! $user_id && is_user_logged_in() ) ? get_current_user_id() : $user_id;
$fields = '';
$admin = doing_action( 'show_user_profile' ) || doing_action( 'edit_user_profile' );if ( $admin ) {
$fields .= "<hr/>
<h3>Additional Affiliate Fields</h3>
<table class='form-table'>";
}foreach ( $yith_wcaf_additional_fields as $field => $opts ) {
if ( $user_id ) {
$value = get_user_meta( $user_id, 'yith_wcaf_' . $field, true );
} else {
$value = ! empty( $_POST[ 'yith_wcaf_' . $field ] ) ? $_POST[ 'yith_wcaf_' . $field ] : '';
}$fields .= $admin ? '<tr><th>' : "<p class='form-row form-row-wide'>";
$fields .= "<label for='yith_wcaf_" . $field . "'>" . $opts['label'] . ': ' . ( $opts['mandatory'] ? "<span class='required'>*</span>" : '' ) . '</label>';
$fields .= $admin ? '</th><td>' : '';
$fields .= "<input type='" . $opts['type'] . "' class='input-text' name='yith_wcaf_" . $field . "' id='yith_wcaf_" . $field . "' value='$value' " . ( $opts['mandatory'] ? 'required' : '' ) . ' />';
$fields .= $admin ? '</td></tr>' : '</p>';
}if ( $admin ) {
$fields .= '</table>';
}echo $fields;
}add_action( 'yith_wcaf_register_form', 'yith_wcaf_add_custom_fields' );
add_action( 'yith_wcaf_settings_form_after_payment_email', 'yith_wcaf_add_custom_fields' );
add_action( 'show_user_profile', 'yith_wcaf_add_custom_fields', 21, 1 );
add_action( 'edit_user_profile', 'yith_wcaf_add_custom_fields', 21, 1 );
}if ( ! function_exists( 'yith_wcaf_register_custom_field' ) ) {
function yith_wcaf_register_custom_field( $param1, $param2 = false ) {
$yith_wcaf_additional_fields = yith_wcaf_get_extra_fields();if ( doing_action( 'yith_wcaf_new_affiliate' ) ) {
$id = $param1;
$affiliate = YITH_WCAF_Affiliate_Handler()::get_instance()->get_affiliate_by_id( $id );
$user_id = $affiliate['user_id'];
} elseif ( doing_action( 'yith_wcaf_save_affiliate_settings' ) ) {
$user_id = $param2;
} elseif ( doing_action( 'personal_options_update' ) || doing_action( 'edit_user_profile_update' ) ) {
$user_id = $param1;if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
}if ( empty( $user_id ) ) {
return false;
}foreach ( $yith_wcaf_additional_fields as $field => $opts ) {
if ( isset( $_REQUEST[ 'yith_wcaf_' . $field ] ) ) {
update_user_meta( $user_id, 'yith_wcaf_' . $field, sanitize_text_field( $_REQUEST[ 'yith_wcaf_' . $field ] ) );
}
}if( doing_action( 'yith_wcaf_save_affiliate_settings' ) ) {
return true;
}}
add_action( 'yith_wcaf_new_affiliate', 'yith_wcaf_register_custom_field', 10, 1 );
add_action( 'yith_wcaf_save_affiliate_settings', 'yith_wcaf_register_custom_field', 10, 2 );
add_action( 'personal_options_update', 'yith_wcaf_register_custom_field', 10, 1 );
add_action( 'edit_user_profile_update', 'yith_wcaf_register_custom_field', 10, 1 );
}
}`
- The topic ‘Help’ is closed to new replies.