On the admin side of Gravity form, I want to add a note if an admin user changes the status of the form entry. I have an admin only field so that bit is working and I know how to add note.
But can't work out, how to add note only if a certain field is changed. I need it to say something like 'status was updated from "approved" to "closed" by xxx'
Any help would be much appreciated.
Thanks.
add_action( 'gform_after_update_entry', function ( $form, $entry_id ) {
$current_user = wp_get_current_user();
$note = 'status updated from' . $status_from . ' to ' . $status_to . ' by ' . $current_user;
RGFormsModel::add_note( $entry_id, $current_user->ID, $current_user->display_name, $not );
}, 10, 2 );
Worked it out. For anyone who may need it. Answer below :)
add_action( 'gform_after_update_entry', 'update_entry', 10, 3 );
function update_entry( $form, $id, $original ) {
$entry = GFAPI::get_entry( $id );
$status_from = $original[ID_OF_THE_FIELD];
$status_to = $entry[ID_OF_THE_FIELD];
if($status_from != $status_to) {
$current_user = wp_get_current_user();
$message = 'Status updated from ' . $status_from . ' to ' . $status_to . ' by ' . $current_user->display_name;
RGFormsModel::add_note( $entry_id, $current_user->ID, $current_user->display_name, $message );
}
}
Related
I am trying to add text through functions.php just after subscription-price">
I can do this with direct code editing, but need help to apply filter through functions.php without changing orignal files.
$option_description = apply_filters( 'wcsatt_single_product_subscription_option_description', '<span class="' . $option_price_class . ' subscription-price">Text Here' . $sub_price_html . '</span>', $sub_price_html, $has_price_filter, false === $force_subscription, $product, $subscription_scheme );
$option = array(
'class' => 'subscription-option',
'value' => $scheme_key,
'selected' => $default_subscription_scheme_option_value === $scheme_key,
'description' => $option_description,
'data' => $option_data
);
something like that
add_filter( 'wcsatt_single_product_subscription_option_description', 'add_custom_text_to_subscription_option');
function add_custom_text_to_subscription_option( $product) {
}
This should suffice, basically anything you assign to the $option_descreption variable will be displayed
Replace Your new text in this answer, depending on your needs
function filter_wcsatt_single_product_subscription_option_description( $option_description, $sub_price_html, $has_price_filter, $force_subscription, $product, $subscription_scheme ) {
// Class
$option_price_class = 'subscription-option';
// New description
$option_description = '<span class="' . $option_price_class . ' subscription-price">Your new Text ' . $sub_price_html . '</span>';
return $option_description;
}
add_filter( 'wcsatt_single_product_subscription_option_description', 'filter_wcsatt_single_product_subscription_option_description', 10, 6 );
For the past week I have been trying to solve a problem related to a custom php script for WooCommerce.
The goal is to add functionality to the bulk order and retrieve the orders I selected and print them in an excel file.
The code is separated into two php files. One to grab the orders and print them on a text file. The second is the printing of the text file to Excel.
Based on How to get WooCommerce order details answer code here is my main script:
// Adding to admin order list bulk dropdown a custom action 'custom_downloads'
add_filter( 'bulk_actions-edit-shop_order', 'downloads_bulk_actions_edit_product', 20, 1 );
function downloads_bulk_actions_edit_product( $actions ) {
$actions['write_downloads'] = __( 'Download orders', 'woocommerce' );
return $actions;
}
// Make the action from selected orders
add_filter( 'handle_bulk_actions-edit-shop_order', 'downloads_handle_bulk_action_edit_shop_order', 10, 3 );
function downloads_handle_bulk_action_edit_shop_order( $redirect_to, $action, $post_ids ) {
if ( $action !== 'write_downloads' ) return $redirect_to; // Exit
$processed_ids = array();
$file = WP_PLUGIN_DIR."/xplugin/Order.txt";
$myfile = fopen($file, "w") or die("STOPP,unable to open file!");
foreach ( $post_ids as $post_id ) {
$order = wc_get_order( $post_id );
$order_data = $order->get_data();
$order_billing_first_name = $order_data['shipping']['first_name'];
$order_billing_last_name = $order_data['shipping']['last_name'];
$order_billing_address_1 = $order_data['shipping']['address_1'];
$order_billing_address_2 = $order_data['shipping']['address_2'];
$order_billing_postcode = $order_data['shipping']['postcode'];
//Hvis nummeret starter på 0 så må du fikse excel
$order_billing_phone = $order_data['billing']['phone'];
//hvis antallet tegn er 8 eller mindre må du legge på "+47"
if( mb_strlen($order_billing_phone) <= 8) {
$order_billing_phone = '+47'. $order_billing_phone;
}
$order_billing_email = $order_data['billing']['email'];
$Pose_på_dør = 'YES';
//Skriver til en den nyåpne tekstfila
fwrite($myfile,
$order_billing_first_name. ' ' .
$order_billing_last_name. '; ' .
$order_billing_address_1. '; ' .
$order_billing_address_2.'; ' .
$order_billing_postcode.'; ' .
$order_billing_first_name. ' ' .
$order_billing_last_name. '; ' .
$order_billing_phone.'; ' .
$order_billing_email.'; ' .
$order_billing_first_name. ' ' .
$order_billing_last_name. '; ' .
$order_billing_first_name. ' ' .
$order_billing_last_name. '; ' .
$Pose_på_dør. "\n"
);
$processed_ids[] = $post_id;
}
printExcel();
fclose($myfile);
return $redirect_to = add_query_arg( array(
'write_downloads' => '1',
'processed_count' => count( $processed_ids ),
'processed_ids' => implode( ',', $processed_ids ),
), $redirect_to );
}
// The results notice from bulk action on orders
add_action( 'admin_notices', 'downloads_bulk_action_admin_notice' );
function downloads_bulk_action_admin_notice() {
if ( empty( $_REQUEST['write_downloads'] ) ) return; // Exit
$count = intval( $_REQUEST['processed_count'] );
printf( '<div id="message" class="updated fade"><p>' .
_n( 'Processed %s Order for downloads.',
'Processed %s Orders for downloads.',
$count,
'write_downloads'
) . '</p></div>', $count );
}
function printExcel() {
include 'print.php';
}
Both scripts behave well, but when I go about combining them with an
function printExcel() {
include 'print.php';
}
it goes wrong.
I'm not able to execute the "print.php" script at the right time.I would like it to run after admin notice is done updating.
I have tried to make an action for different hooks, but not successfully. Can anyone point me in the right direction?
Any suggestions on how to improve the script are much appreciated.
I'm retrieving a value using php cookies from a plugin to woocommerce thankyou page and customer order detail page, it works fine on thankyou page but didn't print anything on email order detail page, how would I fix this?
I have tried fetching values using php sessions, it prints value only for 10 to 15 minutes, after that it doesn't print anything, can anyone help me to retrieve values using PHP cookie.
From here I want to fetch Post ID
<?php
if('on' == $display_ticket_number){
echo '#' . $post->ID . ' ';
}
echo $post->post_title;
$ticketid = $post->ID;
setcookie ("ticketidno",$ticketid, time() +60, "/");
?>
On thankyou.php it prints value
<?php echo $_COOKIE["ticketidno"];?>
email-order-details.php here it doesn't print
<?php echo $_COOKIE["ticketidno"];?>
Edit
I want to get and display cookie value on:
Email Notification, for emails/email-order-details.php template file on this hook:
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); ?>
So before Order Table.
Text SMS Plugin: plugins/woocommerce-apg-sms-notifications/includes/admin/proveedores.php
case "solutions_infini":
$respuesta = wp_remote_get( "http://api-global.solutionsinfini.com/v3/?api_key=" . $apg_sms_settings['clave_solutions_infini'] . "&method=sms" . "&to=" . $telefono . "&sender=" . $apg_sms_settings['identificador_solutions_infini'] . "&message=" . "Thanks for Registering in ". $_SESSION['post_title'] . " your Registration ID no is THR". $_COOKIE["ticketidno"] . apg_sms_codifica_el_mensaje( $mensaje ));
break;
Replacing $_COOKIE["ticketidno"]
Any help is appreciated.
Updated
You should need to grab the cookie value as custom order meta data in thankyou "Order received" page:
add_action( 'woocommerce_thankyou', 'thankyou_grab_cookie_as_meta_data', 10, 1 );
function thankyou_grab_cookie_as_meta_data( $order_id ){
if( ! $order_id ){
return;
}
if( isset($_COOKIE["ticketidno"]) && ! get_post_meta( $order_id, '_cookie_ticketidno', true ) ) {
update_post_meta( $order_id, '_cookie_ticketidno', esc_attr($_COOKIE["ticketidno"]) );
}
}
Code goes on function.php file of your active child theme (or active theme). It should works.
The you will be able to get this grabbed cookie value using:
From the Order ID: $cookie = get_post_meta( $order_id, '_cookie_ticketidno', true );
From the Order Object: $order->get_meta( '_cookie_ticketidno' ); // (on Woocommerce 3+)
Display in email notifications:
// Email notifications display
add_action( 'woocommerce_email_order_details', 'add_order_instruction_email', 5, 4 );
function add_order_instruction_email( $order, $sent_to_admin, $plain_text, $email ) {
if( $value = $order->get_meta('_cookie_ticketidno') )
echo '<p class="ticket-id">' .__('Ticket Id Number: ') . $value . '</p>';
}
Code goes on function.php file of your active child theme (or active theme).
Display on "Order received" page (thankyou):
// On "Order received" page (on start)
add_filter( 'woocommerce_thankyou_order_received_text', 'thankyou_custom_order_received_text', 10, 2 );
function thankyou_custom_order_received_text( $text, $order ) {
if ( $value = $order->get_meta('_cookie_ticketidno') ) {
$text .= '<br><div class="ticket-id"><p>' . __('Ticket Id Number: ') . $value . '</p></div>' ;
}
return $text;
}
Code goes on function.php file of your active child theme (or active theme).
For SMS - As this requires the order ID, try the following without any guaranty:
case "solutions_infini":
$respuesta = wp_remote_get( "http://api-global.solutionsinfini.com/v3/?api_key=" . $apg_sms_settings['clave_solutions_infini'] . "&method=sms" . "&to=" . $telefono . "&sender=" . $apg_sms_settings['identificador_solutions_infini'] . "&message=" . "Thanks for Registering in ". $_SESSION['post_title'] . " your Registration ID no is THR". get_post_meta( $_SESSION['ID'], '_cookie_ticketidno', true ) . apg_sms_codifica_el_mensaje( $mensaje ));
break;
Code should goes on proveedores.php file in your plugin, Just replacing in the code:
$_COOKIE["ticketidno"]
by:
get_post_meta( $_SESSION['ID'], '_cookie_ticketidno', true )
where $_SESSION['ID'] (I suppose and I hope) should be the order ID.
I am trying to find a way on how to add the customer phone and email below the name on the WooCommerce order view. See picture for reference where I need to add this information.
Any ideas, tips or pointers on how to make this happen?
The following code will add the billing phone and email under the order number in backend orders list (for Woocommerce 3.3+ only):
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 50, 2 );
function custom_orders_list_column_content( $column, $post_id ) {
if ( $column == 'order_number' )
{
global $the_order;
if( $phone = $the_order->get_billing_phone() ){
$phone_wp_dashicon = '<span class="dashicons dashicons-phone"></span> ';
echo '<br>' . $phone_wp_dashicon . $phone.'</strong>';
}
if( $email = $the_order->get_billing_email() ){
echo '<br><strong>' . $email . '</strong>';
}
}
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
Thank you, worked perfectly.
I had modifed based on my need, adding the code here for others.
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 50, 2 );
function custom_orders_list_column_content( $column, $post_id ) {
if ( $column == 'order_number' )
{
global $the_order;
if( $phone = $the_order->get_billing_phone() ){
$phone_wp_dashicon = '<span class="dashicons dashicons-phone"></span> ';
echo '<br>Mobile: '.'' . $phone.'</strong>';
}
if( $email = $the_order->get_billing_email() ){
echo '<br>Email: '.'' . $email . '';
}
}
}
I'm basically trying to remove taxonomy bases from my urls e.g from this:
http://www.example.com/posttype/tax/term1/tax/term2
To this:
http://www.example.com/postype/term1/term2
I've read many posts stating that this is impossible to achieve. However I've come across many sites that have achieved this. So I'm asking this question in hope that someone out here has managed to achieve this.
My rewrite code:
function add_query_vars( $query_vars ) {
$new_vars = array( 'vehicle-type', 'fuel', 'color', 'status', 'gearbox', 'interior', 'exterior', 'safety', 'extra', 'location', 'vehicle-year', 'model' );
return array_merge( $new_vars, $query_vars );
}
add_filter( 'query_vars', 'add_query_vars' );`
function add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
'vehicles/vehicle_status/(.+?)/vehicle_fuel_type/(.+?)/vehicle_color/(.+?)/vehicle_status/(.+?)/vehicle_gearbox/(.+?)/vehicle_interior_feature/(.+?)/vehicle_exterior_feature/(.+?)/vehicle_safety_feature/(.+?)/vehicle_extra/(.+?)/vehicle_location/(.+?)/vehicle_year/(.+?)/vehicle_model/(.+?)/?$' => 'index.php?post_type=vehicles&vehicle_status=' . $wp_rewrite->preg_index(1) . '&vehicle_fuel_type=' . $wp_rewrite->preg_index(2) . '&vehicle_color=' . $wp_rewrite->preg_index(3) . '&vehicle_status=' . $wp_rewrite->preg_index(4) . '&vehicle_gearbox=' . $wp_rewrite->preg_index(5) . '&vehicle_interior_feature=' . $wp_rewrite->preg_index(6) . '&vehicle_exterior_feature=' . $wp_rewrite->preg_index(7) . '&vehicle_safety_feature=' . $wp_rewrite->preg_index(8) .'&vehicle_extra=' . $wp_rewrite->preg_index(9) .'&vehicle_location=' . $wp_rewrite->preg_index(10) . '&vehicle_year=' . $wp_rewrite->preg_index(11) . '&vehicle_model=' . $wp_rewrite->preg_index(12)' ) ;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');`
Go to settings -> permalinks in wordpress panel. Select permalink structure as you want.