Very specific issue but, I've been dragged onto an issue with our companies Payment Gateway on our Wordpress / Woocommerce website where we are using the Opayo Plugin (For Opayo Direct).
The issue is:
When originally setup, there was no template / option selected for the Reference field on the data / object sent to the API
The guys originally doing the website then tried contacting the original developer of this now unsupported plugin to which they was sent some code to put into another plugin named PHP Injection the code was similar to below:
add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );
function my_opayo_direct_custom_field_vendordata ( $vendordata, $order ) {
// Get Order ID
$order_id = $order->get_order_number();
$reference = "test_" . $order_id;
// Get the reference field - set '_reference_field' to the meta_key from your order
if( isset( get_post_meta( $order_id, '_reference_field', TRUE ) ) ) {
$vendordata = get_post_meta( $order_id , '_reference_field', TRUE );
//$vendordata['_reference_field'] = $reference; ### Commented as I'm unsure if this is correct
}
return $vendordata;
}
After doing numerous testing and small changes, still nothing seems to be showing up in the Reference field in Opayo itself?
Please tell me someone has encountered this situation before or knows what I might be missing, it's been a while since I've touched PHP
First you mot use $order->get_order_number()when trying to get order meta data but use $order->get_id() with get_post_meta() function instead.
Now you can also use the WC_Data method get_meta() to be used on $order object variable.
What you need to find out is the key slug that you need to use to incorporate that custom field value to the vendor data via opayo_direct_custom_field_vendordata filter hook.
Try the following (where I use 'reference' as key slug, to be replaced with the right slug):
add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );
function my_opayo_direct_custom_field_vendordata ( $vendor_data, $order ) {
$reference = $order->get_meta('_reference_field');
if ( ! empty($reference) ) {
$vendor_data['reference'] = $reference;
}
return $vendor_data;
}
or using get_post_meta() function:
add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );
function my_opayo_direct_custom_field_vendordata ( $vendor_data, $order ) {
$reference = get_post_meta($order->get_id(), '_reference_field', true);
if ( ! empty($reference) ) {
$vendor_data['reference'] = $reference;
}
return $vendor_data;
}
It could better work…
Alright, so, I contacted Opayo myself to see what the Mapping was for the Reference column on the Opayo website and what data that is sent to the API is mapped to that Reference column in the table.
Apparently the value sent to the API that corresponds to this is the VendorData (Not required, 200 Char limit, free-text)
So, to fix this, I had to:
Open the Plugin Editor on Wordpress
Select the woocommerce-gateway-sagepay-form Plugin
Navigate and select the woocommerce-gateway-sagepay-form/classes/direct/sagepay-direct-request-class.php file
I then scrolled to Line 335 inside of the $end array, I then added the field of VendorData as seen by the code below:
$end = array(
"CustomerEMail" => $order->get_billing_email(),
"ClientIPAddress" => $this->get_ipaddress(),
"AccountType" => $this->accounttype,
"ReferrerID" => $this->referrerid,
"Website" => site_url(),
"VendorData" => '#######',
"Crypt" => MD5( $this->open_salt . $order->get_order_key() . $this->close_salt ),
);
And then set the ####### to the Value I needed to send to Opayo to show in the Reference column in the payments table.
Then just to be sure it wasn't going to get pruned (Again, not touched PHP for a while, I went to (NOW) Line 378 and commented it out, see below:
// Customiseable fields
$end['TransType'] = apply_filters( 'opayo_direct_custom_field_transtype', '01', $order );
//$end['VendorData'] = apply_filters( 'opayo_direct_custom_field_vendordata', '', $order );
Saving this, then when an Order / Purchase was made, the Reference field on Opayo's website was populated with what I set the VendorData to.
Quick Note: The VendorData field is max of 200 characters and only Aa or 0-9, I had a couple of failed attempts when I was trying to have _ until I searched the error I received on this page:
https://www.opayo.co.uk/support/error-codes?keyword=3189
I hope that my issue and resolution helps someone in the future and sorry for anyone's time I wasted!
I'm setting up a new Wordpress/Woocommerce website using the Avada theme. The site is not live yet.
The store has custom product taxonomies, and as some of the taxonomy names contain a comma I've had to find a code snippet to do a workaround in PHP so that the comma is displayed without splitting the taxonomy name into two separate names (eg. Bouncy Balls, Putty and Slime). The PHP I found has replaced a double dash (--) with a comma in the front end, which appears to work as it should.
My problem is, that since I have added this code I'm getting an error at the top of the page on individual product pages:
Notice: Trying to get property 'taxonomy' of non-object in /var/sites/a/mywebsite.com/public_html/wpnew/wp-content/themes/Avada-Child-Theme/functions.php on line 32
Line 32 code:
if( $tag_arr->taxonomy == 'post_tag' && strpos( $tag_arr->name, '--' ) ) {
All of the code I inserted into functions.php is below.
I'm not sure what to try to fix this as this is all new to me and I'm learning as I go along. I have very little knowledge of PHP, besides the snippet I have found online and placed here.
if( !is_admin() ){
function comma_tag_filter( $tag_arr ){
$tag_arr_new = $tag_arr;
if( $tag_arr->taxonomy == 'post_tag' && strpos( $tag_arr->name, '--' ) ) {
$tag_arr_new->name = str_replace( '--', ', ', $tag_arr->name );
}
return $tag_arr_new;
}
add_filter( 'get_post_tag', 'comma_tag_filter' );
function comma_tags_filter( $tags_arr ) {
$tags_arr_new = array();
foreach( $tags_arr as $tag_arr ) {
$tags_arr_new[] = comma_tag_filter( $tag_arr );
}
return $tags_arr_new;
}
add_filter( 'get_terms', 'comma_tags_filter' );
add_filter( 'get_the_terms', 'comma_tags_filter' );
}
I expected this code to work without errors, but I have the error message at the top of the product pages.
Thanks for any help
Hi I am trying to solve a problem in my wordpress site https://braenworks.com/braenworks-academy/
There is a error at the top of my page :
Notice: Trying to get property of non-object in /var/www/vhosts/braenworks.com/httpdocs/wp-includes/taxonomy.php on line 3950
I think it is coming from the plugin learnpress because when I link the plugin to another page the error then appears on that page and moves away from the page where it previously stood.
This is the code on line 3950: elseif ( $t->query_var )
if ( empty($termlink) ) {
if ( 'category' == $taxonomy )
$termlink = '?cat=' . $term->term_id;
elseif ( $t->query_var )
$termlink = "?$t->query_var=$slug";
else
$termlink = "?taxonomy=$taxonomy&term=$slug";
$termlink = home_url($termlink);
Can someone maybe help me with this :(?
Thanks!
Hard to say for sure but the following should get rid of the error. Change that elseif statement to this:
elseif (isset($t) && is_object($t) && $t->query_var )
The other thing you could do is turn off PHP errors which should be set to off for production anyway :)
I am trying to fix a PHP error for adding extra fields to WordPress categories. But it gives this error:
Trying to get property of non-object in
D:\MAMP\htdocs\client\wp-content\themes\custom_t\extra_category_fields.php on line 7
Here is my code:
<?php
add_action('edit_category_form_fields', 'extra_category_fields');
add_action ( 'category_add_form_fields', 'extra_category_fields');//adds
same fields to add new cat
//add extra fields to category edit form callback function
function extra_category_fields($tag) { //check for existing featured ID
$t_id = $tag->term_id;
$cat_meta = get_option( "category_$t_id");
The error is on line 7 which has this code: $t_id = $tag->term_id;
I shall appreciate if someone gives me a solution to this php error.
P.S. I do not consider myself an expert in PHP. I already checked this article: Reference - What does this error mean in PHP but I still could not understand a direct solution.
Thank you!
It seems that the variable $tag is not of type object so you can't use the -> operator on it.
Here is an easy way to see what $tag is.
echo(var_dump($tag))
https://www.w3resource.com/php/function-reference/var_dump.php
Explains what it does. It should dump all the info for that variable onto your screen.
It seems like the "category_add_form_fields" hook will give you as parameter a string, that is the slug of your category. Please see this : https://github.com/WordPress/WordPress/blob/4981452aba3a9804dd5a4f869e124e38853cb7cc/wp-admin/edit-tags.php#L473
The "edit_category_form_fields" hook will return you the object you want. Also this hook seems to be deprecated and would be recommend to use "category_edit_form_fields" and this has for the first parameter an object.
So you will need to check if $tag is an object or a string like this :
if( ! is_object( $tag ) ){
$tag = get_category_by_slug( $tag );
}
Hope this helps.
The script below is called when saving my app's options page. All options are stored in an array in $options.
I'm getting a debug error "undefined index, id" on the line with the comment below. Any ideas how I can fix the script?
foreach ($options as $value)
{
if( isset( $value['id'] ) && isset( $_REQUEST[$value['id']] ) )
{
update_option( $value['id'], stripslashes($_REQUEST[$value['id']]) );
}
else
{
update_option( $value['id'], ""); //Error Here
}
}
Your if{} segment precludes the code in your else{} segment from working.
In other words:
In your if block, you ask: "Does $value['id'] exist?"
If it does not, your code executes your else block, which then attempts to reference the non-existent variable.
You'll need to set the array key before you can update it.
Your update_option function should simply check to see if the variable exists, and set it instead of updating it, if it does not.