I was wondering If you knew how to add an invoice code to the forms in Authorize.net.
I check the authorize.net feed settings but they do not ask for an invoice code.Then, I started to do some research and found the hook gform_authorizenet_save_entry_id that could be used to create that invoice code.
The problem comes that there is no documentation about this hook. It was only mentioned as one of the updates. So, I'm creating a hidden field with an {entry_id} as a default value and trying to find a way to pass it as an Invoice Number.
Any help would be appreciated. Thanks :)
Update:
I was able to add a transaction code to the form using the following Snippet
//Adding the transaction code
add_filter( 'gform_authorizenet_transaction_pre_capture', 'set_invoice_number', 10, 5 );
function set_invoice_number( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] == 6 ) {
// your submission ID format to be inserted into the hidden field
$SubmissionID = 'RW-' . $entry['id'];
$transaction->invoice_num = $SubmissionID;
}
return $transaction;
}
I got the invoice number to become "RW-" but the $entry['id'] is not printing anything
You can assign an invoice number using an input field by adding this code to your theme's functions.php file:
add_filter('gform_authorizenet_transaction_pre_capture', 'set_invoice_number', 10, 4);
function set_invoice_number($transaction, $form_data, $config, $form)
{
$transaction->invoice_num = rgpost('input_YOUR INPUT FIELD NUMBER HERE');
}
If the input field is the hidden field containing the form's entry id that should accomplish what you're wanting.
I use the following code to append the "Form Name" to the invoice number passed to Authorize.net. I believe that the previous answer would work if the first field you create in each form was the "Invoice Number" field, but if you add the field later, or add it to your previously created forms, they wouldn't all have the same field number so it may not work. This code will use the automatically generated unique invoice number and add the form name.
i.e. Form Name: "Yearly Subscription" Auto Invioce Number: "1234567890"
Info that Authorize.net receives: "1234567890-Yearly_Subscription"
I have found that instead of adding custom functions to your theme file, it is better to build a custom plugin and add them there instead. This way if your theme updates, you won't lose your functions. The code to create your plugin, along with the functions for your Authorize.net code is included below. Save this file as My_Custom_Functions_Plugin.php and upload it to your web host in the "wp-content/plugins/" folder and then activate it. Next time you need to add any customized functions, just add them at the end of this file.
<?php
/*
Plugin Name: My_Custom_Functions_Plugin
Plugin URL: http://WEBSITE
Description: Custom Functions and Scripts for WEBSITE
Version: 1.0.0
Author: NAME
Author URI: http://WEBSITE
*/
// Functions for apending form name to authorize.net invoice
add_filter( 'gform_authorizenet_transaction_pre_capture', 'invoice_num', 10, 4 );
function invoice_num( $transaction, $form_data, $config, $form ) {
$transaction->invoice_num = uniqid() . '-' . rgar( $form_data, 'form_title' );
gf_authorizenet()->log_debug( 'gform_authorizenet_transaction_pre_capture: ' . print_r( $transaction, 1 ) );
return $transaction;}
// End of Authorize.net Function
// Add any additional Functions below this comment line to keep your themes functions.php file from getting overwritten on theme updates. Copy and paste this comment line before each function and give it a description to help keep you organized about what your function does
?>
Hope this helps!
Related
I have added several custom fields to my checkout that only appear when a user is checking out as a guest for the first time. My checkout process requires that the user create an account to complete checkout.
I have added four fields using the woocommerce_form_field method and then I have tried modifying the code provided in the answer here to achieve what I want. However, I have tried several checkouts, creating new accounts to check if the custom field values save into the new users' profile, but it doesn't seem to be working.
Here is one example of a solution I tried which did not work:
function reigel_woocommerce_checkout_update_user_meta( $customer_id) {
if ( ! empty( $_POST['practitioner_license_number'] ) ) {
$pln = sanitize_text_field( $_POST['practitioner-license-number'] );
update_user_meta($customer_id, 'practitioner_license_number', $pln);
}
}
add_action('woocommerce_created_customer', 'reigel_woocommerce_checkout_update_user_meta', 10, 2);
practitioner-license-number is my custom field added using the woocommerce_form_field method. I modified the code at the link above, so that the function runs on woocommerce_created_customer and then in update_user_meta I'm trying to pass the customer ID so that it saves the meta to the user profile that is created.
Would appreciate help trying to solve this. Most of the questions/answers on this subject assume that the user is logged in and already has an account, which is not the case here.
From the code you share, I think the problem lies in incorrectly passing to the $_POST,
perhaps practitioner_license_number vs practitioner-license-number.
You can use the code below to see if your hook works, if the value is written in the database you know that the problem is indeed elsewhere.
It might help to share the code you used for the custom fields too?
function action_woocommerce_created_customer( $customer_id, $new_customer_data, $password_generated ) {
$pln = 'test';
update_user_meta( $customer_id, 'practitioner_license_number', $pln);
}
add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 );
Guys I'm writting a wordpress site to run a knowldge base for our Service desk. As one person will be updating it i needed to have a field for who wrote the kb artical. I'm tring to add a custom field into my wordpress theme to display writtenby using Advance custom Fields. Now I'm using echo Knowledge Base plugin for knowldge base.
I've got as far add ing code below will display the text below the last up date value that plugin creates. However i cannot get it to put value from the custom field on the page after this. The plugin creates the page using php below the ive added the two lines as below.
$wb = get_post_meta($post->ID, 'Writtenby', true);
echo ' Last Update Writtenby:'.$wb.' ';
// LAST UPDATED ON
public static function last_updated_on( $args ) {
echo '' . esc_html( $args['config']['last_udpated_on_text'] ) . ' ' . EPKB_Utilities::get_formatted_datetime_string( $args['article']->post_modified, 'F d, Y' ).'';
$wb = get_post_meta($post->ID, 'Writtenby', true);
echo ' Last Update Written by:'.$wb.' ';
}
Advanced Custom Fields plugin use a little bit different system to store postmeta. Try to use get_field() instead get_post_meta()
If you have the ID
$customField = get_post_meta($my_id, "_mcf_customField", true);
However if you want to get the ID from the object:
$customField = get_post_meta($post_id->ID, "_mcf_customField", true);
After much more work looks like at the point the page was being created it had no reference to partical page not even a current one. They where writting to an array all artical numbers and info.
So by telling get_field which artical to get the writtenby field from it now displayed data and not blank
$wb= get_field('Writtenby', $args['article']->ID);
So I'll start out by saying, that I am a bit new to this.
So I have this website I'm currently making. It's a guild website for World of Warcraft, and we want to be able to have new people being able to apply for membership.
Making the contact form is easy enough through plugins, but this is in theory what I wish to make:
A contact form where when filled in, the application form will push a notification to a webhook set in Discord where when new applicants happen, a message in a channel will be made, notifying the leaders about it.
Do I need to create a plugin myself, or is there any plugin that can offer this functionality?
I had the same needs, after sometime i found a way to do it.
Its actually very simple with WPForms.
WPForms has hooks so you can easily track forms submitions with the wpforms_process_complete hook. This hook allows you to track ALL WPForms sumbission. But maybe you'd like to have different forms. If you wish to track only a specific form, you can add the form id to the end of the hook name.
In my case i had many different forms which are being handled in various different ways, so i had to split them. When a form is being created in WPForms, it receives an ID so does the fields of the named form.
In my case after my form was created it had the following id :
The hook function.
As explained on the Discord Webhook page, Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use. The endpoint supports both JSON and form data bodies. In my case i went for JSON.
As explained here you just need to use one of the the content file or embeds field. On this example i will just send a message, so i'll be using the content field.
Once the above instructions applied, you should end up with something close to the following function :
if ( ! function_exists( 'discord_form_submission' ) ) :
/**
* This will fire at the very end of a (successful) form entry.
*
* #link https://wpforms.com/developers/wpforms_process_complete/
*
* #param array $fields Sanitized entry field values/properties.
* #param array $entry Original $_POST global.
* #param array $form_data Form data and settings.
* #param int $entry_id Entry ID. Will return 0 if entry storage is disabled or using WPForms Lite.
*/
function discord_form_submission( $fields, $entry, $form_data, $entry_id )
{
// You have to replace this url by your discord webhook.
$endpoint = 'https://discord.com/api/webhooks/{webhook.id}/{webhook.token}';
// This is the content you can put anything you wish.
// In my case i needed the Name, Class, and the Level of the players.
$content = "**Name :** " . $fields[1]['value'] . PHP_EOL;
$content .= "**Class :** " . $fields[2]['value'] . PHP_EOL;
$content .= "**Level :** " . $fields[3]['value'] . PHP_EOL;
// WP has its own tool to send remote POST request, better use it.
wp_remote_post( $endpoint , [
'headers' => [
'Content-Type' => 'application/json; charset=utf-8'
],
'body' => wp_json_encode([ // Same for the JSON encode.
'content' => $content,
]),
'method' => 'POST',
'data_format' => 'body'
]);
}
endif;
This function must be added in the functions.php file of your theme.
Last but not least, with the help of the WP add_action Function you need to hook up with the wpforms_process_complete hook. In my case since i want to only hook up to the form with the id 1862 i have added the id at the end of the hook which gives us the following code :
add_action( 'wpforms_process_complete_1862', 'discord_form_submission', 10, 4 );
This code must be added in the functions.php file of your theme after our newly added function.
I am relatively new to woocommerce development so I am sorry if this question might be too trivial but I need help.
I need in my application a way to make some checks when an admin makes changes to a product in woocommerce.
For example, I want to create a log file of all the changes that occurred on products. Who made them, when and what was the change (price, inventory, description, etc.).
I understand that there are hooks in woocommerce that I can use. Which ones can help me do something like that?
Use post_updated hook for this purpose, place the following code in your functions.php
function product_update_handler( $id, $before_data, $after_data ) {
if( $before_data->post_type == "product" ) {
$current_user = wp_get_current_user();
error_log( $before_data->post_title ." has been updated by ".$current_user->user_login );
}
}
add_action('post_updated', 'product_update_handler', 0, 3);
you have two product objects ( before update, after update ) with the above hook, you can compare both object and log the changes.
Does anyone have any idea how to add custom meta fields while making categories and fetch them in the loop in WordPress? I was wondering how to do that without hacking the WordPress core, but if I do – it won't become a hindrance to update WordPress in the future.
A plugin I have found that comes close is Wp-Category-Meta, but it doesn't have the ability to add checkboxes as fields in Edit Categories.
This will be very useful as users can make certain categories "featured", and then the code can use that meta value in the loop to style "featured" categories differently.
The problem:
Wordpress does not have a structure nor method to store "meta" values for taxonomies.
UPDATE 2017: WP 4.4+ has "term meta"!
For working with term metas use these:
update_term_meta()
get_term_meta()
delete_term_meta()
add_term_meta()
The Actions below are still valid though! :)
Additional reading: 4.4 Taxonomy Roundup
Solution for WP version <= 4.3.x and COMMON actions
Actions:
create_category and edit_category for category edit
category_add_form_fields and category_edit_form for category form fields
There are more actions than I've presented, but they seem to be deprecated (according to developer.wordpress.org).
The reason I chose the actions that I chose:
- They work on WordPress 4.4.2
- Due to lack of documentation I assumed these are the new ones replacing the deprecated ones...
Functions:
get_option( $option, $default );
update_option( $option, $new_value, $autoload );
update_option has two great abilities:
a) It craetes the option when such option does not exist yet
Unless you need to specify the optional arguments of add_option(),
update_option() is a useful catch-all for both adding and updating
options.
b) $new_value can be an integer, string, array, or object.
You may ask, why to use array/object? ...well, because each option = 1 database row => you probably want to store your category options in one row :)
The CODE
function my_category_form_fields($tag_object){
//output/display extra form fields, e.g. by echo ...
//ADD EXTRA SPECIFIC FIELD TO LATER CHECK IF IT'S CATEGORY SAVE/EDIT!
//(see note at 'edit_category' action...)
if( !empty($tag_object['term_id']) ){
//edit category form specific
//...load existing options with get_option( $option, $default );
} else {
//create category form specific
}
}
function my_category_save(){
//CHECK FOR YOUR EXTRA SPECIFIC FIELD TO CHECK IF IT'S CATEGORY SAVE/EDIT
//(see note at 'edit_category' action...)
//SECURITY CHECK
if( empty($_POST['EXTRA_SPECIFIC_FIELD']) || ! current_user_can('manage_categories') )
return null;
//save your form values using update_option()
//Recommendation:
//Add "category_" prefix and $category_id to your option name!
}
add_action( 'create_category', 'my_category_save', 10, 1 );
//Runs when a category is updated/edited,
//INCLUDING when a post or blogroll link is added/deleted or its categories are updated
//(which causes the count for the category to update)
add_action( 'edit_category', 'my_category_save', 10, 1 );
add_action( 'category_add_form_fields', 'my_category_form_fields', 10, 1 );
add_action( 'category_edit_form', 'my_category_form_fields', 10, 1 );
Create or Edit?
You might wonder whether you are creating or saving a category - this not documented yet (as far as I know), but from testing:
Edit save => $tag_object is object and contains some properties, most notably:
term_id
taxonomy
filter
Create save => $tag_object is just a regular string "category" - I guess this might change in the future...
General taxonomy
There are also actions like these for taxonomies in general - check these actions.
Jaz,
It looks like the plugin you mention in your original question has been updated to include a checkbox field (included in v1.2.3)
I think the Category SEO Meta Tags plugin will help you.
There is an updated and refactured version of this plugin to be found here:
https://wordpress.org/plugins/custom-taxonomy-category-and-term-fields/
Also added a WYSIWYG editor fieldtype.