my gateway name is ( Woocommerce_Add_ZarinPal_Gateway )
i want update title this gateway from code
and this my code
$my_options = get_option('woocommerce_WC_ZPal_settings');
$my_options['woocommerce_WC_ZPal_settings']['title'] = 'test';
update_option('woocommerce_WC_ZPal_settings', $my_options);
but when i update gateway other option with same name is update / not update plugin gateway name
my update output :
woocommerce_WC_ZPal_settings";a:2:{s:5:"title";s:4:"test"}
orginal plugin output :
woocommerce_WC_ZPal_settings" string(793) "a:11:{s:11:"base_config";s:0:"";s:7:"enabled";s:3:"yes";s:5:"title";s:35:"پرداخت امن زرین پال";}
note : i have two ((woocommerce_WC_ZPal_settings)) option with same
name ! why?
No need to access the woocommerce_WC_ZPal_settings in the my_options array.
$my_options = get_option('woocommerce_WC_ZPal_settings');
$my_options ['title'] = 'test';
update_option('woocommerce_WC_ZPal_settings', $my_options);
You should try to find the specific option name that corresponds to the gateway title you want to update
$option_name = 'woocommerce_Add_ZarinPal_Gateway_settings';
$my_options = get_option($option_name);
$my_options['title'] = 'test';
update_option($option_name, $my_options);
it should update the gateway title for the specific option that you are targeting.
i found problem , thanks #Pugazhenthi Murugesan .
when i want to update gateway method name from code just must use .
$my_options['title'] = 'test';
update_option('woocommerce_bankmellat_settings', $my_options);
Related
I am using [_remote_ip] in the email I am reciveng from contact form 7, is there is a way to show the country name or flag instead of the received IP number?
The main issue started when I activated caching, where the php country locate stopped working, so I have to use the [_remote_ip] in the email to know the location of the contact, but it's not a good solution that I always have to locate the ip manually.
That's why I want to check if there is a way to show that IP as a name or as a flag.
This will add a form tag to Contact form 7 [country] - Add this to your functions.php or make it a plugin. TO use this, you'll need a subscription (free tier available) to https://ipstack.com.
add_action('wpcf7_init', function (){
wpcf7_add_form_tag( 'country' , 'cf7_ip_to_country_form_tag' );
});
function cf7_ip_to_country_form_tag($tag){
// Your API Key for https://ipstack.com is required
$api_key = 'xxxxxxx';
// Get API Response
$url = 'http://api.ipstack.com/' . $_SERVER['REMOTE_ADDR'] . '?access_key=' . $api_key;
$response = wp_remote_get($url);
$body = json_decode(wp_remote_retrieve_body($response));
/* $body = Object returned from ipstack.
* $body->country_name = Full Country Name
* $body->country_code = 2 Letter ISO Abbrev
* set the value based on what you want.
*/
return '<input type="hidden" name="country" value="'.$body->country_name.'">';
}
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);
I want to get the URL from where the customer can directly pay for their Invoice and also it should work with wc-cancelled and wc-transaction-declined (custom order status).
My Solution
What I'm doing now is created a custom page with my custom get parameters and processing the whole Payment Process as Documentation in Gateway provider Website.
My Problem
But the problem is whenever they update their doc file and plugin I also have to update my code; but if I get the Pay Now URL then WooCommerce and Gateway Plugin will take care of it.
Is there a better solution?
I got the solution in WooCommerce templates/emails/customer-invoice.php file. The function that I was looking for is get_checkout_payment_url().
Usage
$order = wc_get_order($order_id);
$pay_now_url = esc_url( $order->get_checkout_payment_url() );
echo $pay_now_url; //http://example.com/checkout/order-pay/{order_id}?pay_for_order=true&key={order_key}
//http://example.com will be site_url and protocol will depending upon SSL checkout WooCommerce setting.
But this url only works with pending, failed order status; So I used filter woocommerce_valid_order_statuses_for_payment
if (!function_exists('filter_woocommerce_valid_order_statuses_for_payment')) {
//http://woocommerce.wp-a2z.org/oik_api/wc_abstract_orderneeds_payment/
//http://hookr.io/filters/woocommerce_valid_order_statuses_for_payment/
// define the woocommerce_valid_order_statuses_for_payment callback
function filter_woocommerce_valid_order_statuses_for_payment( $array, $instance ) {
$my_order_status = array('cancelled', 'transaction-declined');
return array_merge($array, $my_order_status);
}
// add the filter
add_filter('woocommerce_valid_order_statuses_for_payment', 'filter_woocommerce_valid_order_statuses_for_payment', 10, 2);
}
^^ I added this in my active theme's functions.php file.
Reference:
get_checkout_payment_url()
wc_abstract_orderneeds_payment
woocommerce_valid_order_statuses_for_payment
You can get url with below code but it will work for wc-pending status order only, with the help of order_id or post_id
$order = wc_get_order($order_id);
echo $pay_now_url = $order->get_checkout_payment_url();
I created a plugin in wordpress to display earnings by using a shortcode.The details to display while using shortcode are stored in another database.I used direct database connection in plugin to fetch details from the that database.I used the following code
function earnings_shortcode($atts, $content, $tag)
{ //echo $atts[0];echo '<br>';
$str=base64_encode(1);
base64_decode($str);
$length = 4;
$res = trim(preg_replace("/[^0-9]/", "", $atts[0]));
$mydb1 = new wpdb('root','','db_test','localhost');
$rows = $mydb1->get_row("SELECT total,paydate FROM `tbl_shotcode` WHERE userid = $res", ARRAY_A);
echo "Payout on -" .$rows['paydate']; echo '<br/>';
echo "Total for next Pay Period:-" .$rows['total'];
}
Is there any better option to access another database inside a plugin with out hard coding the username and password.please suggest a solution.
No, you have to access the database and be authenticated to do queries. You can't get into a properly configured database without login in.
You can, however, make your $mydb1 variable global and define it at the top of your file (or in your constructor class) to be accessed by all your functions. I recommend putting it in a class to manage it more easily.
I have sugarcrm instance and want to fetch some data from it using a custom php code.
I am using nusoap client for this. I am able fetch the data but want to select data of particular id(record) only. what i am doing is
$response = $client->call('get_entry_list',array('session'=>$session_id , 'module_name'=>'itf_Apartments', 'where'=>'itf_Apartments.id=2', 'order_by'=>'','offset'=>'','select_fields'=>array('name')));
but iam not getting any results. is ther any problem with my code???
http://www.beanizer.org/site/index.php/en/Articles/Sugar-CRM-integration-with-custom-PHP-applications-I.html
Here you will find all answers.
Can you look at the sugarcrm.log file for the instance to see if there are any SQL errors in it? I'm betting the issue has something to do with the 'where' parameter.
Why not use just get_entry() ?
http://www.sugarcrm.com/forums/f6/problem-soap-get_entry-call-30248/
code below is what needed to be used and its same as you get in sugarcrm examples.
$proxy = new SoapClient('http://server.com/service/v2/soap.php?wsdl',array('exceptions' => 0));
$session = $proxy->login(array('user_name'=> $user , 'password' => md5($pass)));
$query= " customer.id IN ( select id from customer where customer.id = '" . $id . "' and deleted = 0)";
$result= $proxy->get_entry_list($session->id , 'customer', $query ,'', 0 ,array('email', 'username','password', 'name') ,null, 1000, -1 ) ;