Woocommerce API Show orders updated after a certain date - woocommerce

I'm looking for a way to get a list of orders that are updated after a certain specified date. I'm using the Woocommerce REST API to access these orders. In the API docs I find there is a 'after' parameter on a GET call, but this only filters for orders published after a certain date, not updated.
Thanks a lot!

Updated Answer:
Add the following code in a custom plugin.
function modify_orders_after_query($request) {
$request['date_query'][0]['column'] = 'post_modified';
return $request;
}
add_filter( "woocommerce_rest_shop_order_query", 'modify_orders_after_query' );
Then you can make GET request to your API url, Something like this:
http://example.com/wp-json/wc/v1/orders?after=2016-10-10T10:10:10Z
Notice: Please test before using this method.
Legacy:
This can be achieved with updated_at_min.
Please check wp-content\plugins\woocommerce\includes\api\class-wc-api-resource.php: Line 157 and wp-content\plugins\woocommerce\includes\api\class-wc-api-orders.php: Line 723

I've managed to solve the problem using the tips from above. Added a folder with a file in plugin folder, with the same name and the following content:
<?php
/**
* Plugin Name: wooCommerceFilter
* Description: Change the ORDER API endpoint to consider date_modified.
* Version: 1.0
*/
function modify_orders_after_query($request) {
$request['date_query'][0]['column'] = 'post_modified';
return $request;
}
add_filter( "woocommerce_rest_orders_prepare_object_query", 'modify_orders_after_query' );
?>

Related

Woocommerce get items in the orders before it is process on checkout

I am implementing syncing feature between WordPress and my other site. I want to sync orders to my other site before it is processed during checkout. I needed an items to be sync too, but I don't know what hook to used for this approach.
I tried using woocommerce_checkout_order_processed the order is already processed and save on the database. I want a hook that will only provide me some information about the order like booking, items and order data before it is being saved on the database. I needed this because if there is some errors during the sync I can cancel the order and it won't be save on the WordPress database.
I tried woocommerce_checkout_process hook. The problem is I can't get the items using this code.
function syncOrderAsEstimates($order_id) {
$order = wc_get_order($order_id);
$order->getItems(); // returns empty
}
add_action('woocommerce_checkout_process', 'syncOrderAsEstimates', 10, 1);
#Yves Try using this action hook(/includes/class-wc-checkout.php) :
/**
* Action hook to adjust order before save.
*
* #since 3.0.0
*/
do_action( 'woocommerce_checkout_create_order', $order, $data );
Thanks

How to get Pay Now URL with custom order status in WooCommerce?

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();

Gravity forms: Authorize.net Invoice number

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!

Custom Order Listing Page With WooCommerce

I have created a plugin which has a separate page for order listing.. in that it looks like the same as WooCommerce's Order Listing page but. i am unable to get the comments of the order so i added my custom post type to wc_order_types after that there is no order listed.. its showing a empty table. ?
add_filter( 'wc_order_types',array($this,'add_wc_order_types'),10,3);
public function add_wc_order_types($order_types,$type){
$order_types[] = WC_QD_PT;
return $order_types;
}
apply_filters( 'wc_order_types', $order_types, $for ); is default wc_filters which takes 2 parameters you have asked for 3 here add_filter( 'wc_order_types',array($this,'add_wc_order_types'),10,3); and again supplied 2.
visit http://docs.woothemes.com/wc-apidocs/source-function-wc_get_order_types.html#149 It may help you do this.
I Solved The issue just by adding a if condition in my hook's function
function add_wc_order_types($order_types,$type){
$order_type = $order_types;
if('' == $type){
$order_type[] = WC_QD_PT;
}
return $order_type;
}

Facing problems in creating video library using Brightcove Media API

I am facing a problem related to making a video library on my Drupal website using brightcove media API . Can someone please tell me how do I pull out the details of author, date posted and details about the video which I need to display along with the video on my page. I have somehow managed to display the video on my page but I am still struggling with pulling out other details and displaying it along with my video on the page. For your information, I am working in Drupal 6. Can someone please help me out with this??
You might want to check out the following helpful links:
http://opensource.brightcove.com/project/PHP-MAPI-Wrapper/
http://developer.brightcove.com/en/documentation
I'm not sure I understand what you mean by "author", Brightcove currently does not track audit trail type info. For example you cannot query who uploaded the video. Only metadata that belongs to the video.
Assuming "Author" is a custom field, you can obtain that info by doing a call something like:
/**
* function custom_search() - search specified field for given value
* #param string [$term] - Required. The value to search for.
* #param string [$criteria] - any, all, or none. Default: any.
* #param string [$search_field] - Specify the field to look for the search term in. Default: search_text.
*/
/** Available search fields: display_name, reference_id, tag, custom_fields, search_text.
* Using search_text is the equivalent of searching displayName, shortDescription and longDescription fields
* and is also the same as omitting the field name altogether
*/
function custom_search($term, $criteria = 'any', $search_field = 'search_text') {
$bc = create_bcmapi();
$params = array(
'video_fields' => 'id,name,shortDescription,referenceId,tags,custom_fields'
);
$terms = array($criteria => $search_field.':'.$term);
$data['videos'] = $bc->search('video', $terms, $params);
return $data;
}
Sorry this is late, but maybe it will help someone else.

Resources