我正在使用 WooCommerce 订阅。
如何获取列表中从一个特定日期到另一个日期的所有订阅(包括开始日期和结束日期)?
Example 01/09/2016 to 15/09/2016
谢谢
最佳答案
这是一个函数示例,它将在格式化的 html 表格中显示从一个日期到另一个日期的所有事件订阅的列表。在此示例中,您将为每个订阅获取:订阅 ID、日期、客户 ID 和客户名称(您可以自定义代码以获取所需内容)。
所以这个函数有 2 个日期参数。有关用法和规范,请参阅末尾部分。
函数代码:
function active_subscription_list($from_date=null, $to_date=null) {
// Get all customer orders
$subscriptions = get_posts( array(
'numberposts' => -1,
'post_type' => 'shop_subscription', // Subscription post type
'post_status' => 'wc-active', // Active subscription
'orderby' => 'post_date', // ordered by date
'order' => 'ASC',
'date_query' => array( // Start & end date
array(
'after' => $from_date,
'before' => $to_date,
'inclusive' => true,
),
),
) );
// Styles (temporary, only for demo display) should be removed
echo "<style>
.subscription_list th, .subscription_list td{border:solid 1px #666; padding:2px 5px;}
.subscription_list th{font-weight:bold}
.subscription_list td{text-align:center}
</style>";
// Displaying list in an html table
echo "<table class='shop_table subscription_list'>
<tr>
<th>" . __( 'Number ID', 'your_theme_domain' ) . "</th>
<th>" . __( 'Date', 'your_theme_domain' ) . "</th>
<th>" . __( 'User ID', 'your_theme_domain' ) . "</th>
<th>" . __( 'User Name', 'your_theme_domain' ) . "</th>
</tr>
";
// Going through each current customer orders
foreach ( $subscriptions as $subscription ) {
$subscription_id = $subscription->ID; // subscription ID
$subscription_date = array_shift( explode( ' ', $subscription->post_date ) ); // Date
$subscr_meta_data = get_post_meta($subscription->ID);
$customer_id = $subscr_meta_data['_customer_user'][0]; // customer ID
$customer_name = $subscr_meta_data['_billing_first_name'][0] . ' ' . $subscr_meta_data['_billing_last_name'][0];
echo "</tr>
<td>$subscription_id</td>
<td>$subscription_date</td>
<td>$customer_id</td>
<td>$customer_name</td>
</tr>";
}
echo '</table>';
}
此代码位于您的事件子主题(或主题)的 function.php 文件中或任何插件文件中。
用法 (示例):
您必须遵守以下数字日期格式:YEAR-MONTH-DAY
$from_date = '2016-06-19'; // start date
$to_date = '2016-09-21'; // End date
active_subscription_list($from_date, $to_date);
这将显示从 2016-06-19 到 2016-09-21 的所有事件订阅的列表......
此代码已经过测试并且可以工作。
关于php - WooCommerce - 在开始/结束日期之间的列表中获取事件订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39596477/
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url
我的日期格式如下:"%d-%m-%Y"(例如,今天的日期为07-09-2015),我想看看是不是在过去的七天内。谁能推荐一种方法? 最佳答案 你可以这样做:require"date"Date.today-7 关于ruby-检查日期是否在过去7天内,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/32438063/
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build