Compare commits
44 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
56e03c0544 | |
|
|
bfe7fb609d | |
|
|
c7e30d354e | |
|
|
dda5b19e32 | |
|
|
c8ec766bf2 | |
|
|
7b355505bf | |
|
|
708a1fa4a4 | |
|
|
7d081fb691 | |
|
|
9932a571ff | |
|
|
7041a483f0 | |
|
|
8d2f68f6e7 | |
|
|
c0994caaed | |
|
|
924e4d86bd | |
|
|
c2175bfc37 | |
|
|
60e548cc2d | |
|
|
37e1464122 | |
|
|
147748f6c7 | |
|
|
1d59fa1a59 | |
|
|
d7d1890c54 | |
|
|
15b2c611fc | |
|
|
60a125d936 | |
|
|
8c0d9ae33c | |
|
|
8b0433022a | |
|
|
b811acfcf3 | |
|
|
ccb5fe37b5 | |
|
|
072c76acb5 | |
|
|
ca6f1789c9 | |
|
|
a8df935923 | |
|
|
b2a4dd8022 | |
|
|
73217b1ff9 | |
|
|
f98586942f | |
|
|
fbfd2242d2 | |
|
|
7bd88fa86c | |
|
|
cc9b3f8f53 | |
|
|
d3348c6c8f | |
|
|
e40fc0f53b | |
|
|
e3e24b965e | |
|
|
0e446ec239 | |
|
|
5521497bf2 | |
|
|
a87183cf97 | |
|
|
5eedf6aedb | |
|
|
ad47a6a8b3 | |
|
|
e36f44ebee | |
|
|
cda4fb2a79 |
|
|
@ -163,7 +163,7 @@ mkdir( $plugins_dir );
|
|||
|
||||
$plugin_dir = $plugins_dir . '/woocommerce-subscriptions';
|
||||
|
||||
$zip_file = $archives_dir . '/woocommerce-subscriptions-' . $version . '.zip';
|
||||
$zip_file = $archives_dir . '/woocommerce-subscriptions.' . $version . '.zip';
|
||||
|
||||
/**
|
||||
* Download ZIP.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
name: Deploy to Pronamic WordPress directory
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Release tag to deploy'
|
||||
type: string
|
||||
release:
|
||||
types: [released]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
environment:
|
||||
name: Pronamic WordPress directory
|
||||
url: https://wp.pronamic.directory/plugins/woocommerce-subscriptions/
|
||||
|
||||
permissions:
|
||||
contents: 'read'
|
||||
id-token: 'write'
|
||||
|
||||
steps:
|
||||
- name: Deploy
|
||||
uses: pronamic/action-wp-pronamic-directory-plugin-deploy@main
|
||||
with:
|
||||
username: ${{ vars.WP_PRONAMIC_DIRECTORY_USERNAME }}
|
||||
password: ${{ secrets.WP_PRONAMIC_DIRECTORY_PASSWORD }}
|
||||
slug: woocommerce-subscriptions
|
||||
tag: ${{ inputs.tag || github.event.release.tag_name }}
|
||||
|
|
@ -27,7 +27,7 @@ ul {
|
|||
}
|
||||
.wcs-badge {
|
||||
position: relative;
|
||||
background: #9c5d90;
|
||||
background: #7F54B3;
|
||||
text-rendering: optimizeLegibility;
|
||||
padding-top: 150px;
|
||||
height: 52px;
|
||||
|
|
@ -35,7 +35,7 @@ ul {
|
|||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
color: #ddc8d9;
|
||||
color: #fff;
|
||||
margin: 5px 0 0 0;
|
||||
-webkit-box-shadow: 0 1px 3px rgba( 0, 0, 0, 0.2 );
|
||||
box-shadow: 0 1px 3px rgba( 0, 0, 0, 0.2 );
|
||||
|
|
@ -92,44 +92,10 @@ ul {
|
|||
}
|
||||
.woocommerce-message {
|
||||
position: relative;
|
||||
border-left-color: #cc99c2 !important;
|
||||
border-left-color: #7F54B3 !important;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.woocommerce-message a.button-primary,
|
||||
p.woocommerce-actions a.button-primary,
|
||||
.woocommerce-message a.button-primary:focus,
|
||||
p.woocommerce-actions a.button-primary:focus,
|
||||
.woocommerce-message a.button-primary:active,
|
||||
p.woocommerce-actions a.button-primary:active {
|
||||
background: #b366a4;
|
||||
border-color: #b366a4;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba( 255, 255, 255, 0.25 ),
|
||||
0 1px 0 rgba( 0, 0, 0, 0.15 );
|
||||
box-shadow: inset 0 1px 0 rgba( 255, 255, 255, 0.25 ),
|
||||
0 1px 0 rgba( 0, 0, 0, 0.15 );
|
||||
text-shadow: 0 -1px 1px #b366a4, 1px 0 1px #b366a4, 0 1px 1px #b366a4,
|
||||
-1px 0 1px #b366a4;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.woocommerce-message a.button-primary:hover,
|
||||
p.woocommerce-actions a.button-primary:hover {
|
||||
background: #bb77ae;
|
||||
border-color: #aa559a;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba( 255, 255, 255, 0.25 ),
|
||||
0 1px 0 rgba( 0, 0, 0, 0.15 );
|
||||
box-shadow: inset 0 1px 0 rgba( 255, 255, 255, 0.25 ),
|
||||
0 1px 0 rgba( 0, 0, 0, 0.15 );
|
||||
}
|
||||
|
||||
.woocommerce-message a.button-primary:active,
|
||||
p.woocommerce-actions a.button-primary:active {
|
||||
background: #aa559a;
|
||||
border-color: #aa559a;
|
||||
}
|
||||
|
||||
.woocommerce-message a.skip,
|
||||
p.woocommerce-actions a.skip {
|
||||
opacity: 0.7;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
.woo_subscriptions_empty_state__container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 48px 0;
|
||||
position: static;
|
||||
height: 344px;
|
||||
left: calc(50% - 1240px / 2);
|
||||
top: 271px;
|
||||
flex: none;
|
||||
order: 1;
|
||||
flex-grow: 0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
.woo_subscriptions_empty_state__container .woo_subscriptions_empty_state__description {
|
||||
max-width: 535px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
.woo_subscriptions_empty_state__button_container {
|
||||
margin: 8px 0;
|
||||
}
|
||||
.woo_subscriptions_empty_state__container .woo_subscriptions_empty_state__button_container * + * {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
|
@ -2,19 +2,6 @@
|
|||
.woocommerce-subscriptions-activated p a.button-primary {
|
||||
display: inline-block;
|
||||
}
|
||||
.woocommerce-subscriptions-activated a.button-primary:hover {
|
||||
background: #bb77ae;
|
||||
border-color: #aa559a;
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba( 255, 255, 255, 0.25 ),
|
||||
0 1px 0 rgba( 0, 0, 0, 0.15 );
|
||||
box-shadow: inset 0 1px 0 rgba( 255, 255, 255, 0.25 ),
|
||||
0 1px 0 rgba( 0, 0, 0, 0.15 );
|
||||
}
|
||||
.woocommerce-subscriptions-activated a.button-primary:active,
|
||||
.woocommerce-subscriptions-activated a.button-primary:active {
|
||||
background: #aa559a;
|
||||
border-color: #aa559a;
|
||||
}
|
||||
|
||||
/* Subscriptions Admin Page */
|
||||
.woocommerce_page_wc-orders--shop_subscription .tablenav input,
|
||||
|
|
@ -90,6 +77,62 @@ a.close-subscriptions-search {
|
|||
display: block;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.woocommerce_options_panel ._subscription_downloads_field .description,
|
||||
.woocommerce_options_panel .subscription_linked_downloadable_products .description {
|
||||
clear: both;
|
||||
display: block;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Variation Subscription Product Sync Settings */
|
||||
.variable_subscription_sync .subscription_sync_annual > .select2-container {
|
||||
max-width: 48%;
|
||||
}
|
||||
.variable_subscription_sync .subscription_sync_annual > .select2-container:last-child {
|
||||
float: right;
|
||||
}
|
||||
#woocommerce-product-data .variable_subscription_pricing ._subscription_length_field .wc_input_subscription_length + .select2,
|
||||
#woocommerce-product-data .variable_subscription_sync .subscription_sync_week_month .wc_input_subscription_payment_sync + .select2,
|
||||
#woocommerce-product-data .variable_subscription_gifting ._subscription_gifting_field .wc_input_subscription_gifting + .select2 {
|
||||
width: 100% !important;
|
||||
}
|
||||
/* Simple Subscription Product Sync Settings */
|
||||
._subscription_trial_length_field .select2-container:last-child,
|
||||
#general_product_data .subscription_sync_annual .select2-container:last-child {
|
||||
width: 45% !important;
|
||||
margin-left: 5%;
|
||||
}
|
||||
._subscription_trial_length_field .select2-container:not( :last-child ),
|
||||
#general_product_data .subscription_sync_annual .select2-container:not( :last-child ) {
|
||||
width: 50% !important;
|
||||
}
|
||||
/* Simple Subscription Product Gifting Settings */
|
||||
._subscription_gifting_field .select2-container {
|
||||
width: 50% !important;
|
||||
}
|
||||
p.show_if_variable-subscription._subscription_gifting_field {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
p._subscription_gifting_field.overriding-store-settings {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
p._subscription_gifting_field_description.form-field {
|
||||
padding-top: 0 !important;
|
||||
margin-top: 0;
|
||||
}
|
||||
p._subscription_gifting_field_description.form-field .description {
|
||||
display: block;
|
||||
clear: both;
|
||||
margin-left: 0;
|
||||
}
|
||||
.variable_subscription_gifting p._subscription_gifting_field_description {
|
||||
margin-bottom: 0;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
|
||||
@media only screen and ( max-width: 1280px ) {
|
||||
.woocommerce_options_panel ._subscription_price_fields .wrap,
|
||||
.woocommerce_options_panel ._subscription_trial_length_field .wrap,
|
||||
|
|
@ -98,14 +141,15 @@ a.close-subscriptions-search {
|
|||
.wrap {
|
||||
width: 80%;
|
||||
}
|
||||
._subscription_gifting_field .select2-container {
|
||||
width: 80% !important;
|
||||
}
|
||||
}
|
||||
.woocommerce_options_panel ._subscription_price_fields .wrap input,
|
||||
.woocommerce_options_panel ._subscription_price_fields .wrap select {
|
||||
width: 30.75%;
|
||||
margin-right: 3.8%;
|
||||
width: 30%;
|
||||
margin-right: 5%;
|
||||
}
|
||||
.woocommerce_options_panel ._subscription_trial_length_field .wrap input,
|
||||
.woocommerce_options_panel ._subscription_trial_length_field .wrap select,
|
||||
.woocommerce_options_panel
|
||||
._subscription_payment_sync_date_day_field
|
||||
.wrap
|
||||
|
|
@ -314,6 +358,27 @@ a.close-subscriptions-search {
|
|||
width: auto !important;
|
||||
}
|
||||
|
||||
#woocommerce-product-data .wc_input_subscription_length +.select2,
|
||||
#woocommerce-product-data .wc_input_subscription_payment_sync +.select2,
|
||||
#_subscription_limit +.select2 {
|
||||
width: 50% !important;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.wc_input_subscription_period + .select2 {
|
||||
width: 30% !important;
|
||||
margin-top: 0;
|
||||
}
|
||||
.wc_input_subscription_trial_period + .select2 {
|
||||
width: 50% !important;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#general_product_data .wc_input_subscription_period_interval + .select2 {
|
||||
margin-right: 5%;
|
||||
width: 30% !important;
|
||||
}
|
||||
|
||||
.variable_subscription_sync p._subscription_payment_sync_field {
|
||||
padding-left: 0 !important;
|
||||
}
|
||||
|
|
@ -328,9 +393,16 @@ a.close-subscriptions-search {
|
|||
opacity: 0.5;
|
||||
}
|
||||
|
||||
#woocommerce-product-data
|
||||
.form-field._subscription_downloads_field
|
||||
.select2-selection__choice {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Variation Pricing Fields with WooCommerce 3.0+ */
|
||||
.wc-metaboxes-wrapper .variable_subscription_trial label,
|
||||
.wc-metaboxes-wrapper .variable_subscription_pricing label,
|
||||
.wc-metaboxes-wrapper .variable_subscription_gifting label,
|
||||
.wc-metaboxes-wrapper .variable_subscription_sync label {
|
||||
display: block;
|
||||
}
|
||||
|
|
@ -357,10 +429,42 @@ a.close-subscriptions-search {
|
|||
.wc_input_subscription_price,
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
.wc_input_subscription_period_interval {
|
||||
max-width: 33%;
|
||||
.wc_input_subscription_period + .select2,
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
.wc_input_subscription_period_interval + .select2 {
|
||||
width: calc( 100% / 3 ) !important;
|
||||
float: left;
|
||||
}
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
.wc_input_subscription_period + .select2,
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
.wc_input_subscription_period_interval + .select2 {
|
||||
padding-bottom: 2px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
#variable_product_options
|
||||
.select2-container
|
||||
.select2-selection--single {
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
#variable_product_options
|
||||
.select2-container
|
||||
.select2-selection--single
|
||||
.select2-selection__rendered {
|
||||
line-height: 36px;
|
||||
}
|
||||
#variable_product_options
|
||||
.select2-container
|
||||
.select2-selection--single
|
||||
.select2-selection__arrow {
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.variable_subscription_pricing_2_3 .wc_input_subscription_price {
|
||||
clear: left;
|
||||
}
|
||||
|
|
@ -370,18 +474,24 @@ a.close-subscriptions-search {
|
|||
max-width: 34%;
|
||||
float: right;
|
||||
}
|
||||
.variable_subscription_pricing_2_3.variable_subscription_trial p.form-row {
|
||||
.variable_subscription_pricing_2_3.variable_subscription_pricing p.form-row {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
p._subscription_price_field {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
.wc_input_subscription_trial_period,
|
||||
.wc_input_subscription_trial_period + .select2,
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
.wc_input_subscription_trial_length {
|
||||
max-width: 50%;
|
||||
width: 50%;
|
||||
}
|
||||
.variable_subscription_pricing_2_3 .wc_input_subscription_trial_period {
|
||||
.variable_subscription_pricing_2_3 .wc_input_subscription_trial_period + .select2 {
|
||||
margin-top: 2px;
|
||||
float: right;
|
||||
}
|
||||
.variable_subscription_pricing_2_3 .variable_subscription_length,
|
||||
|
|
@ -399,6 +509,11 @@ a.close-subscriptions-search {
|
|||
.wc_input_subscription_payment_sync_month {
|
||||
max-width: 86%;
|
||||
}
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3 .multiple_fields .wrap {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
@media screen and ( max-width: 1190px ) {
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
|
|
@ -412,7 +527,6 @@ a.close-subscriptions-search {
|
|||
.variable_subscription_pricing_2_3
|
||||
p._subscription_price_field {
|
||||
width: 100%;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#variable_product_options
|
||||
.variable_subscription_pricing_2_3
|
||||
|
|
@ -496,6 +610,19 @@ a.close-subscriptions-search {
|
|||
display: inline-block;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#woocommerce-subscription-schedule .date-fields.has-error {
|
||||
color: #d63638;
|
||||
}
|
||||
|
||||
#woocommerce-subscription-schedule .date-fields .message {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#woocommerce-subscription-schedule .date-fields.has-error input {
|
||||
border-color: #d63638;
|
||||
}
|
||||
|
||||
#woocommerce-subscription-schedule
|
||||
.wcs-date-input
|
||||
input[type='text']:first-of-type {
|
||||
|
|
@ -735,7 +862,7 @@ table.wp-list-table .subscription_renewal_order::after {
|
|||
height: 100%;
|
||||
text-align: center;
|
||||
content: '\e018';
|
||||
color: #a46497;
|
||||
color: var(--wp-admin-theme-color);
|
||||
}
|
||||
|
||||
table.wc_gateways .renewals .tips {
|
||||
|
|
@ -816,6 +943,10 @@ span.product-type.variable-subscription::before {
|
|||
width: 400px;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
table.form-table input#woocommerce_subscriptions_customer_notifications_offset {
|
||||
/* Aligns with .woocommerce table.form-table select */
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
/* Reports Page */
|
||||
.woocommerce-reports-wide .postbox .chart-legend li a {
|
||||
|
|
@ -857,3 +988,26 @@ span.product-type.variable-subscription::before {
|
|||
#wcs_order_price_lock > .woocommerce-help-tip {
|
||||
margin: 0 8px 0 2px;
|
||||
}
|
||||
.show_if_subscription .select2-selection, .show_if_variable-subscription .select2-selection {
|
||||
font-size: 14px;
|
||||
}
|
||||
.wc-settings-row-enable-gifting.checked .titledesc {
|
||||
padding-bottom: 14px;
|
||||
}
|
||||
.wc-settings-row-enable-gifting.checked .forminp-checkbox {
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.wc-settings-row-gifting-radios td {
|
||||
padding-top: 0;
|
||||
}
|
||||
.wc-settings-row-gifting-radios th {
|
||||
padding-top: 0;
|
||||
}
|
||||
.wc-settings-row-gifting-radios li:nth-child(2) label {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
.wc-settings-row-gifting-radios p {
|
||||
margin: 2px 0 5px;
|
||||
color: #646970;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
.wc-shortcode-components-validation-error {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#shortcode-validate-error-invalid-gifting-recipient {
|
||||
font-size: 0.75em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: -12px;
|
||||
margin-bottom: 20px;
|
||||
|
||||
}
|
||||
|
||||
#shortcode-validate-error-invalid-gifting-recipient svg {
|
||||
fill: var(--wc-red, #cc1818);
|
||||
|
||||
}
|
||||
|
||||
#shortcode-validate-error-invalid-gifting-recipient span {
|
||||
color: var(--wc-red, #cc1818);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
font-style: normal;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
||||
.woocommerce .woocommerce_subscriptions_gifting_recipient_email .input-text.recipient_email.wcsg-email-error {
|
||||
border-color: var(--wc-red, #cc1818);
|
||||
color: var(--wc-red, #cc1818);
|
||||
}
|
||||
|
||||
.wcsg_add_recipient_fields_container label {
|
||||
display: inline-block;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.woocommerce-cart-form__cart-item .wcsg_add_recipient_fields_container label {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.wcsg_add_recipient_fields_container .wcsg_add_recipient_fields .woocommerce_subscriptions_gifting_recipient_email {
|
||||
padding: 0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.wcsg_add_recipient_fields_container .wcsg_add_recipient_fields.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wcsg_add_recipient_fields_container .recipient_email:focus {
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
#woocommerce_subscriptions_gifting_field {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
#woocommerce_subscriptions_gifting_field div {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
max-width: 100%;
|
||||
word-break: break-all;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
|
@ -3,10 +3,10 @@ body.wcs-modal-open {
|
|||
}
|
||||
|
||||
.wcs-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 0;
|
||||
|
|
@ -17,6 +17,7 @@ body.wcs-modal-open {
|
|||
}
|
||||
|
||||
.wcs-modal.open {
|
||||
display: flex;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
|
|
@ -50,6 +51,10 @@ body.wcs-modal-open {
|
|||
top: 0;
|
||||
right: 0;
|
||||
z-index: 50;
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.wcs-modal .content-wrapper .modal-header {
|
||||
|
|
@ -1,12 +1,31 @@
|
|||
@media only screen and ( max-width: 768px ) {
|
||||
.subscription_details .button {
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 2px;
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
width: 100%;
|
||||
max-width: 200px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.subscription_details .button {
|
||||
display: inline-block;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
button.subscription-auto-renew-toggle,
|
||||
button.subscription-auto-renew-toggle:hover {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
box-shadow: none;
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.subscription-auto-renew-toggle {
|
||||
margin-left: 5px;
|
||||
margin-bottom: 2px;
|
||||
|
|
@ -82,3 +101,46 @@
|
|||
font-size: 1.4em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.woocommerce-subscriptions-related-orders-pagination-links.woocommerce-pagination {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1em;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.woocommerce-subscriptions-related-orders-pagination-links .pagination-links a {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.woocommerce-subscriptions-related-orders-pagination-links .pagination-links a.disabled:hover {
|
||||
cursor: default;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.woocommerce-subscriptions-related-orders-pagination-links .pagination-links a .symbol {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.rtl .woocommerce-subscriptions-related-orders-pagination-links {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.rtl .woocommerce-subscriptions-related-orders-pagination-links .pagination-links {
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
@media ( max-width: 30em ) {
|
||||
.woocommerce-subscriptions-related-orders-pagination-links .pagination-links a {
|
||||
padding: 0.5em 1em;
|
||||
}
|
||||
|
||||
.woocommerce-subscriptions-related-orders-pagination-links .pagination-links a .label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.woocommerce-subscriptions-related-orders-pagination-links .pagination-links a .symbol {
|
||||
display: inherit;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 885 B After Width: | Height: | Size: 885 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
|
|
@ -0,0 +1,26 @@
|
|||
<svg width="141" height="115" viewBox="0 0 141 115" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M104.686 23.5272H42.6647C38.3831 23.5272 34.9121 26.9982 34.9121 31.2798V86.8401C34.9121 91.1218 38.3831 94.5927 42.6647 94.5927H104.686C108.967 94.5927 112.438 91.1218 112.438 86.8401V31.2798C112.438 26.9982 108.967 23.5272 104.686 23.5272Z" fill="#D1C1FF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M104.686 23.5272H42.6647C38.3827 23.5272 34.9121 26.9978 34.9121 31.2798V42.9087H112.438V31.2798C112.438 26.9978 108.968 23.5272 104.686 23.5272Z" fill="#A77EFF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M112.434 61.4844V86.8405C112.434 91.1226 108.963 94.5932 104.681 94.5932H79.3252C97.611 94.5932 112.434 79.7702 112.434 61.4844Z" fill="#2C045D" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M73.6715 34.8336C76.3476 34.8336 78.5169 32.6642 78.5169 29.9882C78.5169 27.3122 76.3476 25.1428 73.6715 25.1428C70.9955 25.1428 68.8262 27.3122 68.8262 29.9882C68.8262 32.6642 70.9955 34.8336 73.6715 34.8336Z" fill="#2C045D" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M54.2917 34.8336C56.9677 34.8336 59.137 32.6642 59.137 29.9882C59.137 27.3122 56.9677 25.1428 54.2917 25.1428C51.6156 25.1428 49.4463 27.3122 49.4463 29.9882C49.4463 32.6642 51.6156 34.8336 54.2917 34.8336Z" fill="#2C045D" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M76.9023 29.0193V19.6516C76.9023 18.2244 75.7454 17.0674 74.3181 17.0674H73.026C71.5988 17.0674 70.4418 18.2244 70.4418 19.6516V29.0193C70.4418 30.4465 71.5988 31.6035 73.026 31.6035H74.3181C75.7454 31.6035 76.9023 30.4465 76.9023 29.0193Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M57.5215 29.0193V19.6516C57.5215 18.2244 56.3645 17.0674 54.9373 17.0674H53.6452C52.218 17.0674 51.061 18.2244 51.061 19.6516V29.0193C51.061 30.4465 52.218 31.6035 53.6452 31.6035H54.9373C56.3645 31.6035 57.5215 30.4465 57.5215 29.0193Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M61.6236 82.6491C59.458 82.6491 57.6956 80.8866 57.6956 78.7211V63.6707C57.6956 63.5285 57.5457 63.5234 57.5431 63.5234C57.5121 63.5234 57.4863 63.5337 57.4553 63.557L56.4733 64.3503C55.8867 64.8258 55.1864 65.0765 54.4499 65.0765C52.659 65.0765 51.2041 63.6242 51.2041 61.8385C51.2041 60.8126 51.6977 59.8383 52.5246 59.231L58.7164 54.6828C59.458 54.1376 60.3367 53.8507 61.2566 53.8507C63.6238 53.8507 65.549 55.7759 65.549 58.1431V78.7236C65.549 80.8892 63.7866 82.6516 61.621 82.6516L61.6236 82.6491Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-miterlimit="10"/>
|
||||
<path d="M72.0717 82.6493C70.0587 82.6493 68.4229 81.0109 68.4229 79.0004C68.4229 77.7109 69.1154 76.504 70.2266 75.8502L80.4213 69.8807C82.3078 68.7979 83.7911 67.8547 84.8377 67.0743C85.8274 66.3378 86.5278 65.6581 86.9231 65.056C87.2849 64.5056 87.4581 63.9371 87.4581 63.3194C87.4581 62.6656 87.2875 62.1049 86.9387 61.6087C86.5872 61.11 86.0393 60.7094 85.308 60.4174C84.5198 60.1021 83.4887 59.9419 82.2432 59.9419C80.7727 59.9419 79.5659 60.1512 78.6589 60.5621C77.7906 60.9549 77.1394 61.4795 76.7233 62.1204C76.5786 62.3426 76.452 62.5752 76.346 62.8129C75.7155 64.2368 74.3303 65.1568 72.8212 65.1568C71.312 65.1568 70.1388 64.4229 69.4488 63.1902C68.7691 61.9757 68.795 60.5466 69.5186 59.3656C69.7356 59.0142 69.976 58.6705 70.237 58.3423C71.5265 56.7297 73.2527 55.4686 75.3666 54.5978C77.4469 53.7398 79.8347 53.3057 82.4576 53.3057C85.0806 53.3057 87.1945 53.6985 89.0965 54.4711C91.0398 55.2619 92.5825 56.3938 93.686 57.8358C94.8127 59.3114 95.3838 61.0453 95.3838 62.9912C95.3838 64.4952 94.9884 65.9114 94.2106 67.2009C93.4586 68.4465 92.2621 69.6973 90.6573 70.9248C89.1016 72.1135 87.0213 73.4056 84.4707 74.7649L82.8995 75.6306C82.8659 75.6487 82.7988 75.6848 82.8272 75.796C82.8556 75.9071 82.9306 75.9071 82.9693 75.9071H92.7712C94.6292 75.9071 96.141 77.4188 96.141 79.2769C96.141 81.1349 94.6292 82.6467 92.7712 82.6467H72.0717V82.6493Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-miterlimit="10"/>
|
||||
<path d="M33.3676 95.9851L2.50293 46.8893L21.0797 35.2107L51.9444 84.3065C52.6064 85.3596 52.998 86.5619 53.0802 87.8047L55.4775 106.262C55.754 108.384 53.4144 109.855 51.6221 108.686L36.0278 98.5249C34.9456 97.9108 34.0297 97.0381 33.3676 95.9851Z" fill="#B999FF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M21.0813 35.211L27.7547 45.8263C29.1375 48.0258 26.0982 52.4217 20.9689 55.6463C15.8396 58.8709 10.5607 59.7043 9.17795 57.5049L2.5045 46.8896C1.12176 44.6901 4.16103 40.2942 9.29035 37.0695C14.4197 33.8449 19.6985 33.0115 21.0813 35.211Z" fill="#E1D7FF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M21.0786 35.2102L18.4248 36.8785L51.7921 89.9551L51.9433 84.306L21.0786 35.2102Z" fill="#2C045D" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M27.7526 45.8261L31.0893 51.1337C32.472 53.3332 29.4328 57.7291 24.3034 60.9538C19.1741 64.1784 13.8952 65.0118 12.5125 62.8123L9.17578 57.5046C10.5585 59.7041 15.8374 58.8707 20.9667 55.6461C26.096 52.4215 29.1353 48.0256 27.7526 45.8261Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M14.2954 45.031C19.4253 41.8061 22.4634 37.4095 21.0813 35.211C19.6992 33.0125 14.4202 33.8446 9.29035 37.0695C4.16051 40.2945 1.12238 44.6911 2.5045 46.8896C3.88662 49.0881 9.1656 48.256 14.2954 45.031Z" fill="#D1C1FF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M51.6229 108.686C53.4153 109.855 55.7549 108.384 55.4784 106.262L53.0811 87.8044C52.9967 86.5629 51.7731 84.0323 51.1111 82.9793L50.0662 87.3389C49.5551 88.9902 48.5434 91.0184 46.833 90.7666L45.6279 90.5883C43.9182 90.333 42.2792 91.3634 41.766 93.0161L41.4043 94.1794C40.8933 95.8307 38.6256 95.8611 36.9139 95.6073L32.5322 94.6592C33.1942 95.7122 34.9422 97.9131 36.0265 98.5259L51.6208 108.687L51.6229 108.686Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M54.3923 97.999L55.4678 106.269C55.7443 108.39 53.4046 109.861 51.6123 108.692L44.6782 104.174C46.3741 104.186 48.3947 103.588 50.3012 102.39C52.2077 101.191 53.6832 99.5615 54.3923 97.999Z" fill="#2C045D" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M136.455 23.6709C134.348 23.6709 132.471 22.3832 131.667 20.4353C131.658 20.4135 131.649 20.3936 131.64 20.3718C130.827 18.4203 131.237 16.1768 132.732 14.6823L135.238 12.1758L128.825 5.76269L126.319 8.26918C124.824 9.76365 122.581 10.1717 120.629 9.3592C120.607 9.35013 120.587 9.34106 120.566 9.33199C118.618 8.52854 117.33 6.65139 117.33 4.54391V1H108.262V4.54572C108.262 6.6532 106.974 8.53035 105.026 9.33381C105.004 9.34288 104.984 9.35194 104.963 9.36101C103.011 10.1735 100.768 9.76365 99.2731 8.271L96.7666 5.76451L90.3535 12.1776L92.86 14.6841C94.3545 16.1786 94.7625 18.4239 93.9518 20.3736C93.9428 20.3954 93.9337 20.4153 93.9246 20.4371C93.1212 22.385 91.244 23.6727 89.1365 23.6727H85.5908V32.741H89.1365C91.244 32.741 93.1212 34.0287 93.9246 35.9766C93.9337 35.9984 93.9428 36.0183 93.9518 36.0401C94.7643 37.9916 94.3545 40.2351 92.86 41.7296L90.3535 44.236L96.7666 50.6492L99.2731 48.1427C100.768 46.6482 103.011 46.2401 104.963 47.0527C104.984 47.0617 105.004 47.0708 105.026 47.0799C106.974 47.8833 108.262 49.7605 108.262 51.868V55.4137H117.33V51.868C117.33 49.7605 118.618 47.8833 120.566 47.0799C120.587 47.0708 120.607 47.0617 120.629 47.0527C122.581 46.2401 124.824 46.65 126.319 48.1427L128.825 50.6492L135.238 44.236L132.732 41.7296C131.237 40.2351 130.829 37.9898 131.64 36.0401C131.649 36.0183 131.658 35.9984 131.667 35.9766C132.471 34.0287 134.348 32.741 136.455 32.741H140.001V23.6727H136.455V23.6709ZM112.796 37.2734C107.788 37.2734 103.728 33.2126 103.728 28.205C103.728 23.1975 107.788 19.1367 112.796 19.1367C117.803 19.1367 121.864 23.1975 121.864 28.205C121.864 33.2126 117.803 37.2734 112.796 37.2734Z" fill="#F2EDFF" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<g style="mix-blend-mode:multiply">
|
||||
<path d="M121.832 28.2051C121.832 33.2127 117.771 37.2735 112.764 37.2735C110.259 37.2735 107.992 36.2578 106.351 34.6183L93.5264 47.4427L96.7329 50.6493L99.2394 48.1428C100.734 46.6483 102.977 46.2403 104.929 47.0528C104.951 47.0619 104.971 47.0709 104.992 47.08C106.94 47.8834 108.228 49.7606 108.228 51.8681V55.4138H117.296V51.8681C117.296 49.7606 118.584 47.8834 120.532 47.08C120.554 47.0709 120.574 47.0619 120.595 47.0528C122.547 46.2403 124.79 46.6502 126.285 48.1428L128.791 50.6493L135.204 44.2362L132.698 41.7297C131.204 40.2352 130.795 37.9899 131.606 36.0402C131.615 36.0184 131.624 35.9985 131.633 35.9767C132.437 34.0288 134.314 32.7411 136.421 32.7411H139.967V23.6728H136.421C134.314 23.6728 132.437 22.3851 131.633 20.4372C131.624 20.4154 131.615 20.3955 131.606 20.3737C130.794 18.4222 131.204 16.1787 132.698 14.6842L135.204 12.1778L131.998 8.97119L119.173 21.7956C120.815 23.437 121.829 25.7041 121.829 28.2088L121.832 28.2051Z" fill="#B999FF"/>
|
||||
</g>
|
||||
<path d="M112.798 14.6027C105.286 14.6027 99.1953 20.693 99.1953 28.2052C99.1953 35.7174 105.286 41.8077 112.798 41.8077C120.31 41.8077 126.4 35.7174 126.4 28.2052C126.4 20.693 120.31 14.6027 112.798 14.6027ZM112.798 37.2735C107.79 37.2735 103.729 33.2127 103.729 28.2052C103.729 23.1976 107.79 19.1368 112.798 19.1368C117.805 19.1368 121.866 23.1976 121.866 28.2052C121.866 33.2127 117.805 37.2735 112.798 37.2735Z" fill="#F2EDFF"/>
|
||||
<path d="M112.796 37.2735C117.804 37.2735 121.864 33.2135 121.864 28.2052C121.864 23.1969 117.804 19.1368 112.796 19.1368C107.788 19.1368 103.728 23.1969 103.728 28.2052C103.728 33.2135 107.788 37.2735 112.796 37.2735Z" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M112.798 14.6027C120.31 14.6027 126.4 20.693 126.4 28.2052C126.4 35.7174 120.31 41.8077 112.798 41.8077C105.286 41.8077 99.1953 35.7174 99.1953 28.2052" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M121.893 18.0848C124.105 20.5043 125.458 23.7253 125.458 27.2638C125.458 34.776 119.368 40.8663 111.856 40.8663C108.317 40.8663 105.096 39.5151 102.677 37.3006C105.163 40.0193 108.74 41.7242 112.715 41.7242C120.228 41.7242 126.318 35.6339 126.318 28.1217C126.318 24.1461 124.613 20.5714 121.894 18.083L121.893 18.0848Z" fill="#2C045D" stroke="#2C045D" stroke-width="1.62161" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 250 KiB After Width: | Height: | Size: 250 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
|
@ -1,6 +1,15 @@
|
|||
jQuery( function ( $ ) {
|
||||
let observer = null;
|
||||
|
||||
if ( arePointersEnabled() ) {
|
||||
setTimeout( showSubscriptionPointers, 800 ); // give TinyMCE a chance to finish loading
|
||||
observer = new MutationObserver( showSubscriptionPointers );
|
||||
|
||||
observer.observe( document.getElementById( 'poststuff' ), {
|
||||
attributes: true,
|
||||
childList: true,
|
||||
characterData: false,
|
||||
subtree:true,
|
||||
} );
|
||||
}
|
||||
|
||||
$( 'select#product-type' ).on( 'change', function () {
|
||||
|
|
@ -62,5 +71,9 @@ jQuery( function ( $ ) {
|
|||
pointer: 'wcs_pointer',
|
||||
action: 'dismiss-wp-pointer',
|
||||
} );
|
||||
|
||||
if ( observer ) {
|
||||
observer.disconnect();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
|
@ -40,21 +40,14 @@ jQuery( function ( $ ) {
|
|||
'hide_if_variable-subscription'
|
||||
);
|
||||
|
||||
/**
|
||||
* WC core will hide and show product specific fields in show_and_hide_panels(), however that function only runs on specific events, but not
|
||||
* when variations are added or loaded. To make sure our subscription-related fields aren't shown by default when a variation is added, we set
|
||||
* subscription pricing elements "base" cases here.
|
||||
*
|
||||
* Note: show() being called on the 'hide_if_' fields and vice versa is intentional. All fields are set in their inverse state first, and
|
||||
* then shown/hidden by product type afterwards.
|
||||
*/
|
||||
$( '.hide_if_variable-subscription' ).show();
|
||||
$( '.show_if_variable-subscription' ).hide();
|
||||
var product_type = $( 'select#product-type' ).val();
|
||||
|
||||
if ( $( 'select#product-type' ).val() == 'variable-subscription' ) {
|
||||
if ( 'variable-subscription' === product_type ) {
|
||||
// Hide and show subscription fields when variable subscription is selected
|
||||
$( 'input#_downloadable' ).prop( 'checked', false );
|
||||
$( 'input#_virtual' ).prop( 'checked', false );
|
||||
|
||||
// Variable subscriptions inherit fields from variable products.
|
||||
$( '.show_if_variable' ).show();
|
||||
$( '.hide_if_variable' ).hide();
|
||||
$( '.show_if_variable-subscription' ).show();
|
||||
|
|
@ -67,14 +60,7 @@ jQuery( function ( $ ) {
|
|||
.addClass( 'form-row-full' )
|
||||
.removeClass( 'form-row-last' );
|
||||
} else {
|
||||
if ( 'variable' === $( 'select#product-type' ).val() ) {
|
||||
$( '.show_if_variable-subscription' ).hide();
|
||||
$( '.show_if_variable' ).show();
|
||||
$( '.hide_if_variable' ).hide();
|
||||
$.showOrHideStockFields();
|
||||
}
|
||||
|
||||
if ( 'subscription' === $( 'select#product-type' ).val() ) {
|
||||
if ( 'subscription' === product_type ) {
|
||||
$( '.show_if_subscription' ).show();
|
||||
$( '.hide_if_subscription' ).hide();
|
||||
}
|
||||
|
|
@ -410,7 +396,7 @@ jQuery( function ( $ ) {
|
|||
// Add the subscription price fields above the standard price fields
|
||||
$( this ).insertBefore( $regularPriceRow );
|
||||
|
||||
$trialSignUpRow.insertBefore( $( this ) );
|
||||
$trialSignUpRow.insertAfter( $( this ) );
|
||||
|
||||
// Replace the regular price field with the trial period field
|
||||
$regularPriceRow
|
||||
|
|
@ -420,6 +406,27 @@ jQuery( function ( $ ) {
|
|||
$( this ).addClass( 'wcs_moved' );
|
||||
} );
|
||||
},
|
||||
moveSubscriptionGiftingFields: function () {
|
||||
$( '#variable_product_options .variable_subscription_gifting' )
|
||||
.not( '.wcs_gifting_moved' )
|
||||
.each( function () {
|
||||
var $trialSignUpRow = $( this ).siblings(
|
||||
'.variable_subscription_trial_sign_up'
|
||||
),
|
||||
$subscriptionPricingRow = $( this ).siblings(
|
||||
'.variable_subscription_pricing'
|
||||
);
|
||||
|
||||
// Position gifting field after trial sign up row if it exists, otherwise after subscription pricing
|
||||
if ( $trialSignUpRow.length > 0 ) {
|
||||
$( this ).insertAfter( $trialSignUpRow );
|
||||
} else if ( $subscriptionPricingRow.length > 0 ) {
|
||||
$( this ).insertAfter( $subscriptionPricingRow );
|
||||
}
|
||||
|
||||
$( this ).addClass( 'wcs_gifting_moved' );
|
||||
} );
|
||||
},
|
||||
getVariationBulkEditValue: function ( variation_action ) {
|
||||
var value;
|
||||
|
||||
|
|
@ -632,6 +639,53 @@ jQuery( function ( $ ) {
|
|||
},
|
||||
} );
|
||||
|
||||
/**
|
||||
* Relocates the linked downloadable product fields in the context of a variable subscription product, and
|
||||
* selectively shows/hides it, depending on whether the variation is downloadable or not.
|
||||
*/
|
||||
function initLinkedDownloadableProductFieldsForVariationProduct() {
|
||||
$( '#variable_product_options .variable_subscription_linked_downloadable_products' )
|
||||
.not( '.wcs_moved' )
|
||||
.each( function () {
|
||||
const $this = $( this );
|
||||
const $variablePricing = $( this ).siblings( '.variable_pricing' );
|
||||
|
||||
const $downloadableFiles = $( this ).siblings( '.form-row.downloadable_files' ).parent( 'div' );
|
||||
|
||||
$this.insertAfter( $downloadableFiles );
|
||||
$this.addClass( 'wcs_gifting_moved' );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the linked downloadable product fields to the correct location (which is underneath the downloadable files
|
||||
* section).
|
||||
*/
|
||||
function relocateLinkedDownloadableProductFields() {
|
||||
const $linkedDownloadableProducts = $( '.subscription_linked_downloadable_products_section' );
|
||||
const $productTypeSelector = $('select#product-type');
|
||||
|
||||
const showHide = () => {
|
||||
$productTypeSelector.val() === WCSubscriptions.productType
|
||||
? $linkedDownloadableProducts.show()
|
||||
: $linkedDownloadableProducts.hide();
|
||||
};
|
||||
|
||||
$linkedDownloadableProducts
|
||||
.not( '.wcs_moved' )
|
||||
.each( function () {
|
||||
const $downloadableFilesSection = $( '.form-field.downloadable_files' ).parent( 'div' );
|
||||
|
||||
if ( $downloadableFilesSection.length === 1 ) {
|
||||
$( this ).insertAfter( $downloadableFilesSection );
|
||||
$( this ).addClass( 'wcs_moved' );
|
||||
}
|
||||
} );
|
||||
|
||||
showHide();
|
||||
$productTypeSelector.on( 'change', showHide );
|
||||
}
|
||||
|
||||
$( '.options_group.pricing ._sale_price_field .description' ).prepend(
|
||||
'<span id="sale-price-period" style="display: none;"></span>'
|
||||
);
|
||||
|
|
@ -646,33 +700,46 @@ jQuery( function ( $ ) {
|
|||
$( '.options_group.subscription_pricing' )
|
||||
);
|
||||
|
||||
// Move the subscription variation pricing section to a better location in the DOM on load
|
||||
// Move the subscription variation pricing, gifting and linked downloadable product sections to a better location in
|
||||
// the DOM on load. We do this because these sections are initially loaded at the end of the variable product
|
||||
// options section, which is not the best location for them, so we move to before the "Sale price" section.
|
||||
if (
|
||||
$( '#variable_product_options .variable_subscription_pricing' ).length >
|
||||
0
|
||||
) {
|
||||
$.moveSubscriptionVariationFields();
|
||||
}
|
||||
if (
|
||||
$( '#variable_product_options .variable_subscription_gifting' ).length >
|
||||
0
|
||||
) {
|
||||
$.moveSubscriptionGiftingFields();
|
||||
}
|
||||
|
||||
// When a variation is added
|
||||
$( '#woocommerce-product-data' ).on(
|
||||
'woocommerce_variations_added woocommerce_variations_loaded',
|
||||
function () {
|
||||
$.moveSubscriptionVariationFields();
|
||||
$.moveSubscriptionGiftingFields();
|
||||
$.showHideVariableSubscriptionMeta();
|
||||
$.showHideSyncOptions();
|
||||
$.setSubscriptionLengths();
|
||||
initLinkedDownloadableProductFieldsForVariationProduct();
|
||||
}
|
||||
);
|
||||
|
||||
if ( $( '.options_group.pricing' ).length > 0 ) {
|
||||
$.setSalePeriod();
|
||||
$.showHideSubscriptionMeta();
|
||||
$.enableSubscriptionProductFields();
|
||||
$.showHideVariableSubscriptionMeta();
|
||||
$.setSubscriptionLengths();
|
||||
$.setTrialPeriods();
|
||||
$.showHideSyncOptions();
|
||||
$.disableEnableOneTimeShipping();
|
||||
$.showHideSubscriptionsPanels();
|
||||
relocateLinkedDownloadableProductFields();
|
||||
}
|
||||
|
||||
// Update subscription ranges when subscription period or interval is changed
|
||||
|
|
@ -721,16 +788,21 @@ jQuery( function ( $ ) {
|
|||
);
|
||||
|
||||
if ( 0 < $( this ).val() ) {
|
||||
$syncDayOfMonthInput
|
||||
.val( 1 )
|
||||
.attr( {
|
||||
step: '1',
|
||||
min: '1',
|
||||
max: $.daysInMonth( $( this ).val() ),
|
||||
} )
|
||||
.prop( 'disabled', false );
|
||||
// Clear existing options.
|
||||
$syncDayOfMonthInput.empty();
|
||||
|
||||
// Add options for each day in the month.
|
||||
for ( var day = 1; day <= $.daysInMonth( $( this ).val() ); day++ ) {
|
||||
$syncDayOfMonthInput.append( $( '<option>', {
|
||||
value: day,
|
||||
text: day
|
||||
} ) );
|
||||
}
|
||||
|
||||
$syncDayOfMonthInput.prop( 'disabled', false );
|
||||
} else {
|
||||
$syncDayOfMonthInput.val( 0 ).trigger( 'change' );
|
||||
$syncDayOfMonthInput.prop( 'disabled', true );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -940,6 +1012,9 @@ jQuery( function ( $ ) {
|
|||
),
|
||||
$syncRenewals = $(
|
||||
document.getElementById( 'woocommerce_subscriptions_sync_payments' )
|
||||
),
|
||||
$customerNotifications = $(
|
||||
document.getElementById( 'woocommerce_subscriptions_customer_notifications_enabled' )
|
||||
);
|
||||
|
||||
// We're on the Subscriptions settings page
|
||||
|
|
@ -962,6 +1037,9 @@ jQuery( function ( $ ) {
|
|||
).parents( 'tr' ),
|
||||
$suspensionExtensionRow = $(
|
||||
'#woocommerce_subscriptions_recoup_suspension'
|
||||
).parents( 'tr' ),
|
||||
$customerNotificationOffsetRow = $(
|
||||
'#woocommerce_subscriptions_customer_notifications_offset'
|
||||
).parents( 'tr' );
|
||||
|
||||
// No animation for initial hiding when switching is disabled.
|
||||
|
|
@ -1017,6 +1095,54 @@ jQuery( function ( $ ) {
|
|||
$daysNoFeeRow.fadeOut();
|
||||
}
|
||||
} );
|
||||
|
||||
// No animation when initially hiding customer notification offset row.
|
||||
if ( ! $customerNotifications.is( ':checked' ) ) {
|
||||
$customerNotificationOffsetRow.hide();
|
||||
}
|
||||
// Watch the enable/disable customer notifications checkbox for changes.
|
||||
$customerNotifications.on( 'change', function () {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$customerNotificationOffsetRow.fadeIn();
|
||||
} else {
|
||||
$customerNotificationOffsetRow.fadeOut();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
var $giftingEnableCheckbox = $(
|
||||
document.getElementById(
|
||||
'woocommerce_subscriptions_gifting_enable_gifting'
|
||||
)
|
||||
),
|
||||
$giftingRadios = $( '.wc-settings-row-gifting-radios' ),
|
||||
$giftingCheckboxText = $( '.wc-settings-row-gifting-checkbox-text' ),
|
||||
$giftingDownloadableProducts = $(
|
||||
'.wc-settings-row-gifting-downloadable-products'
|
||||
);
|
||||
|
||||
if ( $giftingEnableCheckbox.length > 0 ) {
|
||||
function toggleGiftingCheckbox( checked ) {
|
||||
if ( checked ) {
|
||||
$giftingRadios.show();
|
||||
$giftingCheckboxText.show();
|
||||
$giftingDownloadableProducts.show();
|
||||
$giftingEnableCheckbox.closest( 'tr' ).addClass( 'checked' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$giftingRadios.hide();
|
||||
$giftingCheckboxText.hide();
|
||||
$giftingDownloadableProducts.hide();
|
||||
$giftingEnableCheckbox.closest( 'tr' ).removeClass( 'checked' );
|
||||
}
|
||||
|
||||
$giftingEnableCheckbox.on( 'change', function () {
|
||||
toggleGiftingCheckbox( this.checked );
|
||||
} );
|
||||
|
||||
toggleGiftingCheckbox( $giftingEnableCheckbox.is( ':checked' ) );
|
||||
}
|
||||
|
||||
// Don't display the variation notice for variable subscription products
|
||||
|
|
@ -1427,4 +1553,9 @@ jQuery( function ( $ ) {
|
|||
);
|
||||
}
|
||||
} );
|
||||
|
||||
// On the subscriptions list table empty state screen, add the is-busy class to the button when clicked.
|
||||
$( '.woo_subscriptions_empty_state__button_container a' ).on( 'click', function ( e ) {
|
||||
$( this ).addClass( 'is-busy' );
|
||||
} );
|
||||
} );
|
||||
|
|
@ -46,7 +46,7 @@ var jstz = (function () {
|
|||
'Australia/Sydney': ['Australia/Lord_Howe'],
|
||||
'Asia/Tokyo': ['Asia/Yakutsk'],
|
||||
'Asia/Dhaka': ['Asia/Omsk'],
|
||||
// In the real world Yerevan is not ambigous for Baku... but Windows.
|
||||
// In the real world Yerevan is not ambiguous for Baku... but Windows.
|
||||
'Asia/Baku': ['Asia/Yerevan'],
|
||||
'Australia/Brisbane': ['Asia/Vladivostok'],
|
||||
'Pacific/Noumea': ['Asia/Vladivostok'],
|
||||
|
|
@ -332,7 +332,7 @@ var jstz = (function () {
|
|||
* Builds up the current timezones DST rules for the years defined
|
||||
* in the jstz.olson.dst_rules.years array.
|
||||
*
|
||||
* If there are no DST occurences for those years, immediately returns
|
||||
* If there are no DST occurrences for those years, immediately returns
|
||||
* the preliminary timezone. Otherwise proceeds and tries to solve
|
||||
* ambiguities.
|
||||
*
|
||||
|
|
@ -242,22 +242,66 @@ jQuery( function ( $ ) {
|
|||
// Update the UTC timestamp sent to the server
|
||||
date_pieces = $date_input.val().split( '-' );
|
||||
|
||||
var newTimeStampValue = moment( {
|
||||
years: date_pieces[ 0 ],
|
||||
months: date_pieces[ 1 ] - 1,
|
||||
date: date_pieces[ 2 ],
|
||||
hours: $hour_input.val(),
|
||||
minutes: $minute_input.val(),
|
||||
seconds: one_hour_from_now.format( 'ss' ),
|
||||
} )
|
||||
.utc()
|
||||
.unix();
|
||||
|
||||
|
||||
// Moment will return NaN if the date is invalid, that's why we need to check for NaN only.
|
||||
if ( isNaN( newTimeStampValue ) ) {
|
||||
wcsShowDateFieldError( date_type );
|
||||
} else {
|
||||
wcsHideDateFieldError( date_type );
|
||||
}
|
||||
|
||||
// Intentionally do not prevent timestamp updates if the date is invalid.
|
||||
// This way it's easier to catch invalid fields during submit event if attempted without editing invalid values.
|
||||
$( '#' + date_type + '_timestamp_utc' ).val(
|
||||
moment( {
|
||||
years: date_pieces[ 0 ],
|
||||
months: date_pieces[ 1 ] - 1,
|
||||
date: date_pieces[ 2 ],
|
||||
hours: $hour_input.val(),
|
||||
minutes: $minute_input.val(),
|
||||
seconds: one_hour_from_now.format( 'ss' ),
|
||||
} )
|
||||
.utc()
|
||||
.unix()
|
||||
newTimeStampValue
|
||||
);
|
||||
|
||||
$( 'body' ).trigger( 'wcs-updated-date', date_type );
|
||||
} );
|
||||
|
||||
function wcsShowDateFieldError( date_type ) {
|
||||
var $fieldContainer = $( '#subscription-' + date_type + '-date' );
|
||||
$fieldContainer.addClass( 'has-error' );
|
||||
var $messageContainer = $fieldContainer.find( '.message' );
|
||||
var $messageContent = $messageContainer.find( '.message-content' );
|
||||
|
||||
// Clear and set content before showing to ensure screen readers announce the new message
|
||||
$messageContent.text('');
|
||||
$messageContainer.show();
|
||||
|
||||
// Use setTimeout to ensure DOM update occurs before adding new text
|
||||
setTimeout(function() {
|
||||
// If the focus switched to the next field voice over skips announcing the error message.
|
||||
// This is a workaround to ensure the error message is announced.
|
||||
$fieldContainer
|
||||
.find( `input#${date_type}` )
|
||||
.trigger( 'focus' )
|
||||
.trigger( 'blur' );
|
||||
$messageContent.text( wcs_admin_meta_boxes.i18n_invalid_date_notice );
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function wcsHideDateFieldError( date_type ) {
|
||||
var $fieldContainer = $( '#subscription-' + date_type + '-date' );
|
||||
$fieldContainer.removeClass( 'has-error' );
|
||||
var $messageContainer = $fieldContainer.find( '.message' );
|
||||
var $messageContent = $messageContainer.find( '.message-content' );
|
||||
|
||||
$messageContainer.hide();
|
||||
$messageContent.text('');
|
||||
}
|
||||
|
||||
function zeroise( val ) {
|
||||
return val > 9 ? val : '0' + val;
|
||||
}
|
||||
|
|
@ -327,6 +371,26 @@ jQuery( function ( $ ) {
|
|||
return false;
|
||||
}
|
||||
|
||||
$( 'body.post-type-shop_subscription #post, body.woocommerce_page_wc-orders--shop_subscription #order' ).on( 'submit', function ( evt ) {
|
||||
var invalid_dates = [];
|
||||
$( '.woocommerce-subscriptions.date-picker' ).each( function () {
|
||||
var $date_input = $( this );
|
||||
var date_type = $date_input.attr( 'id' );
|
||||
var timestamp = $( '#' + date_type + '_timestamp_utc' ).val();
|
||||
// At this point, timestamp is a string, not a number.
|
||||
// We check for NaN only because everything else should be a valid timestamp set during the change event.
|
||||
if ( timestamp === 'NaN' ) {
|
||||
invalid_dates.push( date_type );
|
||||
}
|
||||
} );
|
||||
|
||||
if ( invalid_dates.length > 0 ) {
|
||||
// Focus the first invalid date to make it noticeable.
|
||||
$( '#subscription-' + invalid_dates[0] + '-date' ).find( '.wcs-date-input input' ).first().focus();
|
||||
return false;
|
||||
}
|
||||
} )
|
||||
|
||||
$( 'body.post-type-shop_subscription #post, body.woocommerce_page_wc-orders--shop_subscription #order' ).on( 'submit', function () {
|
||||
if (
|
||||
'wcs_process_renewal' ==
|
||||
|
|
@ -351,4 +415,17 @@ jQuery( function ( $ ) {
|
|||
);
|
||||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* When the auto-renewal is toggled on or off, show or hide the chosen payment methods meta fields.
|
||||
*/
|
||||
$( '#wc-subscription-auto-renew' ).on( 'change', function() {
|
||||
var $payment_method_meta_elements = $( '#wcs_' + $( '#_payment_method' ).val() + '_fields' );
|
||||
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$payment_method_meta_elements.fadeIn();
|
||||
} else {
|
||||
$payment_method_meta_elements.fadeOut();
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
jQuery( function ( $ ) {
|
||||
/**
|
||||
* Displays an appropriate error message when the delete token button is clicked for a token used by subscriptions.
|
||||
*/
|
||||
$( '.wcs_deletion_error' ).on( 'click', function ( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var notice_content_container = $( '#wcs_delete_token_warning' ).find(
|
||||
'li'
|
||||
);
|
||||
|
||||
// For block based WC notices we need to find the notice content container.
|
||||
if (
|
||||
$( '#wcs_delete_token_warning' ).find(
|
||||
'.wc-block-components-notice-banner'
|
||||
).length > 0
|
||||
) {
|
||||
notice_content_container = $( '#wcs_delete_token_warning' ).find(
|
||||
'.wc-block-components-notice-banner__content'
|
||||
);
|
||||
}
|
||||
|
||||
// Use the href to determine which notice needs to be displayed.
|
||||
if ( '#choose_default' === $( this ).attr( 'href' ) ) {
|
||||
notice_content_container.html(
|
||||
wcs_payment_methods.choose_default_error
|
||||
);
|
||||
} else {
|
||||
notice_content_container.html(
|
||||
wcs_payment_methods.add_method_error
|
||||
);
|
||||
}
|
||||
|
||||
// Display the notice.
|
||||
$( '#wcs_delete_token_warning' ).slideDown();
|
||||
} );
|
||||
} );
|
||||
|
|
@ -11,8 +11,11 @@ jQuery( function ( $ ) {
|
|||
var $early_renewal_modal_content = $( '.wcs-modal > .content-wrapper' );
|
||||
|
||||
function getTxtColor() {
|
||||
if ( ! txtColor && $icon && $icon.length ) {
|
||||
txtColor = getComputedStyle( $icon[ 0 ] ).color;
|
||||
if ( ! txtColor ) {
|
||||
// Create a temporary link to get the theme's accent color.
|
||||
var $tempLink = $( '<a href="#" style="display:none;"></a>' ).appendTo( $toggleContainer );
|
||||
txtColor = getComputedStyle( $tempLink[ 0 ] ).color;
|
||||
$tempLink.remove();
|
||||
}
|
||||
|
||||
return txtColor;
|
||||
|
|
@ -38,9 +41,6 @@ jQuery( function ( $ ) {
|
|||
function onToggle( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
// Remove focus from the toggle element.
|
||||
$toggle.trigger( 'blur' );
|
||||
|
||||
// Ignore the request if the toggle is disabled.
|
||||
if ( $toggle.hasClass( 'subscription-auto-renew-toggle--disabled' ) ) {
|
||||
return;
|
||||
|
|
@ -105,17 +105,20 @@ jQuery( function ( $ ) {
|
|||
$icon.removeClass( 'fa-toggle-off' ).addClass( 'fa-toggle-on' );
|
||||
$toggle
|
||||
.removeClass( 'subscription-auto-renew-toggle--off' )
|
||||
.addClass( 'subscription-auto-renew-toggle--on' );
|
||||
.addClass( 'subscription-auto-renew-toggle--on' )
|
||||
.attr( 'aria-checked', 'true' );
|
||||
}
|
||||
|
||||
function displayToggleOff() {
|
||||
$icon.removeClass( 'fa-toggle-on' ).addClass( 'fa-toggle-off' );
|
||||
$toggle
|
||||
.removeClass( 'subscription-auto-renew-toggle--on' )
|
||||
.addClass( 'subscription-auto-renew-toggle--off' );
|
||||
.addClass( 'subscription-auto-renew-toggle--off' )
|
||||
.attr( 'aria-checked', 'false' );
|
||||
}
|
||||
|
||||
function blockToggle() {
|
||||
$toggle.addClass( 'subscription-auto-renew-toggle--disabled' );
|
||||
$toggleContainer.block( {
|
||||
message: null,
|
||||
overlayCSS: { opacity: 0.0 },
|
||||
|
|
@ -123,6 +126,7 @@ jQuery( function ( $ ) {
|
|||
}
|
||||
|
||||
function unblockToggle() {
|
||||
$toggle.removeClass( 'subscription-auto-renew-toggle--disabled' );
|
||||
$toggleContainer.unblock();
|
||||
}
|
||||
|
||||
|
|
@ -149,10 +153,25 @@ jQuery( function ( $ ) {
|
|||
return $paymentMethod.data( 'is_manual' ) === 'no';
|
||||
}
|
||||
|
||||
function blockActionsOnTrigger() {
|
||||
$( '.subscription_details' ).block( {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6,
|
||||
},
|
||||
} );
|
||||
}
|
||||
|
||||
$toggle.on( 'click', onToggle );
|
||||
maybeApplyColor();
|
||||
displayToggle();
|
||||
|
||||
$early_renewal_modal_submit.on( 'click', blockEarlyRenewalModal );
|
||||
$( document ).on( 'wcs_show_modal', shouldShowEarlyRenewalModal );
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.wcs_block_ui_on_click',
|
||||
blockActionsOnTrigger
|
||||
);
|
||||
} );
|
||||
|
|
@ -26,10 +26,10 @@ jQuery( function ( $ ) {
|
|||
$( document ).on(
|
||||
'change',
|
||||
'select.shipping_method, :input[name^=shipping_method]',
|
||||
function( event ) {
|
||||
function ( event ) {
|
||||
var shipping_method_option = $( event.target );
|
||||
var shipping_method_id = shipping_method_option.val();
|
||||
var package_index = shipping_method_option.data( 'index' );
|
||||
var shipping_method_id = shipping_method_option.val();
|
||||
var package_index = shipping_method_option.data( 'index' );
|
||||
|
||||
// We're only interested in the initial cart shipping method options which have int package indexes.
|
||||
if ( ! Number.isInteger( package_index ) ) {
|
||||
|
|
@ -37,9 +37,17 @@ jQuery( function ( $ ) {
|
|||
}
|
||||
|
||||
// Find all recurring cart info elements with the same package index as the changed shipping method.
|
||||
$( '.recurring-cart-shipping-mapping-info[data-index=' + package_index + ']' ).each( function() {
|
||||
$(
|
||||
'.recurring-cart-shipping-mapping-info[data-index=' +
|
||||
package_index +
|
||||
']'
|
||||
).each( function () {
|
||||
// Update the corresponding subscription's hidden chosen shipping method.
|
||||
$( 'input[name="shipping_method[' + $( this ).data( 'recurring_index' ) + ']"]' ).val( shipping_method_id );
|
||||
$(
|
||||
'input[name="shipping_method[' +
|
||||
$( this ).data( 'recurring_index' ) +
|
||||
']"]'
|
||||
).val( shipping_method_id );
|
||||
} );
|
||||
}
|
||||
);
|
||||
|
|
@ -0,0 +1,358 @@
|
|||
jQuery( document ).ready( function ( $ ) {
|
||||
setShippingAddressNoticeVisibility( true );
|
||||
|
||||
$( document ).on(
|
||||
'change',
|
||||
'.woocommerce_subscription_gifting_checkbox[type="checkbox"]',
|
||||
function ( e, eventContext ) {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( this )
|
||||
.closest( '.wcsg_add_recipient_fields_container' )
|
||||
.find( '.wcsg_add_recipient_fields' )
|
||||
.slideDown( 250, function () {
|
||||
if (
|
||||
typeof eventContext === 'undefined' ||
|
||||
eventContext !== 'pageload'
|
||||
) {
|
||||
$( this )
|
||||
.find( '.recipient_email' )
|
||||
.trigger( 'focus' );
|
||||
}
|
||||
} )
|
||||
.removeClass( 'hidden' );
|
||||
|
||||
const shipToDifferentAddressCheckbox = $( document ).find(
|
||||
'#ship-to-different-address-checkbox'
|
||||
);
|
||||
if ( ! shipToDifferentAddressCheckbox.is( ':checked' ) ) {
|
||||
shipToDifferentAddressCheckbox.click();
|
||||
}
|
||||
setShippingAddressNoticeVisibility( false );
|
||||
} else {
|
||||
$( this )
|
||||
.closest( '.wcsg_add_recipient_fields_container' )
|
||||
.find( '.wcsg_add_recipient_fields' )
|
||||
.slideUp( 250 )
|
||||
.addClass( 'hidden' );
|
||||
|
||||
const recipientEmailElement = $( this )
|
||||
.closest( '.wcsg_add_recipient_fields_container' )
|
||||
.find( '.recipient_email' );
|
||||
recipientEmailElement.val( '' );
|
||||
hideValidationErrorForEmailField( recipientEmailElement );
|
||||
setShippingAddressNoticeVisibility( true );
|
||||
|
||||
if ( $( 'form.checkout' ).length !== 0 ) {
|
||||
// Trigger the event to update the checkout after the recipient field has been cleared.
|
||||
updateCheckout();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Handles showing and hiding the gifting checkbox on variable subscription products.
|
||||
*/
|
||||
function hideGiftingCheckbox() {
|
||||
$( '.woocommerce_subscription_gifting_checkbox[type="checkbox"]' )
|
||||
.prop( 'checked', false )
|
||||
.trigger( 'change' );
|
||||
$( '.wcsg_add_recipient_fields_container' ).hide();
|
||||
}
|
||||
|
||||
// When a variation is found, show the gifting checkbox if it's enabled for the variation, otherwise hide it.
|
||||
$( document ).on( 'found_variation', function ( event, variationData ) {
|
||||
if ( variationData.gifting ) {
|
||||
$( '.wcsg_add_recipient_fields_container' ).show();
|
||||
return;
|
||||
}
|
||||
|
||||
hideGiftingCheckbox();
|
||||
} );
|
||||
|
||||
// When the data is reset, hide the gifting checkbox.
|
||||
$( document ).on( 'reset_data', hideGiftingCheckbox );
|
||||
|
||||
/**
|
||||
* Handles recipient e-mail inputs on the cart page.
|
||||
*/
|
||||
const cart = {
|
||||
init: function () {
|
||||
$( document ).on(
|
||||
'submit',
|
||||
'div.woocommerce > form',
|
||||
this.set_update_cart_as_clicked
|
||||
);
|
||||
|
||||
// We need to make sure our callback is hooked before WC's.
|
||||
const handlers = $._data( document, 'events' );
|
||||
if ( typeof handlers.submit !== 'undefined' ) {
|
||||
handlers.submit.unshift( handlers.submit.pop() );
|
||||
}
|
||||
},
|
||||
|
||||
set_update_cart_as_clicked: function ( evt ) {
|
||||
const $form = $( evt.target );
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
const $submit = $( document.activeElement );
|
||||
|
||||
// If we're not on the cart page exit.
|
||||
if ( $form.find( 'table.shop_table.cart' ).length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the recipient email element is the active element, the clicked button is the update cart button.
|
||||
if ( $submit.is( 'input.recipient_email' ) ) {
|
||||
$( ':input[type="submit"][name="update_cart"]' ).attr(
|
||||
'clicked',
|
||||
'true'
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
cart.init();
|
||||
|
||||
/**
|
||||
* Email validation function
|
||||
*
|
||||
* @param {string} email - The email to validate
|
||||
* @return {boolean} - Whether the email is valid
|
||||
*/
|
||||
function isValidEmail( email ) {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return emailRegex.test( email );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate all recipient emails and return overall validation status
|
||||
*
|
||||
* @param {boolean} showErrors - Whether to show validation errors
|
||||
* @return {boolean} - Whether all emails are valid
|
||||
*/
|
||||
function validateAllRecipientEmails( showErrors = true ) {
|
||||
const $allEmailFields = $( '.recipient_email' );
|
||||
let allValid = true;
|
||||
|
||||
// Check each email field
|
||||
$allEmailFields.each( function () {
|
||||
const $emailField = $( this );
|
||||
const $giftingCheckbox = $( this )
|
||||
.closest( '.wcsg_add_recipient_fields_container' )
|
||||
.find( '.woocommerce_subscription_gifting_checkbox' );
|
||||
const email = $emailField.val().trim();
|
||||
|
||||
if ( ! $giftingCheckbox.is( ':checked' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if email format is valid
|
||||
if ( ! isValidEmail( email ) ) {
|
||||
if ( showErrors ) {
|
||||
showValidationErrorForEmailField( $emailField );
|
||||
}
|
||||
allValid = false;
|
||||
}
|
||||
} );
|
||||
|
||||
// Control update cart button state
|
||||
const $updateCartButton = $(
|
||||
'.woocommerce-cart-form :input[type="submit"][name="update_cart"]'
|
||||
);
|
||||
|
||||
if ( $updateCartButton.length && ! allValid ) {
|
||||
$updateCartButton.prop( 'disabled', true );
|
||||
}
|
||||
|
||||
return allValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate recipient email and show error if invalid
|
||||
*
|
||||
* @param {jQuery} $emailField - The email input field jQuery object
|
||||
* @return {boolean} - Whether the email is valid
|
||||
*/
|
||||
function validateRecipientEmail( $emailField ) {
|
||||
const email = $emailField.val().trim();
|
||||
|
||||
hideValidationErrorForEmailField( $emailField );
|
||||
|
||||
// Check if email format is valid
|
||||
if ( ! isValidEmail( email ) ) {
|
||||
showValidationErrorForEmailField( $emailField );
|
||||
|
||||
// Only validate all emails and update button state on cart and checkout shortcode pages.
|
||||
if ( isShortcodeCartOrCheckoutPage() ) {
|
||||
validateAllRecipientEmails();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only validate all emails and update button state on cart and checkout shortcode pages.
|
||||
if ( isShortcodeCartOrCheckoutPage() ) {
|
||||
validateAllRecipientEmails();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle add to cart button click with email validation
|
||||
*/
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.single_add_to_cart_button, .add_to_cart_button',
|
||||
function ( e ) {
|
||||
// Check if we're on a product page with gifting enabled
|
||||
const $giftingContainer = $(
|
||||
'.wcsg_add_recipient_fields_container'
|
||||
);
|
||||
if ( $giftingContainer.length === 0 ) {
|
||||
return; // No gifting on this page
|
||||
}
|
||||
|
||||
// Check if gifting checkbox is checked
|
||||
const $giftingCheckbox = $giftingContainer.find(
|
||||
'.woocommerce_subscription_gifting_checkbox'
|
||||
);
|
||||
if ( ! $giftingCheckbox.is( ':checked' ) ) {
|
||||
return; // Gifting not enabled for this item
|
||||
}
|
||||
|
||||
// Get the recipient email field
|
||||
const $emailField = $giftingContainer.find( '.recipient_email' );
|
||||
if ( $emailField.length === 0 ) {
|
||||
return; // No email field found
|
||||
}
|
||||
|
||||
// Validate the email
|
||||
if ( ! validateRecipientEmail( $emailField ) ) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Focus on the email field
|
||||
$emailField.focus();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Real-time email validation on input
|
||||
*/
|
||||
$( document ).on( 'blur', '.recipient_email', function () {
|
||||
const $emailField = $( this );
|
||||
validateRecipientEmail( $emailField );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Clear error styling when user starts typing
|
||||
*/
|
||||
$( document ).on( 'input', '.recipient_email', function () {
|
||||
const $emailField = $( this );
|
||||
|
||||
hideValidationErrorForEmailField( $emailField );
|
||||
} );
|
||||
|
||||
/*******************************************
|
||||
* Update checkout on input changed events *
|
||||
*******************************************/
|
||||
let updateTimer;
|
||||
|
||||
$( document ).on( 'change', '.recipient_email', function () {
|
||||
if ( $( 'form.checkout' ).length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( validateAllRecipientEmails() ) {
|
||||
updateCheckout();
|
||||
}
|
||||
} );
|
||||
|
||||
$( document ).on( 'keyup', '.recipient_email', function ( e ) {
|
||||
const code = e.keyCode || e.which || 0;
|
||||
|
||||
if ( $( 'form.checkout' ).length === 0 || code === 9 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const currentRecipient = $( this ).val();
|
||||
const originalRecipient = $( this ).attr( 'data-recipient' );
|
||||
resetCheckoutUpdateTimer();
|
||||
|
||||
// If the recipient has changed since last load, mark the element as needing an update.
|
||||
if ( currentRecipient !== originalRecipient ) {
|
||||
$( this ).addClass( 'wcsg_needs_update' );
|
||||
// Only set timer if all emails are valid
|
||||
if ( validateAllRecipientEmails( false ) ) {
|
||||
updateTimer = setTimeout( updateCheckout, 1500 );
|
||||
}
|
||||
} else {
|
||||
$( this ).removeClass( 'wcsg_needs_update' );
|
||||
}
|
||||
} );
|
||||
|
||||
function updateCheckout() {
|
||||
resetCheckoutUpdateTimer();
|
||||
$( '.recipient_email' ).removeClass( 'wcsg_needs_update' );
|
||||
$( document.body ).trigger( 'update_checkout' );
|
||||
}
|
||||
|
||||
function resetCheckoutUpdateTimer() {
|
||||
clearTimeout( updateTimer );
|
||||
}
|
||||
|
||||
function setShippingAddressNoticeVisibility( hide = true ) {
|
||||
const notice = $( 'form.checkout' )
|
||||
.find( '.woocommerce-shipping-fields' )
|
||||
.find( '.woocommerce-info' );
|
||||
|
||||
if ( ! notice.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( hide ) {
|
||||
notice.css( { display: 'none' } );
|
||||
} else {
|
||||
notice.css( { display: '' } );
|
||||
}
|
||||
}
|
||||
|
||||
function isShortcodeCartOrCheckoutPage() {
|
||||
return (
|
||||
$( 'form.woocommerce-cart-form' ).length > 0 ||
|
||||
$( 'form.woocommerce-checkout' ).length > 0
|
||||
);
|
||||
}
|
||||
|
||||
function showValidationErrorForEmailField( $emailField ) {
|
||||
$emailField.addClass( 'wcsg-email-error' );
|
||||
$emailField
|
||||
.closest( '.wcsg_add_recipient_fields' )
|
||||
.find( '.wc-shortcode-components-validation-error' )
|
||||
.show();
|
||||
}
|
||||
|
||||
function hideValidationErrorForEmailField( $emailField ) {
|
||||
$emailField.removeClass( 'wcsg-email-error' );
|
||||
$emailField
|
||||
.closest( '.wcsg_add_recipient_fields' )
|
||||
.find( '.wc-shortcode-components-validation-error' )
|
||||
.hide();
|
||||
}
|
||||
|
||||
// Triggers
|
||||
$( '.woocommerce_subscription_gifting_checkbox[type="checkbox"]' ).trigger(
|
||||
'change',
|
||||
'pageload'
|
||||
);
|
||||
|
||||
// Validate all recipient emails on page load to set initial button state
|
||||
$( document ).ready( function () {
|
||||
setTimeout( function () {
|
||||
// Only run validation on cart and checkout shortcode pages
|
||||
if ( isShortcodeCartOrCheckoutPage() ) {
|
||||
validateAllRecipientEmails();
|
||||
}
|
||||
}, 1000 );
|
||||
} );
|
||||
} );
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
jQuery( document ).ready( function ( $ ) {
|
||||
// Remove WC's revoke handler to make sure that only our handler is called (to make sure only the correct permissions are revoked not all permissions matching the product/order ID)
|
||||
$( '.order_download_permissions' ).off( 'click', 'button.revoke_access' );
|
||||
|
||||
$( '.order_download_permissions' ).on(
|
||||
'click',
|
||||
'button.revoke_access',
|
||||
function () {
|
||||
if (
|
||||
window.confirm(
|
||||
woocommerce_admin_meta_boxes.i18n_permission_revoke
|
||||
)
|
||||
) {
|
||||
var el = $( this ).parent().parent();
|
||||
var permission_id = $( this )
|
||||
.siblings()
|
||||
.find( '.wcsg_download_permission_id' )
|
||||
.val();
|
||||
var post_id = $( '#post_ID' ).val();
|
||||
|
||||
if ( 0 < permission_id ) {
|
||||
$( el ).block( {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6,
|
||||
},
|
||||
} );
|
||||
|
||||
var data = {
|
||||
action: 'wcsg_revoke_access_to_download',
|
||||
post_id: post_id,
|
||||
download_permission_id: permission_id,
|
||||
nonce: wcs_gifting.revoke_download_permission_nonce,
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
url: wcs_gifting.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function () {
|
||||
// Success
|
||||
$( el ).fadeOut( '300', function () {
|
||||
$( el ).remove();
|
||||
} );
|
||||
},
|
||||
} );
|
||||
} else {
|
||||
$( el ).fadeOut( '300', function () {
|
||||
$( el ).remove();
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
jQuery( function ( $ ) {
|
||||
const modals = $( '.wcs-modal' );
|
||||
const $modals = $( '.wcs-modal' );
|
||||
let $currentModal;
|
||||
let $triggerElement;
|
||||
|
||||
// Resize all open modals on window resize.
|
||||
$( window ).on( 'resize', resizeModals );
|
||||
|
||||
// Initialize modals
|
||||
$( modals ).each( function () {
|
||||
$( $modals ).each( function () {
|
||||
trigger = $( this ).data( 'modal-trigger' );
|
||||
$( trigger ).on( 'click', { modal: this }, show_modal );
|
||||
} );
|
||||
|
|
@ -18,34 +20,35 @@ jQuery( function ( $ ) {
|
|||
* @param {JQuery event} event
|
||||
*/
|
||||
function show_modal( event ) {
|
||||
const modal = $( event.data.modal );
|
||||
$triggerElement = $( event.target );
|
||||
$currentModal = $( event.data.modal );
|
||||
|
||||
if ( ! should_show_modal( modal ) ) {
|
||||
if ( ! should_show_modal( $currentModal ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent the trigger element event being triggered.
|
||||
event.preventDefault();
|
||||
|
||||
const contentWrapper = modal.find( '.content-wrapper' );
|
||||
const close = modal.find( '.close' );
|
||||
const $contentWrapper = $currentModal.find( '.content-wrapper' );
|
||||
const $close = $currentModal.find( '.close' );
|
||||
|
||||
modal.trigger( 'focus' );
|
||||
modal.addClass( 'open' );
|
||||
|
||||
resizeModal( modal );
|
||||
$currentModal.addClass( 'open' );
|
||||
resizeModal( $currentModal );
|
||||
|
||||
$( document.body ).toggleClass( 'wcs-modal-open', true );
|
||||
$currentModal.focus();
|
||||
document.addEventListener( 'focusin', keepFocusInModal );
|
||||
|
||||
// Attach callbacks to handle closing the modal.
|
||||
close.on( 'click', () => close_modal( modal ) );
|
||||
modal.on( 'click', () => close_modal( modal ) );
|
||||
contentWrapper.on( 'click', ( e ) => e.stopPropagation() );
|
||||
$close.on( 'click', () => close_modal( $currentModal ) );
|
||||
$currentModal.on( 'click', () => close_modal( $currentModal ) );
|
||||
$contentWrapper.on( 'click', ( e ) => e.stopPropagation() );
|
||||
|
||||
// Close the modal if the escape key is pressed.
|
||||
modal.on( 'keyup', function ( e ) {
|
||||
$currentModal.on( 'keyup', function ( e ) {
|
||||
if ( 27 === e.keyCode ) {
|
||||
close_modal( modal );
|
||||
close_modal( $currentModal );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
|
@ -53,14 +56,17 @@ jQuery( function ( $ ) {
|
|||
/**
|
||||
* Closes a modal and resets any forced height styles.
|
||||
*
|
||||
* @param {JQuery Object} modal
|
||||
* @param {JQuery Object} $modal
|
||||
*/
|
||||
function close_modal( modal ) {
|
||||
modal.removeClass( 'open' );
|
||||
$( modal ).find( '.content-wrapper' ).css( 'height', '' );
|
||||
function close_modal( $modal ) {
|
||||
$modal.removeClass( 'open' );
|
||||
$( $modal ).find( '.content-wrapper' ).css( 'height', '' );
|
||||
|
||||
if ( 0 === modals.filter( '.open' ).length ) {
|
||||
if ( 0 === $modals.filter( '.open' ).length ) {
|
||||
$( document.body ).removeClass( 'wcs-modal-open' );
|
||||
$currentModal = false;
|
||||
document.removeEventListener( 'focusin', keepFocusInModal );
|
||||
$triggerElement.focus();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +92,7 @@ jQuery( function ( $ ) {
|
|||
* Resize all open modals to fit the display.
|
||||
*/
|
||||
function resizeModals() {
|
||||
$( modals ).each( function () {
|
||||
$( $modals ).each( function () {
|
||||
if ( ! $( this ).hasClass( 'open' ) ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -98,17 +104,28 @@ jQuery( function ( $ ) {
|
|||
/**
|
||||
* Resize a modal to fit the display.
|
||||
*
|
||||
* @param {JQuery Object} modal
|
||||
* @param {JQuery Object} $modal
|
||||
*/
|
||||
function resizeModal( modal ) {
|
||||
var modal_container = $( modal ).find( '.content-wrapper' );
|
||||
function resizeModal( $modal ) {
|
||||
const $modal_container = $( $modal ).find( '.content-wrapper' );
|
||||
|
||||
// On smaller displays the height is already forced to be 100% in CSS. We just clear any height we might set previously.
|
||||
if ( $( window ).width() <= 414 ) {
|
||||
modal_container.css( 'height', '' );
|
||||
} else if ( modal_container.height() > $( window ).height() ) {
|
||||
$modal_container.css( 'height', '' );
|
||||
} else if ( $modal_container.height() > $( window ).height() ) {
|
||||
// Force the container height to trigger scroll etc if it doesn't fit on the screen.
|
||||
modal_container.css( 'height', '90%' );
|
||||
$modal_container.css( 'height', '90%' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If focus moves out of the open modal, return focus to it.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
function keepFocusInModal( event ) {
|
||||
if ( $currentModal && ! $currentModal[0].contains( event.target ) ) {
|
||||
$currentModal.focus();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
/**
|
||||
* @deprecated subscriptions-core 7.7.0 This file is no longer in use and can be removed in future.
|
||||
*/
|
||||
jQuery( function ( $ ) {
|
||||
var upgrade_start_time = null,
|
||||
total_subscriptions = wcs_update_script_data.subscription_count;
|
||||
|
|
@ -1,205 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ $# -lt 3 ] && [ -z $WCPAY_DIR ]; then
|
||||
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [wc-version] [skip-database-creation]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DB_NAME=${1-wcpay_tests}
|
||||
DB_USER=${2-root}
|
||||
DB_PASS=${3-$MYSQL_ROOT_PASSWORD}
|
||||
DB_HOST=${4-$WORDPRESS_DB_HOST}
|
||||
WP_VERSION=${5-latest}
|
||||
WC_VERSION=${6-latest}
|
||||
SKIP_DB_CREATE=${7-false}
|
||||
|
||||
TMPDIR=${TMPDIR-/tmp}
|
||||
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
|
||||
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
|
||||
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
|
||||
|
||||
download() {
|
||||
if [ `which curl` ]; then
|
||||
curl -s "$1" > "$2";
|
||||
elif [ `which wget` ]; then
|
||||
wget -nv -O "$2" "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
wp() {
|
||||
WORKING_DIR="$PWD"
|
||||
cd "$WP_CORE_DIR"
|
||||
|
||||
if [ ! -f $TMPDIR/wp-cli.phar ]; then
|
||||
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar "$TMPDIR/wp-cli.phar"
|
||||
fi
|
||||
php "$TMPDIR/wp-cli.phar" $@
|
||||
|
||||
cd "$WORKING_DIR"
|
||||
}
|
||||
|
||||
get_db_connection_flags() {
|
||||
# parse DB_HOST for port or socket references
|
||||
local DB_HOST_PARTS=(${DB_HOST//\:/ })
|
||||
local DB_HOSTNAME=${DB_HOST_PARTS[0]};
|
||||
local DB_SOCK_OR_PORT=${DB_HOST_PARTS[1]};
|
||||
local EXTRA_FLAGS=""
|
||||
|
||||
if ! [ -z $DB_HOSTNAME ] ; then
|
||||
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
|
||||
EXTRA_FLAGS=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
|
||||
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
|
||||
EXTRA_FLAGS=" --socket=$DB_SOCK_OR_PORT"
|
||||
elif ! [ -z $DB_HOSTNAME ] ; then
|
||||
EXTRA_FLAGS=" --host=$DB_HOSTNAME --protocol=tcp"
|
||||
fi
|
||||
fi
|
||||
echo "--user=$DB_USER --password=$DB_PASS $EXTRA_FLAGS";
|
||||
}
|
||||
|
||||
wait_db() {
|
||||
local MYSQLADMIN_FLAGS=$(get_db_connection_flags)
|
||||
local WAITS=0
|
||||
|
||||
set +e
|
||||
mysqladmin status $MYSQLADMIN_FLAGS > /dev/null
|
||||
while [[ $? -ne 0 ]]; do
|
||||
((WAITS++))
|
||||
if [ $WAITS -ge 6 ]; then
|
||||
echo "Maximum database wait time exceeded"
|
||||
exit 1
|
||||
fi;
|
||||
echo "Waiting until the database is available..."
|
||||
sleep 5s
|
||||
mysqladmin status $MYSQLADMIN_FLAGS > /dev/null
|
||||
done
|
||||
set -e
|
||||
}
|
||||
|
||||
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
|
||||
WP_BRANCH=${WP_VERSION%\-*}
|
||||
WP_TESTS_TAG="branches/$WP_BRANCH"
|
||||
|
||||
elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
|
||||
WP_TESTS_TAG="branches/$WP_VERSION"
|
||||
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
|
||||
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
|
||||
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
|
||||
WP_TESTS_TAG="tags/${WP_VERSION%??}"
|
||||
else
|
||||
WP_TESTS_TAG="tags/$WP_VERSION"
|
||||
fi
|
||||
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
|
||||
WP_TESTS_TAG="trunk"
|
||||
else
|
||||
# http serves a single offer, whereas https serves multiple. we only want one
|
||||
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
|
||||
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
|
||||
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
|
||||
if [[ -z "$LATEST_VERSION" ]]; then
|
||||
echo "Latest WordPress version could not be found"
|
||||
exit 1
|
||||
fi
|
||||
WP_TESTS_TAG="tags/$LATEST_VERSION"
|
||||
fi
|
||||
set -e
|
||||
|
||||
install_wp() {
|
||||
if [ -d $WP_CORE_DIR ]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
mkdir -p $WP_CORE_DIR
|
||||
|
||||
wp core download --version=$WP_VERSION
|
||||
|
||||
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
|
||||
}
|
||||
|
||||
configure_wp() {
|
||||
WP_SITE_URL="http://local.wordpress.test"
|
||||
wait_db
|
||||
|
||||
if [[ ! -f "$WP_CORE_DIR/wp-config.php" ]]; then
|
||||
wp core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --dbprefix=wptests_
|
||||
fi
|
||||
wp core install --url="$WP_SITE_URL" --title="Example" --admin_user=admin --admin_password=password --admin_email=info@example.com --skip-email
|
||||
}
|
||||
|
||||
install_test_suite() {
|
||||
# portable in-place argument for both GNU sed and Mac OSX sed
|
||||
if [[ $(uname -s) == 'Darwin' ]]; then
|
||||
local ioption='-i.bak'
|
||||
else
|
||||
local ioption='-i'
|
||||
fi
|
||||
|
||||
# set up testing suite if it doesn't yet exist
|
||||
if [ ! -d $WP_TESTS_DIR ]; then
|
||||
# set up testing suite
|
||||
mkdir -p $WP_TESTS_DIR
|
||||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
|
||||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
|
||||
fi
|
||||
|
||||
if [ ! -f wp-tests-config.php ]; then
|
||||
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
# remove all forward slashes in the end
|
||||
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
|
||||
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/example.org/woocommerce.com/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
sed $ioption "s/admin@example.org/tests@woocommerce.com/" "$WP_TESTS_DIR"/wp-tests-config.php
|
||||
fi
|
||||
}
|
||||
|
||||
install_db() {
|
||||
if [ ${SKIP_DB_CREATE} = "true" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
wait_db
|
||||
local MYSQLADMIN_FLAGS=$(get_db_connection_flags)
|
||||
|
||||
# drop database if exists
|
||||
set +e
|
||||
mysqladmin drop --force $DB_NAME $MYSQLADMIN_FLAGS &> /dev/null
|
||||
set -e
|
||||
|
||||
# create database
|
||||
mysqladmin create $DB_NAME $MYSQLADMIN_FLAGS
|
||||
}
|
||||
|
||||
install_woocommerce() {
|
||||
WC_INSTALL_EXTRA=''
|
||||
INSTALLED_WC_VERSION=$(wp plugin get woocommerce --field=version)
|
||||
|
||||
if [[ $WC_VERSION == 'beta' ]]; then
|
||||
# Get the latest non-trunk version number from the .org repo. This will usually be the latest release, beta, or rc.
|
||||
WC_VERSION=$(curl https://api.wordpress.org/plugins/info/1.0/woocommerce.json | jq -r '.versions | with_entries(select(.key|match("beta";"i"))) | keys[-1]' --sort-keys)
|
||||
fi
|
||||
|
||||
if [[ -n $INSTALLED_WC_VERSION ]] && [[ $WC_VERSION == 'latest' ]]; then
|
||||
# WooCommerce is already installed, we just must update it to the latest stable version
|
||||
wp plugin update woocommerce
|
||||
wp plugin activate woocommerce
|
||||
else
|
||||
if [[ $INSTALLED_WC_VERSION != $WC_VERSION ]]; then
|
||||
# WooCommerce is installed but it's the wrong version, overwrite the installed version
|
||||
WC_INSTALL_EXTRA+=" --force"
|
||||
fi
|
||||
if [[ $WC_VERSION != 'latest' ]] && [[ $WC_VERSION != 'beta' ]]; then
|
||||
WC_INSTALL_EXTRA+=" --version=$WC_VERSION"
|
||||
fi
|
||||
wp plugin install woocommerce --activate$WC_INSTALL_EXTRA
|
||||
fi
|
||||
}
|
||||
|
||||
install_wp
|
||||
install_db
|
||||
configure_wp
|
||||
install_test_suite
|
||||
install_woocommerce
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-i18n', 'wp-primitives'), 'version' => '8bad0ce18409676b15d1');
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
.wcs-recurring-totals-panel{padding:1em 0 0;position:relative}.wcs-recurring-totals-panel:after{border-style:solid;border-width:1px 0;bottom:0;content:"";display:block;right:0;opacity:.3;pointer-events:none;position:absolute;left:0;top:0}.wcs-recurring-totals-panel+.wcs-recurring-totals-panel:after{border-top-width:0}.wcs-recurring-totals-panel .wc-block-components-panel .wc-block-components-totals-item{padding-right:0;padding-left:0}.wcs-recurring-totals-panel .wc-block-components-totals-item__label:first-letter{text-transform:capitalize}.wcs-recurring-totals-panel .wcs-recurring-totals-panel__title .wc-block-components-totals-item__label{font-weight:500}.wcs-recurring-totals-panel__title{margin:0}.wc-block-components-main .wcs-recurring-totals-panel__details{padding:0 16px}.wcs-recurring-totals-panel__details .wc-block-components-panel__button,.wcs-recurring-totals-panel__details .wc-block-components-panel__button:focus,.wcs-recurring-totals-panel__details .wc-block-components-panel__button:hover{font-size:.875em}.wcs-recurring-totals-panel__details .wc-block-components-panel__content>.wc-block-components-totals-item:first-child{margin-top:0}.wcs-recurring-totals-panel__details .wc-block-components-panel__content>.wc-block-components-totals-item:last-child{margin-bottom:0}.wcs-recurring-totals-panel__details .wcs-recurring-totals-panel__details-total .wc-block-components-totals-item__label{font-weight:700}.wcs-recurring-totals__subscription-length{float:left}
|
||||
.wc-block-components-local-pickup-rates-control .wc-block-components-local-pickup-select:not(:last-child){margin-bottom:16px}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-data-store', 'wc-price-format', 'wc-settings', 'wp-data', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '32bfa486d902830f29c7');
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
.wcs-recurring-totals-panel{padding:1em 0 0;position:relative}.wcs-recurring-totals-panel:after{border-style:solid;border-width:1px 0;bottom:0;content:"";display:block;left:0;opacity:.3;pointer-events:none;position:absolute;right:0;top:0}.wcs-recurring-totals-panel+.wcs-recurring-totals-panel:after{border-top-width:0}.wcs-recurring-totals-panel .wc-block-components-panel .wc-block-components-totals-item{padding-left:0;padding-right:0}.wcs-recurring-totals-panel .wc-block-components-totals-item__label:first-letter{text-transform:capitalize}.wcs-recurring-totals-panel .wcs-recurring-totals-panel__title .wc-block-components-totals-item__label{font-weight:500}.wcs-recurring-totals-panel__title{margin:0}.wc-block-components-main .wcs-recurring-totals-panel__details{padding:0 16px}.wcs-recurring-totals-panel__details .wc-block-components-panel__button,.wcs-recurring-totals-panel__details .wc-block-components-panel__button:focus,.wcs-recurring-totals-panel__details .wc-block-components-panel__button:hover{font-size:.875em}.wcs-recurring-totals-panel__details .wc-block-components-panel__content>.wc-block-components-totals-item:first-child{margin-top:0}.wcs-recurring-totals-panel__details .wc-block-components-panel__content>.wc-block-components-totals-item:last-child{margin-bottom:0}.wcs-recurring-totals-panel__details .wcs-recurring-totals-panel__details-total .wc-block-components-totals-item__label{font-weight:700}.wcs-recurring-totals__subscription-length{float:right}
|
||||
.wc-block-components-local-pickup-rates-control .wc-block-components-local-pickup-select:not(:last-child){margin-bottom:16px}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
.woocommerce-subscriptions-announcement__container{border-radius:2px;bottom:44px;cursor:default;display:inline;position:fixed;left:16px;z-index:9999}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step{box-shadow:0 2px 3px 0 rgba(0,0,0,.05),0 4px 5px 0 rgba(0,0,0,.04),0 4px 5px 0 rgba(0,0,0,.03),0 16px 16px 0 rgba(0,0,0,.02)}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step .components-elevation{display:none}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__header{position:absolute}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__header-image{background-color:#f2edff;border-radius:0;height:140px;padding:18px}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__header-image img{margin:0 auto;max-width:100%;width:120px!important}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__body{padding-top:8px!important}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step-navigation{justify-content:end!important}
|
||||
|
|
@ -0,0 +1 @@
|
|||
.woocommerce-subscriptions-announcement__container{border-radius:2px;bottom:44px;cursor:default;display:inline;position:fixed;right:16px;z-index:9999}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step{box-shadow:0 2px 3px 0 rgba(0,0,0,.05),0 4px 5px 0 rgba(0,0,0,.04),0 4px 5px 0 rgba(0,0,0,.03),0 16px 16px 0 rgba(0,0,0,.02)}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step .components-elevation{display:none}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__header{position:absolute}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__header-image{background-color:#f2edff;border-radius:0;height:140px;padding:18px}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__header-image img{margin:0 auto;max-width:100%;width:120px!important}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step__body{padding-top:8px!important}.woocommerce-subscriptions-announcement .woocommerce-tour-kit-step-navigation{justify-content:end!important}
|
||||
|
|
@ -0,0 +1 @@
|
|||
.wcsg-gifting-to-container-editing{display:flex;gap:5px;margin-top:10px;min-width:210px}.wcsg-gifting-to-container-editing .wc-block-components-text-input{flex-grow:1;margin-top:0}.wcsg-gifting-to-container-editing .wp-element-button.gifting-update-button:not(.is-link){min-height:unset;padding:0 var(--xs,20px)}.wcsg-gifting-to-container-editing .components-base-control__field{margin-bottom:0}.wcsg-gifting-to-container-editing .wc-block-components-text-input input:-webkit-autofill{padding-top:.5em}.wcsg-gifting-to-container-editing .has-error .components-text-control__input{color:var(--wc-red,#cc1818)}.wp-block-woocommerce-mini-cart-contents .wcsg-gifting-to-container-editing{flex-direction:column}.wp-block-woocommerce-mini-cart-contents .gifting-update-button{height:40px}.wcsg-gifting-to-container-view{align-items:center;display:flex;flex-wrap:wrap;gap:5px;max-width:100%}.wcsg-gifting-to-container-view span{align-items:center;display:inline-flex;max-width:100%;word-break:break-all;word-wrap:break-word;gap:5px}.wcsg-gifting-to-container-view .components-button.is-link{color:var(--wp--preset--color--contrast);flex-shrink:0;font-size:medium}.wc-block-checkout,.wc-block-components-product-details__gifting-to{align-items:center;display:flex;flex-wrap:wrap;max-width:100%}.wc-block-checkout .wc-block-components-product-details__name:after,.wc-block-components-product-details__gifting-to .wc-block-components-product-details__name:after{content:" "}.wc-block-checkout .wc-block-components-product-details__value,.wc-block-components-product-details__gifting-to .wc-block-components-product-details__value{align-items:center;display:inline-flex;max-width:100%;word-break:break-all;word-wrap:break-word}.wcsg-block-recipient-container{font-size:var(--wp--preset--font-size--small,14px);line-height:20px}.wcsg-block-recipient-container .components-checkbox-control__label{font-size:var(--wp--preset--font-size--small,14px);margin-bottom:0}.wc-block-cart .wc-block-components-product-details__gifting-to,.wc-block-cart .wc-block-components-product-details__gifting-to-hidden,.wc-block-cart .wc-block-components-product-details__item-key,.wc-block-checkout .wc-block-components-product-details__gifting-to-hidden,.wc-block-checkout .wc-block-components-product-details__item-key,.wp-block-woocommerce-mini-cart-contents .wc-block-components-product-details__gifting-to,.wp-block-woocommerce-mini-cart-contents .wc-block-components-product-details__gifting-to-hidden,.wp-block-woocommerce-mini-cart-contents .wc-block-components-product-details__item-key{display:none}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'react-dom', 'wc-blocks-checkout', 'wp-components', 'wp-data', 'wp-i18n', 'wp-plugins', 'wp-url'), 'version' => 'cf4dd71c0c7418b591fd');
|
||||
|
|
@ -0,0 +1 @@
|
|||
.wcsg-gifting-to-container-editing{display:flex;gap:5px;margin-top:10px;min-width:210px}.wcsg-gifting-to-container-editing .wc-block-components-text-input{flex-grow:1;margin-top:0}.wcsg-gifting-to-container-editing .wp-element-button.gifting-update-button:not(.is-link){min-height:unset;padding:0 var(--xs,20px)}.wcsg-gifting-to-container-editing .components-base-control__field{margin-bottom:0}.wcsg-gifting-to-container-editing .wc-block-components-text-input input:-webkit-autofill{padding-top:.5em}.wcsg-gifting-to-container-editing .has-error .components-text-control__input{color:var(--wc-red,#cc1818)}.wp-block-woocommerce-mini-cart-contents .wcsg-gifting-to-container-editing{flex-direction:column}.wp-block-woocommerce-mini-cart-contents .gifting-update-button{height:40px}.wcsg-gifting-to-container-view{align-items:center;display:flex;flex-wrap:wrap;gap:5px;max-width:100%}.wcsg-gifting-to-container-view span{align-items:center;display:inline-flex;max-width:100%;word-break:break-all;word-wrap:break-word;gap:5px}.wcsg-gifting-to-container-view .components-button.is-link{color:var(--wp--preset--color--contrast);flex-shrink:0;font-size:medium}.wc-block-checkout,.wc-block-components-product-details__gifting-to{align-items:center;display:flex;flex-wrap:wrap;max-width:100%}.wc-block-checkout .wc-block-components-product-details__name:after,.wc-block-components-product-details__gifting-to .wc-block-components-product-details__name:after{content:" "}.wc-block-checkout .wc-block-components-product-details__value,.wc-block-components-product-details__gifting-to .wc-block-components-product-details__value{align-items:center;display:inline-flex;max-width:100%;word-break:break-all;word-wrap:break-word}.wcsg-block-recipient-container{font-size:var(--wp--preset--font-size--small,14px);line-height:20px}.wcsg-block-recipient-container .components-checkbox-control__label{font-size:var(--wp--preset--font-size--small,14px);margin-bottom:0}.wc-block-cart .wc-block-components-product-details__gifting-to,.wc-block-cart .wc-block-components-product-details__gifting-to-hidden,.wc-block-cart .wc-block-components-product-details__item-key,.wc-block-checkout .wc-block-components-product-details__gifting-to-hidden,.wc-block-checkout .wc-block-components-product-details__item-key,.wp-block-woocommerce-mini-cart-contents .wc-block-components-product-details__gifting-to,.wp-block-woocommerce-mini-cart-contents .wc-block-components-product-details__gifting-to-hidden,.wp-block-woocommerce-mini-cart-contents .wc-block-components-product-details__item-key{display:none}
|
||||
407
changelog.txt
|
|
@ -1,5 +1,412 @@
|
|||
*** WooCommerce Subscriptions Changelog ***
|
||||
|
||||
2026-01-06 - version 8.3.0
|
||||
* Add: Support for ajax add-to-cart flows from the single product page, when upgrading or downgrading subscriptions.
|
||||
* Add: Enhanced functionality from the WooCommerce Subscription Downloads plugin has now been integrated directly into WooCommerce Subscriptions.
|
||||
* Fix: Ensured the subject line for the "Customer Renewal Invoice" email correctly updates.
|
||||
|
||||
2025-12-22 - version 8.2.1
|
||||
* Fix: Subscription pricing strings now correctly display singular and plural billing intervals like "$10 / month" and "$10 every 3 months" in cart and checkout totals.
|
||||
* Fix: Display all recurring coupon names in the totals section of classic cart and checkout when multiple recurring coupons are applied.
|
||||
* Fix: Payment method selector options on Subscriptions list page are now properly displaying the payment method name for gateways providing multiple payment methods.
|
||||
* Fix: PayPal Standard plugin IPN renewal orders not being created for failed payment retries.
|
||||
* Fix: Prevent fatal errors on shop pages when special characters like % are used in a product name.
|
||||
* Fix: Prevent an email validation error from briefly and inadvertently flashing on the screen when the "this is a gift" checkbox is used.
|
||||
|
||||
2025-12-10 - version 8.2.0
|
||||
* Fix: Various accessibility issues.
|
||||
* Added button roles.
|
||||
* Added labels to remove product links.
|
||||
* Adding missing header labels on related orders table.
|
||||
* Prevented various hidden elements from being exposed to screen readers.
|
||||
* Fixed focus problems for the renewal dialog.
|
||||
* Fixed focus when closing modals.
|
||||
* Fixed toggle state change using spacebar.
|
||||
* Fixed label for sign up now button.
|
||||
* Fixed toggle aria-label text to reflect state.
|
||||
* Added aria-haspopup attribute to buttons that open modals.
|
||||
* Fixed link for view order aria-label.
|
||||
* Fixed renew now button text and aria-label.
|
||||
* Added aria-modal and role attributes to modals and dialogs.
|
||||
* Fix: Resubscribe button now appears correctly for cancelled limited subscriptions.
|
||||
* Fix: Missing translation for pricing string on languages without plural form.
|
||||
* Fix: Customized subscriptions links in WooCommerce emails now work correctly.
|
||||
* Fix: Possible fatal errors when switching grouped subscriptions.
|
||||
* Fix: Prevent unnecessary log entries related to gifted subscriptions.
|
||||
* Fix: Make it easier for translation plugins to respect individual customer language preferences when sending subscription emails.
|
||||
* Fix: Prevent recurring local pickup options from displaying for virtual subscriptions when the cart contains physical products.
|
||||
* Fix: Prevent shipping summary from displaying on Blocks Checkout for virtual subscriptions.
|
||||
* Fix: Item price in blocks checkout is correctly displayed without "due today" words for items with zero sign up fee.
|
||||
|
||||
2025-11-13 - version 8.1.0
|
||||
* Fix: Prevent a fatal error that can occur when previewing emails in WooCommerce email settings.
|
||||
* Fix: Prevent technical subscription-specific discount types from appearing in the coupon edit UI.
|
||||
* Fix: Add admin notice and debug tool to recreate the payment retry database table when it's missing.
|
||||
* Fix: Prevent resubscribe and reactivate buttons from showing for subscriptions containing disabled, deleted, draft, or limited products.
|
||||
* Fix: Prevent error that blocks the subscriptions list from loading when gifted subscriptions are purchased with certain payment methods.
|
||||
* Fix: Ensure gift recipient email address is displayed in the order confirmation email sent to the purchaser.
|
||||
* Fix: Prevent pickup location options from displaying incorrectly alongside shipping methods on the Blocks Checkout page.
|
||||
* Fix: Fix invalid HTML tags that cause fatal errors when using themes with WordPress Interactivity API.
|
||||
* Fix: Add password reset links to the new account email template for gifted subscription recipients.
|
||||
* Tweak: Improve the gift recipient email input field on Blocks Cart and Mini Cart to match the style of other checkout fields.
|
||||
* Dev: Improve housekeeping of output buffers when handling requests to change subscription payment methods.
|
||||
* Dev: Improve type safety in relation to the `wcs_get_subscription()` function.
|
||||
|
||||
2025-10-15 - version 8.0.0
|
||||
* Add: Blocks Checkout now displays a single shipping method selection for both initial and recurring carts, similar to Classic Checkout. This can be disabled using the `wcs_cart_totals_shipping_html_price_only` filter.
|
||||
* Fix: Resubscribing to a limited subscription from the product page will now reactivate the existing subscription.
|
||||
* Fix: "New initial order - Recipient" email template preview no longer causes critical error.
|
||||
* Fix: Shipping value on blocks checkout no longer shows as "Free" when no shipping method is available.
|
||||
* Dev: Improved data telemetry which is sent to WooCommerce:
|
||||
* WooCommerce Subscriptions setting values
|
||||
* Order totals of subscription-related orders by order type and payment gateway, aggregated by month
|
||||
* Number of subscription-related orders by order type and payment gateway, aggregated by month
|
||||
* Number of products in parent subscription orders, aggregated by month
|
||||
* Number of non-zero value parent subscription orders, aggregated by month
|
||||
* Number of subscription products by billing interval
|
||||
* Number of giftable subscription products
|
||||
* Number of subscriptions by payment method, billing period, and renewal type
|
||||
* Number of gifted subscriptions
|
||||
* Number of subscribers
|
||||
* Purchase event for subscription products
|
||||
* Exclude orders with a "processing" status from the "subscription_orders" telemetry data.
|
||||
|
||||
2025-09-16 - version 7.9.0
|
||||
* Add: REST API endpoint to retrieve subscriptions associated with a specific order ID.
|
||||
* Fix: Keep subscription with successful renewals active when parent order fails.
|
||||
* Fix: Error when renewing subscriptions with downloadable gifts.
|
||||
* Fix: Improve performance by loading assets only when necessary.
|
||||
* Fix: "Update cart" button being always enabled.
|
||||
* Fix: Gifting recipient email layout issues when using a long e-mail address.
|
||||
* Fix: Gifting checkbox not showing up on blocks cart when using WooCommerce 10.2+.
|
||||
* Fix: Deleting a gifted subscription recipient will not delete their subscriptions, they will be moved to the subscription purchaser instead.
|
||||
* Dev: The `wcs_get_subscriptions()` and `wcs_get_subscriptions_for_order()` functions are now stricter, and only return instances of `WC_Subscription`.
|
||||
|
||||
2025-09-02 - version 7.8.2
|
||||
* Fix: Error when updating/renewing subscriptions containing a pseudo coupon.
|
||||
* Fix: Fix gifting recipient notice being shown for non gifting orders.
|
||||
|
||||
2025-08-25 - version 7.8.1
|
||||
* Fix: Fix checkout button default label.
|
||||
* Fix: Fix error when WP CLI is enabled in some environments.
|
||||
|
||||
2025-08-19 - version 7.8.0
|
||||
* Add: Native support for subscriptions gifting. Gifting for WooCommerce Subscriptions extension is no longer required.
|
||||
* Add: Enable subscriptions gifting storewide and per product.
|
||||
* Add: Blocks support for gifting on product, cart, and checkout pages.
|
||||
* Update: Make WooCommerce Subscriptions reports compatible with High Performance Order Storage.
|
||||
* Update: Rename Subscribe now button to Add to Cart to follow WooCommerce convention.
|
||||
* Fix: Fix integration with WooCommerce dashboard widget.
|
||||
* Fix: Cancel pending related orders when a subscription is cancelled to prevent orphaned orders that need payment.
|
||||
* Fix: Allow manual payments for pending renewal orders of Product Bundles or Composite Products when Mixed Checkout options is disabled.
|
||||
* Dev: Update moment.js package to the latest version 2.30.1
|
||||
|
||||
2025-07-09 - version 7.7.0
|
||||
* Fix: Restores normal behavior for the report caching updates scheduled action, which was failing due to a bad filepath.
|
||||
* Fix: Fix error when placing an order with a valid card after using a declined one.
|
||||
* Fix: Fix order renewal errors when using some plugins.
|
||||
* Fix: Prevent fatal errors when loading or deleting subscriptions with corrupted date values stored in a database.
|
||||
* Fix: Prevent fatal errors when trying to save invalid date values and display better error messages instead.
|
||||
* Fix: Fix broken blocks and javascript translations.
|
||||
* Fix: Keep newly created subscriptions in pending status when initial payment fails instead of putting them on hold.
|
||||
* Dev: Improve test suite bootstrap process by postponing interactions with Action Scheduler until it has fully initialized.
|
||||
* Dev: Plugin upgrade routines will now be triggered by changes in the main plugin version (and not the core library version).
|
||||
* Dev: Update wcs_is_paypal_profile_a() so it handles non-string parameters more gracefully. This is principally to reduce noise levels when running the test suite.
|
||||
* Dev: Proactively reviewed and hardened code to improve our security posture going forward.
|
||||
|
||||
2025-06-11 - version 7.6.0
|
||||
* Update: Allow updating billing info on existing subscriptions when customer changes account details.
|
||||
* Fix: Use floats instead of integers for tax calculation in subscription switching when prices include tax.
|
||||
* Fix: Enhance checks in email templates upgrade script for WooCommerce Subscriptions core 8.3.0.
|
||||
* Dev: Refactor argument processing in run-tests.sh to add a direct check for the -w flag.
|
||||
* Fix: Undefined array key `new`
|
||||
* Fix: Ensure subscription exists before updating its last order date.
|
||||
* Fix: Prevent fatal error when the line items no longer exist in the database.
|
||||
|
||||
2025-05-20 - version 7.5.0
|
||||
* Update: Add pagination to the related orders list in the My Account > View Subscription page.
|
||||
* Fix: Infinite loop when trying to load subscription related orders meta after cache busting.
|
||||
* Fix: Replace blogname with site_title on translation files.
|
||||
* Dev: Make the `wcs_get_subscriptions_for_order()` function more robust. It should not return any subscriptions if presented with an invalid order.
|
||||
|
||||
2025-04-14 - version 7.4.0
|
||||
* Update: Increase the number of args accepted by wcs_get_subscriptions(), to bring about parity with wc_get_orders().
|
||||
* Dev: Update wcs_maybe_prefix_key() and wcs_maybe_unprefix_key() to support an array of keys.
|
||||
* Fix: Prevent sending renewal reminders for orders with a 0 total.
|
||||
* Fix: Ensure the second parameter passed to the 'get_edit_post_link' filter is an integer.
|
||||
* Fix: Prevent WooCommerce Subscriptions buttons from overflowing in the View subscription page
|
||||
* Dev: Update subscriptions-core to 8.2.0
|
||||
|
||||
2025-03-31 - version 7.3.1
|
||||
* Update: Display the subscription parent order icon in the WooCommerce Orders list table by default.
|
||||
* Dev: Update subscriptions-core to 8.1.1
|
||||
|
||||
2025-03-24 - version 7.3.0
|
||||
* Tweak: Adjust the warning that appears on the reports page when HPOS is enabled but Compatibility Mode is disabled (provide a direct link to the relevant settings).
|
||||
* Update: Improved subscription search performance for WP Post stores by removing unnecessary _order_key and _billing_email meta queries.
|
||||
* Update: Make it possible to dispatch the Cancelled Subscription email more than once (when initially set to pending-cancellation, and again when it reaches final cancellation).
|
||||
* Update: Reduced duplicate queries when fetching multiple subscription related orders types.
|
||||
* Update: Removed unnecessary get_time() calls to reduce redundant get_last_order() queries in the Subscriptions list table.
|
||||
* Update: Improved performance on the Orders list table when rendering the Subscription Relationship column.
|
||||
* Update: Improved performance of the Generate Related Order Cache tool found under WooCommerce > Status > Tools.
|
||||
* Fix: Do not schedule updates to the report data cache if reporting is not available (ie, if HPOS is enabled but Compatibility Mode is not).
|
||||
* Fix: Resolved deprecated dynamic property warnings in WCS_Email_Payment_Retry and WCS_Email_Customer_Payment_Retry.
|
||||
* Fix: Added support for previewing payment retry emails in WooCommerce email settings.
|
||||
* Fix: Updated subscription email item table template to align with WooCommerce 9.7 email improvements.
|
||||
* Fix: Prevent PHP warning on cart page shipping method updates by removing unused method: maybe_restore_shipping_methods.
|
||||
* Fix: Removed unnecessary setting of renewal order paid date on status transition, relying on WooCommerce core behavior instead.
|
||||
* Fix: Ensure the order_awaiting_payment session arg is restored when loading a renewal cart from the session to prevent duplicate orders.
|
||||
* Fix: Ensure custom placeholders (time_until_renewal, customers_first_name) are included in customer notification email previews.
|
||||
* Fix: For stores with HPOS + compatibility mode enabled, using the bulk delete related orders cache tool was not correctly deleting the meta from the WP Posts table.
|
||||
* Fix: Prevent empty strings being saved in related orders cache ID meta when backfilling order data to the WP Posts table.
|
||||
* Fix: Correctly load product names with HTML on the cart and checkout shipping rates.
|
||||
* Dev: Fix Node version mismatch between package.json and .nvmrc (both are now set to v16.17.1).
|
||||
* Dev: Update subscriptions-core to 8.1.0
|
||||
|
||||
2025-02-13 - version 7.2.1
|
||||
* Fix: Revert a change released in 7.2.0 which triggered the "woocommerce_cart_item_name" filter with the wrong number of parameters.
|
||||
* Dev: Update subscriptions-core to 8.0.1.
|
||||
|
||||
2025-02-13 - version 7.2.0
|
||||
* Fix: In the system status report, show correct icon in the Cache Update Failures section when the total failures is 0.
|
||||
* Fix: Recommend WooPayments when there is no available payment gateway.
|
||||
* Fix: Safeguards added to the Subscriptions Totals template used in the My Account area, to guard against fatal errors that could arise in unusual conditions.
|
||||
* Fix: Correctly load product names with HTML on the cart and checkout shipping rates.
|
||||
* Fix: Improve our admin notice handling to ensure notices are displayed to the intended admin user.
|
||||
* Fix: Improve protections around the pending renewal order-creation process, to prevent uncaught exceptions and other errors from breaking the subscription editor.
|
||||
* Fix: Prevent unnecessary subscription object lookups on non-subscription admin pages when global $post is set.
|
||||
* Fix: After enabling the Customer Notification feature or changing the reminder timing setting, ensure notifications are correctly scheduled for all subscriptions with pending cancellation status.
|
||||
* Update: Improve performance of displaying recurring coupon limits in the admin coupon list table by optimizing coupon object retrieval.
|
||||
* Update: Display the subscription items table in all customer notification emails.
|
||||
* Update: Subscription notes for unsent customer notification emails now only occurs if WCS_DEBUG is enabled.
|
||||
* Dev: Introduces a new `woocommerce_subscription_valid_customer_notification_types` filter to modify which notification types are scheduled in Action Scheduler.
|
||||
* Dev: Update subscriptions-core to 8.0.0.
|
||||
|
||||
2025-01-10 - version 7.1.0
|
||||
* Add: Compatibility with WooCommerce's new preview email feature introduced in 9.6.
|
||||
* Fix: Prevents PHP fatal error when wcs_can_user_renew_early() is called with a non-existent subscription ID.
|
||||
* Fix: Prevent payment gateways that complete Change Payment requests asynchronously from blocking future attempts to update payment methods for all subscriptions.
|
||||
* Fix: Resolved an issue that could lead to undefined variable when attempting to send a customer notification email with no order.
|
||||
* Fix: Prevents the customer's postal code being used as their billing city in the current session, following a change to payment details.
|
||||
* Dev: Use the subscription's customer ID during the `wcs_can_user_renew_early()` function call when sending customer notification emails.
|
||||
* Dev: Fix PHP deprecated warnings caused by calling esc_url with null.
|
||||
* Dev: Update subscriptions-core to 7.9
|
||||
|
||||
2024-12-16 - version 7.0.0
|
||||
* Fix: Prevent failing non-recent renewal order from suspending the subscription and marking the most recent renewal order as failed.
|
||||
* Fix: Use block theme-styled buttons for subscription and related-orders actions on My Account pages.
|
||||
* Fix: Subscription totals not properly updating when customers remove items via the My Account > View Subscription page on some stores with caching enabled.
|
||||
* Fix: Resolved unexpected errors during the renewal process when a subscription contains metadata with key "id".
|
||||
* Update: Changed the link on the order thank-you page to take customers directly to their "My Account > Subscriptions" page.
|
||||
* Dev: Update subscriptions-core to 7.8.0
|
||||
|
||||
2024-11-27 - version 6.9.1
|
||||
* Fix: Resolved compatibility issues with WordPress 6.7 caused by translating strings too early.
|
||||
* Dev: Update subscriptions-core to 7.7.2
|
||||
|
||||
2024-11-14 - version 6.9.0
|
||||
* Add: New Customer Notification feature - sends reminder emails for upcoming subscription renewals, trials ending, and subscription expirations.
|
||||
* Fix: Prevent adding products to the cart if a subscription renewal is already present.
|
||||
* Update: Improved performance of wcs_get_subscription() when querying by product and customer or order.
|
||||
* Update: Improved performance when checking limited subscription product availability.
|
||||
* Update: Deprecate upgrading from versions of WooCommerce Subscriptions prior to 3.0.0 (released Jan 2020).
|
||||
* Dev: Minor refactoring of `init` method in `WC_Subscriptions_Upgrader` class.
|
||||
* Dev: Introduce the filter `woocommerce_subscriptions_synced_first_renewal_payment_timestamp` to enable plugins to modify the first renewal date of synced subscriptions.
|
||||
* Dev: Update `get_post_meta()` calls to fetch product meta using CRUD getters.
|
||||
* Dev: Update subscriptions-core to 7.7.1
|
||||
|
||||
2024-10-14 - version 6.8.0
|
||||
* Fix: Restore Retry icon in Orders table for HPOS-enabled stores.
|
||||
* Fix: Correctly updates a subscription status to `cancelled` during a payment failure call when the current status is `pending-cancel`.
|
||||
* Fix: Clear the `cancelled_email_sent` meta when a subscription is reactivated to allow the customer to receive future cancellation emails.
|
||||
* Fix: Prevent deprecation notices after updating to WooCommerce 9.3.
|
||||
* Fix: Prevent PHP fatal error that occurs when calculating the total tax refunded on a subscription.
|
||||
* Dev: Only initialise the `WCS_WC_Admin_Manager` class on stores running WC 9.2 or older. This class handled integration with the Woo Navigation feature that was removed in WC 9.3.
|
||||
|
||||
2024-09-13 - version 6.7.0
|
||||
* Fix: Resolved two issues preventing the correct display of the "Subscription items can no longer be edited." message on the Edit Subscription page.
|
||||
* Fix: Checks for the existence of `wc_get_page_screen_id` before calling it on `wcs_get_page_screen_id`, and for the admin context before calling `list_table_primary_column` to prevent fatal errors.
|
||||
* Fix: Blocks the reactivation of a subscription when the end date is in the past.
|
||||
* Fix: Ensure a subscription's modified date is updated when its related order cache is updated on non-HPOS sites.
|
||||
* Fix: Ensure trial period form data is set before use to prevent fatal errors when the data is missing.
|
||||
* Fix: Resolved an error with coupon discount calculations for manual or early renewal orders on stores with tax-inclusive pricing.
|
||||
* Fix: Add the theme-compatible button class to the switch button on the My Account > Subscription page.
|
||||
* Dev: Removing the unused method `maybe_remove_formatted_order_total_filter` hooked to `woocommerce_get_formatted_order_total` which was deprecated.
|
||||
* Dev: Update subscriptions-core to 7.5.0
|
||||
|
||||
2024-09-05 - version 6.6.2
|
||||
* Fix: Prevent errors during checkout when a customer is switching their subscription product and does not require payment.
|
||||
* Dev: Update subscriptions-core to 7.4.3.
|
||||
|
||||
2024-08-27 - version 6.6.1
|
||||
* Fix: Resolved an issue where simple product prices were incorrectly set to $0 when purchasing subscriptions and simple products with a coupon in WC 9.2.
|
||||
* Dev: Update subscriptions-core to 7.4.2.
|
||||
|
||||
2024-08-22 - version 6.6.0
|
||||
* Fix: Resolve duplicate subscription creation and PHP warning when switching subscriptions with Prepaid for WooCommerce Subscriptions plugin active.
|
||||
* Fix: Switch calculations now exclude previous switch orders with a checkout-draft status.
|
||||
* Dev: Introduce new parameter to WC_Subscription::get_last_order() to enable filtering out orders with specific statuses.
|
||||
* Update: Schedule subscription-related events with a priority of 1 to allow for earlier execution within the Action Scheduler.
|
||||
* Fix: Ensure admin notices are displayed after performing bulk actions on subscriptions when HPOS is enabled.
|
||||
* Fix: Add a year to the next renewal date billing interval is 12 months or more for a synced subscription.
|
||||
* Dev: Added filter to enable overriding the total paid for current switch period.
|
||||
* Dev: Updated subscriptions-core to 7.4.1.
|
||||
|
||||
2024-07-16 - version 6.5.0
|
||||
* Add: Include trial_period, suspension_count, and requires_manual_renewal in the REST API response for subscriptions.
|
||||
* Update: When a renewal order's payment is skipped, include the order's current status in the note to help troubleshooting.
|
||||
* Fix: Label improvements on subscription and order page templates.
|
||||
* Fix: Fixed an issue with subscriptions containing multiple renewal orders to mark a random item as processing, instead of the last order.
|
||||
* Fix: Prevent errors from invalid subscription objects during customer payment method updates.
|
||||
* Dev: Updated subscriptions-core to 7.3.0.
|
||||
|
||||
2024-06-28 - version 6.4.1
|
||||
* Fix: Resolved errors preventing subscription-related webhooks from sending on WC 9.0 stores.
|
||||
|
||||
2024-06-13 - version 6.4.0
|
||||
* Add: New WP CLI support to manage subscriptions via command line.
|
||||
* Add: Introduce wc/v2 subscription REST API endpoints.
|
||||
* Fix: label improvement on my subscription page template.
|
||||
* Fix: Regenerate subscriptions related order caches (renewal, resubscribe, switch) if it's stored as an invalid value to prevent fatal errors.
|
||||
* Update: Show "FREE" instead of 0 when there is no shipping cost in the recurring totals section of the Cart and Checkout blocks (requires WooCommerce 9.0+).
|
||||
* Dev: New function wcs_set_recurring_item_total() to set line item totals that have been copied from an initial order to their proper recurring totals (i.e. remove sign-up fees).
|
||||
* Dev: Updated subscriptions-core to 7.2.0.
|
||||
|
||||
2024-05-24 - version 6.3.2
|
||||
* Fix: Prevent overriding line item totals provided in request data when creating Orders via the REST API.
|
||||
|
||||
2024-05-09 - version 6.3.1
|
||||
* Fix: Resolved an issue that caused "WC_DateTime could not be converted to int" warnings to occur on non-hpos sites while editing a subscription.
|
||||
|
||||
2024-05-09 - version 6.3.0
|
||||
* Fix: Uncaught exception from 'WCS_Related_Order_Store_Cached_CPT::delete_relations' when order is not an instance of WC_Order.
|
||||
* Fix: Include subscription sign-up fees on orders created via the REST API.
|
||||
* Fix: Add check to prevent fatal error in rsort and array_sum.
|
||||
* Fix: Use `add_to_cart_ajax_redirect` instead of the deprecated `redirect_ajax_add_to_cart` function as callback.
|
||||
* Fix: Filtered order links in subscription reports returns all the orders when HPOS is enabled.
|
||||
* Fix: Typo in confirmation alert when users remove an item from a subscription.
|
||||
* Fix: Ensure the scheduled sale price for subscription products ends at the end of the "to" day set in product settings.
|
||||
* Fix: Subscription table is empty in mobile view when HPOS is enabled.
|
||||
* Fix: WooCommerce page header is hidden when HPOS is enabled.
|
||||
* Fix: Subscription updated messages missing on the Edit Subscription page when HPOS is enabled.
|
||||
* Fix: Resolved an issue that prevented bulk actions from running on the Subscriptions list table when the table was filtered by date, payment method, product or customer.
|
||||
* Fix: Subscriptions created via the POST `/wc/v3/orders/{order_id}/subscriptions` endpoint shouldn't include sign-up fees and/or $0 trial periods in line item totals.
|
||||
* Update: Update the shipping method styling to apply borders to the highlighted shipping option in the Checkout block.
|
||||
* Update: Include a full stack trace in failed scheduled action logs to improve troubleshooting issues.
|
||||
* Update: Show notice about product being removed from the cart when a subscription is for disabled mixed checkout setting.
|
||||
* Update: Change plugin name back to WooCommerce Subscriptions.
|
||||
* Dev: Calling wcs_create_subscription() will no longer attempt to fetch a fresh instance of the subscription at the end. This is to prevent loading the subscription from the database potentially unnecessarily.
|
||||
* Dev: Updated subscriptions-core to 7.1.0.
|
||||
* Dev: Bump WooCommerce minimum required version to 7.9.0.
|
||||
|
||||
2024-04-11 - version 6.2.0
|
||||
* Add: Declare WooCommerce as a plugin dependency in the plugin header.
|
||||
* Fix: Ensure next payment dates are only extended when early renewal orders paid via the modal are fully paid. Prevents extending dates on authorized but not captured payments.
|
||||
* Fix: Updated the switching calculator to handle situations where an upgrade has a new price per day less than the old price per day. Previously this would result in a negative upgrade cost.
|
||||
* Fix: Update the failing payment method on a subscription when customers successfully pay for a failed renewal order via the block checkout.
|
||||
* Fix: Resolved an issue that would cause subscriptions to be directly cancelled by the WooCommerce process of automatically cancelling unpaid orders in-line with the hold stock setting.
|
||||
* Fix: Prevent duplicate status transition notes on subscriptions and potential infinite loops when processing subscription status transitions.
|
||||
* Fix: Resolved an issue that could lead to "Undefined array key 'order-received'" errors.
|
||||
* Fix: Resolved errors that could occur when paying for renewal orders via the checkout when the store has custom checkout fields.
|
||||
* Fix: Resolved database errors that would occur when ordering the subscriptions list table by the 'Last order date' on sites with HPOS enabled.
|
||||
* Dev: Introduced a new filter ('wcs_setup_cart_for_subscription_initial_payment') to enable third-party plugins to use the pay-for-order flow to complete a subscription's initial payment.
|
||||
* Dev: Updated subscriptions-core to 7.0.0.
|
||||
|
||||
2024-03-28 - version 6.1.0
|
||||
* Fix: Ensure the subscription renewal payment process doesn't attempt to reprocess previously paid renewal orders.
|
||||
* Fix: Resolved an issue where discounts, when reapplied to failed or manual subscription order payments, would incorrectly account for inclusive tax.
|
||||
* Fix: Resolved an issue that could cause an empty error notice to appear on the My Account > Payment methods page when a customer attempted to delete a token used by subscriptions.
|
||||
* Fix: Make sure we always clear the subscription object from cache after updating dates.
|
||||
* Fix: Use block theme styles for the 'Add to Cart' button on subscription product pages.
|
||||
* Fix: Customer notes not being saved on the Edit Subscription page for stores with HPOS enabled.
|
||||
* Fix: Ensure products that have a yearly billing period can choose a date that the subscription is synchronized to.
|
||||
* Fix: Improved alignment of subscription product pricing fields on the edit product screen for consistency with other fields.
|
||||
* Fix: Avoid setting empty meta keys on subscriptions when changing the customer's default payment method.
|
||||
* Fix: Use a more scalable way to filter the orders admin list table by parent orders on HPOS stores.
|
||||
* Fix: Resolved an issue that prevented subscription custom place order button labels from working on the block checkout.
|
||||
* Update: Change the update all subscriptions checkbox displayed on the change payment method page to be enabled by default.
|
||||
* Dev: Update subscriptions-core to 6.9.0
|
||||
|
||||
2024-02-08 - version 6.0.0
|
||||
* Add: Subscription plugin settings can now be fetched via the /wc/v3/settings/subscriptions REST API endpoint.
|
||||
* Fix: Trigger the subscription.updated webhook event for all subscription updates.
|
||||
* Fix: Block the UI after a customer clicks actions on the My Account > Subscriptions page to prevent multiple requests from being sent.
|
||||
* Fix: WC 8.6.0 compatibility: Resolved wc_get_log_file_path() deprecation warnings.
|
||||
* Dev: Update subscriptions-core to 6.8.0
|
||||
|
||||
2024-01-17 - version 5.9.1
|
||||
* Fix: Resolved an error that would occur with WooCommerce 8.5.0 when editing a subscription customer from the admin dashboard.
|
||||
|
||||
2024-01-11 - version 5.9.0
|
||||
* Fix: Resolved an issue that caused ordering the Admin Subscriptions List Table to not work when HPOS is enabled.
|
||||
* Fix: When switching all subscription items in the same cart, ensure the previous subscription is reused where possible instead of creating all new subscriptions.
|
||||
* Update: Changed the edit subscription product "Expire after" (Subscription length) so it more clearly describes when a subscription will automatically stop renewing.
|
||||
* Update: Log all exceptions caught by WooCommerce while processing a subscription scheduled action.
|
||||
* Dev: Update subscriptions-core to 6.7.0.
|
||||
|
||||
2023-12-21 - version 5.8.0
|
||||
* Fix: Incorrect switch calculation when upgrading a synchronised product before the first renewal is due where the initial payment was prorated.
|
||||
* Fix: When updating a subscription via the REST API, don't update the start date to the current time if the start date is not set in the request.
|
||||
* Fix: When using the checkout block to pay for renewal orders, ensure the order's cart hash is updated to make sure the existing order can be used.
|
||||
* Fix: Prevents a PHP fatal error that occurs when the cart contains a renewal order item that no longer exists.
|
||||
* Fix: When HPOS is enabled and data compatibility mode is turned on, make sure subscription date changes made to postmeta are synced to orders_meta table.
|
||||
* Fix: Resolved an issue that would cause undefined $current_page, $max_num_pages, and $paginate variable errors when viewing a page with the subscriptions-shortcode.
|
||||
* Dev: Update subscriptions-core to 6.6.0.
|
||||
|
||||
2023-11-09 - version 5.7.0
|
||||
* Add: Introduce a new REST API endpoint to create subscription(s) from a given order. This endpoint is available at POST `/wc/v3/orders/{order_id}/subscriptions` and accepts a single order ID.
|
||||
* Add: When a customer toggles automatic renewals on or off via their My Account page, add a note to the subscription to record that event.
|
||||
* Fix: Set and update a subscription's trial end date via the REST API.
|
||||
* Fix: Ensure the `woocommerce_subscription_renewal_payment_complete` hook is always triggered when processing early renewals via the checkout page (introduced in 5.6.0).
|
||||
* Fix: When a subscription is flagged as requiring manual payments, allow admin users to turn on automatic payments for a subscription via the Edit Subscription page by selecting a new payment method.
|
||||
* Fix: When processing an early renewal order, make sure the suspension count is reset back to 0 on payment complete.
|
||||
* Fix: Ensure proper backfilling of subscription metadata (i.e. dates and cache) to the postmeta table when HPOS is enabled and compatibility mode (data syncing) is turned on.
|
||||
* Fix: Fetch and update the `_cancelled_email_sent` meta in a HPOS compatibile way.
|
||||
* Dev: Introduce a new wcs_get_subscription_grouping_key() function to generate a unique key for a subscription based on its billing schedule. This function uses the existing recurring cart key concept.
|
||||
* Dev: Deprecate the WC_Subscriptions_Synchroniser::add_to_recurring_cart_key(). Use WC_Subscriptions_Synchroniser::add_to_recurring_product_grouping_key() instead.
|
||||
* Dev: Update subscriptions-core to 6.5.0.
|
||||
|
||||
2023-10-18 - version 5.6.0
|
||||
* Add: Introduce the "Subscription Relationship" column under the Orders list admin page when HPOS is enabled.
|
||||
* Add: Use admin theme color and the correct WooCommerce colors.
|
||||
* Fix: Resolved an issue that caused subscriptions to go on-hold when a customer fails or abandons an early renewal order payment.
|
||||
* Fix: Resolved an issue that caused subscriptions with an unpaid early renewal order to be incorrectly considered as needing payment.
|
||||
* Fix: When HPOS is enabled, make the orders_by_type_query filter box work in the WooCommerce orders screen.
|
||||
* Fix: Ensure renewal orders paid via the Block Checkout are correctly linked to their subscription.
|
||||
* Fix: Resolved an issue that caused paying for failed/pending parent orders that include Product Add-ons to not calculate the correct total.
|
||||
* Fix: Ensure the order needs processing transient is deleted when a subscription order (eg renewal) is created. Fixes issues with renewal orders going straight to a completed status.
|
||||
* Fix: Store the correct subscription start date in postmeta and ordermeta when HPOS and data syncing is being used.
|
||||
* Fix: When HPOS is enabled, deleting a customer will now delete their subscriptions.
|
||||
* Fix: Missing styles on the Edit Subscription page when HPOS is enabled.
|
||||
* Fix: Resolve an issue that would cause additional subscriptions to be created when completing a switch via the Block Checkout.
|
||||
* Fix: Resolve an issue that would cause 3rd party plugin edit product fields with the show_if_variable-subscription class to be incorrectly hidden.
|
||||
* Fix: Allow gateways to execute action on payment method deletion before updating the subscription.
|
||||
* Fix: Ensure subscriptions have a date created that correctly accounts for the site's timezone. Fixes issues with subscriptions having a date created double the site's UTC offset.
|
||||
* Fix: When HPOS is enabled, fix quick-editing the subscription statuses on the admin list table.
|
||||
* Dev: PHP 8.2: Fix "Creation of dynamic property" warnings.
|
||||
* Dev: PHP 8.2: Fix "Automatic conversion of false to array is deprecated" warnings.
|
||||
* Dev: PHP warnings from using debug_backtrace().
|
||||
* Dev: Updated subscriptions-core to 6.4.0
|
||||
* Dev: Updated the hooks for Checkout Blocks, replacing the deprecated `woocommerce_blocks_checkout_` prefixed hooks with `woocommerce_store_api_checkout`.
|
||||
|
||||
2023-09-21 - version 5.5.0
|
||||
* Tweak - Use admin theme color in selectors.
|
||||
* Tweak - Change plugin name to Woo Subscriptions.
|
||||
|
||||
2023-08-11 - version 5.4.0
|
||||
* Add: Introduce an updated empty state screen for the WooCommerce > Subscriptions list table.
|
||||
* Fix: Ensure subscription checkout and cart block integrations are loaded on store environments where WooPayments is not enabled.
|
||||
* Fix: Ensure the shipping phone number field is copied to subscriptions and their orders when copying address meta.
|
||||
* Update: When HPOS is disabled, fetch subscriptions by customer_id using the user's subscription cache to improve performance.
|
||||
* Dev: Deprecated the 'woocommerce_subscriptions_not_found_label' filter.
|
||||
* Dev: Updated subscriptions-core to 6.2.0
|
||||
|
||||
2023-07-26 - version 5.3.1
|
||||
* Fix: Resolved an issue that prevented the "Used for variations" checkbox to not be enabled on the edit product page load causing variations to be deleted erroneously.
|
||||
* Dev: Fixed wcs_get_subscription_orders() returning an empty list when querying parent orders when HPOS is enabled with data syncing off.
|
||||
* Dev: Use the WC_VERSION constant when determining the active WooCommerce version inside our dependency manager if it's defined.
|
||||
* Dev: Updated subscriptions-core to 6.1.0
|
||||
|
||||
2023-07-19 - version 5.3.0
|
||||
* Fix: Ensure when a customer changes the shipping method on cart and checkout that the recurring totals correctly reflect the chosen method.
|
||||
* Fix: Resolve an issue that prevented the "Used for variations" checkbox from being enabled on the variable subscription product edit screen on WC version v7.9.0.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
* WCS_Admin_Assets Class
|
||||
*
|
||||
* Handles admin assets (scripts and styles) for WooCommerce Subscriptions.
|
||||
*
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
*/
|
||||
class WCS_Admin_Assets {
|
||||
|
||||
/**
|
||||
* Initialize the tour handler
|
||||
*/
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue required scripts and styles
|
||||
*/
|
||||
public static function enqueue_scripts() {
|
||||
$script_asset_path = \WC_Subscriptions_Plugin::instance()->get_plugin_directory( 'build/admin.asset.php' );
|
||||
$script_asset = file_exists( $script_asset_path )
|
||||
? require $script_asset_path
|
||||
: array(
|
||||
'dependencies' => array(
|
||||
'react',
|
||||
'wc-blocks-checkout',
|
||||
'wc-price-format',
|
||||
'wc-settings',
|
||||
'wp-element',
|
||||
'wp-i18n',
|
||||
'wp-plugins',
|
||||
),
|
||||
'version' => WC_Subscriptions::$version,
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'wcs-admin',
|
||||
plugins_url( '/build/admin.js', WC_Subscriptions::$plugin_file ),
|
||||
$script_asset['dependencies'],
|
||||
$script_asset['version'],
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'wcs-admin',
|
||||
plugins_url( '/build/style-admin.css', WC_Subscriptions::$plugin_file ),
|
||||
array( 'wp-components' ),
|
||||
$script_asset['version']
|
||||
);
|
||||
|
||||
wp_set_script_translations(
|
||||
'wcs-admin',
|
||||
'woocommerce-subscriptions',
|
||||
plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'languages'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,10 +23,13 @@ class WCS_Admin_Reports {
|
|||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// The subscription reports are incompatible with stores running HPOS with sycning disabled.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() && ! wcs_is_custom_order_tables_data_sync_enabled() ) {
|
||||
add_action( 'admin_notices', [ __CLASS__, 'display_hpos_incompatibility_notice' ] );
|
||||
return;
|
||||
// The subscription reports are compatible with HPOS since 7.8.0.
|
||||
// We can inform users running data sync mode, that it's no longer needed.
|
||||
if (
|
||||
wcs_is_custom_order_tables_usage_enabled() &&
|
||||
wcs_is_custom_order_tables_data_sync_enabled()
|
||||
) {
|
||||
add_action( 'admin_notices', [ __CLASS__, 'display_hpos_compatibility_notice' ] );
|
||||
}
|
||||
|
||||
// Add the reports layout to the WooCommerce -> Reports admin section
|
||||
|
|
@ -37,12 +40,18 @@ class WCS_Admin_Reports {
|
|||
|
||||
// Add any actions we need based on the screen
|
||||
add_action( 'current_screen', __CLASS__ . '::conditional_reporting_includes' );
|
||||
|
||||
// Starting from WooCommerce 10.0 the dashboard widget is loaded asynchronously.
|
||||
// We also need to hook into AJAX request before WooCommerce so we can attach our hook to widget rendering flow.
|
||||
add_action( 'wp_ajax_woocommerce_load_status_widget', __CLASS__ . '::init_dashboard_report', 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an admin notice indicating subscription reports are disabled on HPOS environments with no syncing.
|
||||
* Displays an admin notice indicating subscription reports are compatible with HPOS.
|
||||
*
|
||||
* @since 7.8.0
|
||||
*/
|
||||
public static function display_hpos_incompatibility_notice() {
|
||||
public static function display_hpos_compatibility_notice() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
// Only display the admin notice on report admin screens.
|
||||
|
|
@ -50,28 +59,41 @@ class WCS_Admin_Reports {
|
|||
return;
|
||||
}
|
||||
|
||||
$admin_notice = new WCS_Admin_Notice( 'error' );
|
||||
$nonce_name = 'wcs_reports_hpos_compatibility_notice';
|
||||
$option_name = 'woocommerce_subscriptions_reports_hpos_compatibility_notice_dismissed';
|
||||
|
||||
$admin_notice->set_html_content(
|
||||
sprintf(
|
||||
'<p><strong>%s</strong></p><p>%s</p>',
|
||||
_x( 'WooCommerce Subscriptions - Reports Not Available', 'heading used in an admin notice', 'woocommerce-subscriptions' ),
|
||||
sprintf(
|
||||
// translators: placeholders $1 and $2 are opening <a> tags linking to the WooCommerce documentation on HPOS and data synchronization. Placeholder $3 is a closing link (<a>) tag.
|
||||
__( 'Subscription reports are incompatible with the %1$sWooCommerce data storage features%3$s enabled on your store. Please enable %2$stable synchronization%3$s if you wish to use subscription reports.', 'woocommerce-subscriptions' ),
|
||||
'<a href="https://woocommerce.com/document/high-performance-order-storage/">',
|
||||
'<a href="https://woocommerce.com/document/high-performance-order-storage/#section-4">',
|
||||
'</a>'
|
||||
)
|
||||
)
|
||||
$is_dismissed = get_option( $option_name );
|
||||
|
||||
if ( 'yes' === $is_dismissed ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['_wcsnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wcsnonce'] ) ), $nonce_name ) && ! empty( $_GET[ $nonce_name ] ) ) {
|
||||
update_option( $option_name, 'yes' );
|
||||
return;
|
||||
}
|
||||
|
||||
$dismiss_url = wp_nonce_url( add_query_arg( $nonce_name, '1' ), $nonce_name, '_wcsnonce' );
|
||||
|
||||
$admin_notice = new WCS_Admin_Notice( 'notice notice-info is-dismissible', array(), $dismiss_url );
|
||||
|
||||
$content = sprintf(
|
||||
// translators: placeholders $1 and $2 are opening <a> tags linking to the WooCommerce documentation on HPOS, and to the Advanced Features settings screen. Placeholder $3 is a closing link (</a>) tag.
|
||||
__( 'WooCommerce Subscriptions now supports %1$sHigh-Performance Order Storage (HPOS)%3$s - compatibility mode is no longer required to view subscriptions reports. You can disable compatibility mode in your %2$sstore settings%3$s.', 'woocommerce-subscriptions' ),
|
||||
'<a href="https://woocommerce.com/document/high-performance-order-storage/">',
|
||||
'<a href="' . esc_url( get_admin_url( null, 'admin.php?page=wc-settings&tab=advanced§ion=features' ) ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
$admin_notice->set_html_content( "<p>{$content}</p>" );
|
||||
|
||||
$admin_notice->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the 'Subscriptions' report type to the WooCommerce reports screen.
|
||||
*
|
||||
* @param array Array of Report types & their labels, excluding the Subscription product type.
|
||||
* @param array $reports Array of Report types & their labels, excluding the Subscription product type.
|
||||
* @return array Array of Report types & their labels, including the Subscription product type.
|
||||
* @since 2.1
|
||||
*/
|
||||
|
|
@ -169,12 +191,19 @@ class WCS_Admin_Reports {
|
|||
|
||||
$screen = get_current_screen();
|
||||
|
||||
switch ( $screen->id ) {
|
||||
case 'dashboard':
|
||||
new WCS_Report_Dashboard();
|
||||
break;
|
||||
// Before WooCommerce 10.0 the dashboard widget was loaded synchronously on the dashboard screen. Keep this for backward compatibility.
|
||||
if ( isset( $screen->id ) && 'dashboard' === $screen->id ) {
|
||||
self::init_dashboard_report();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the dashboard report.
|
||||
*
|
||||
* Used for loading the dashboard widget sync and async.
|
||||
*/
|
||||
public static function init_dashboard_report() {
|
||||
new WCS_Report_Dashboard();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,32 +252,4 @@ class WCS_Admin_Reports {
|
|||
WC_Tracks::record_event( $reports[ $name ], $properties );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If we hit one of our reports in the WC get_report function, change the path to our dir.
|
||||
*
|
||||
* @param string $report_path the parth to the report.
|
||||
* @param string $name the name of the report.
|
||||
* @param string $class the class of the report.
|
||||
*
|
||||
* @return string path to the report template.
|
||||
* @since 2.1
|
||||
* @deprecated in favor of autoloading
|
||||
* @access private
|
||||
*/
|
||||
public static function initialize_reports_path( $report_path, $name, $class ) {
|
||||
_deprecated_function( __METHOD__, '2.4.0' );
|
||||
if ( in_array( strtolower( $class ), array(
|
||||
'wc_report_subscription_events_by_date',
|
||||
'wc_report_upcoming_recurring_revenue',
|
||||
'wc_report_retention_rate',
|
||||
'wc_report_subscription_by_product',
|
||||
'wc_report_subscription_by_customer',
|
||||
'wc_report_subscription_payment_retry',
|
||||
) ) ) {
|
||||
$report_path = dirname( __FILE__ ) . '/reports/classwcsreport' . $name . '.php';
|
||||
}
|
||||
|
||||
return $report_path;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,10 +75,9 @@ class WCS_Report_Cache_Manager {
|
|||
/**
|
||||
* Attach callbacks to manage cache updates
|
||||
*
|
||||
* @since 2.1
|
||||
* @since 7.8.0 - Compatible with HPOS, originally introduced in 2.1
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Use the old hooks
|
||||
if ( wcs_is_woocommerce_pre( '3.0' ) ) {
|
||||
|
||||
|
|
@ -117,7 +116,7 @@ class WCS_Report_Cache_Manager {
|
|||
* This function is attached as a callback on the events in the $update_events_and_classes property.
|
||||
*
|
||||
* @since 2.1
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
public function set_reports_to_update() {
|
||||
if ( isset( $this->update_events_and_classes[ current_filter() ] ) ) {
|
||||
|
|
@ -141,37 +140,38 @@ class WCS_Report_Cache_Manager {
|
|||
*/
|
||||
public function schedule_cache_updates() {
|
||||
|
||||
if ( ! empty( $this->reports_to_update ) ) {
|
||||
if ( empty( $this->reports_to_update ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// On large sites, we want to run the cache update once at 4am in the site's timezone
|
||||
if ( $this->use_large_site_cache() ) {
|
||||
// On large sites, we want to run the cache update once at 4am in the site's timezone
|
||||
if ( $this->use_large_site_cache() ) {
|
||||
|
||||
$cache_update_timestamp = $this->get_large_site_cache_update_timestamp();
|
||||
$cache_update_timestamp = $this->get_large_site_cache_update_timestamp();
|
||||
|
||||
// Schedule one update event for each class to avoid updating cache more than once for the same class for different events
|
||||
foreach ( $this->reports_to_update as $index => $report_class ) {
|
||||
// Schedule one update event for each class to avoid updating cache more than once for the same class for different events
|
||||
foreach ( $this->reports_to_update as $index => $report_class ) {
|
||||
|
||||
$cron_args = array( 'report_class' => $report_class );
|
||||
$cron_args = array( 'report_class' => $report_class );
|
||||
|
||||
if ( false === as_next_scheduled_action( $this->cron_hook, $cron_args ) ) {
|
||||
// Use the index to space out caching of each report to make them 15 minutes apart so that on large sites, where we assume they'll get a request at least once every few minutes, we don't try to update the caches of all reports in the same request
|
||||
as_schedule_single_action( $cache_update_timestamp + 15 * MINUTE_IN_SECONDS * ( $index + 1 ), $this->cron_hook, $cron_args );
|
||||
}
|
||||
if ( false === as_next_scheduled_action( $this->cron_hook, $cron_args ) ) {
|
||||
// Use the index to space out caching of each report to make them 15 minutes apart so that on large sites, where we assume they'll get a request at least once every few minutes, we don't try to update the caches of all reports in the same request
|
||||
as_schedule_single_action( $cache_update_timestamp + 15 * MINUTE_IN_SECONDS * ( $index + 1 ), $this->cron_hook, $cron_args );
|
||||
}
|
||||
} else { // Otherwise, run it 10 minutes after the last cache invalidating event
|
||||
}
|
||||
} else { // Otherwise, run it 10 minutes after the last cache invalidating event
|
||||
|
||||
// Schedule one update event for each class to avoid updating cache more than once for the same class for different events
|
||||
foreach ( $this->reports_to_update as $index => $report_class ) {
|
||||
// Schedule one update event for each class to avoid updating cache more than once for the same class for different events
|
||||
foreach ( $this->reports_to_update as $index => $report_class ) {
|
||||
|
||||
$cron_args = array( 'report_class' => $report_class );
|
||||
$cron_args = array( 'report_class' => $report_class );
|
||||
|
||||
if ( false !== as_next_scheduled_action( $this->cron_hook, $cron_args ) ) {
|
||||
as_unschedule_action( $this->cron_hook, $cron_args );
|
||||
}
|
||||
|
||||
// Use the index to space out caching of each report to make them 5 minutes apart so that on large sites, where we assume they'll get a request at least once every few minutes, we don't try to update the caches of all reports in the same request
|
||||
as_schedule_single_action( gmdate( 'U' ) + MINUTE_IN_SECONDS * ( $index + 1 ) * 5, $this->cron_hook, $cron_args );
|
||||
if ( false !== as_next_scheduled_action( $this->cron_hook, $cron_args ) ) {
|
||||
as_unschedule_action( $this->cron_hook, $cron_args );
|
||||
}
|
||||
|
||||
// Use the index to space out caching of each report to make them 5 minutes apart so that on large sites, where we assume they'll get a request at least once every few minutes, we don't try to update the caches of all reports in the same request
|
||||
as_schedule_single_action( (int) gmdate( 'U' ) + MINUTE_IN_SECONDS * ( $index + 1 ) * 5, $this->cron_hook, $cron_args );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -180,7 +180,6 @@ class WCS_Report_Cache_Manager {
|
|||
* Update the cache data for a given report, as specified with $report_class, by call it's get_data() method.
|
||||
*
|
||||
* @since 2.1
|
||||
* @return null
|
||||
*/
|
||||
public function update_cache( $report_class ) {
|
||||
/**
|
||||
|
|
@ -212,7 +211,19 @@ class WCS_Report_Cache_Manager {
|
|||
|
||||
// Load report class dependencies
|
||||
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
||||
require_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php' );
|
||||
|
||||
$within_ci_environment = getenv( 'CI' );
|
||||
$wc_core_dir_from_env = getenv( 'WC_CORE_DIR' );
|
||||
|
||||
if ( $within_ci_environment && ! empty( $wc_core_dir_from_env ) ) {
|
||||
$wc_core_dir = $wc_core_dir_from_env;
|
||||
} elseif ( $within_ci_environment ) {
|
||||
$wc_core_dir = '/tmp/woocommerce';
|
||||
} else {
|
||||
$wc_core_dir = WC()->plugin_path();
|
||||
}
|
||||
|
||||
require_once( $wc_core_dir . '/includes/admin/reports/class-wc-admin-report.php' );
|
||||
|
||||
$reflector = new ReflectionMethod( $report_class, 'get_data' );
|
||||
|
||||
|
|
@ -321,7 +332,7 @@ class WCS_Report_Cache_Manager {
|
|||
'label' => 'Cache Update Failures',
|
||||
/* translators: %d refers to the number of times we have detected cache update failures */
|
||||
'note' => sprintf( _n( '%d failures', '%d failure', $failures, 'woocommerce-subscriptions' ), $failures ),
|
||||
'success' => 0 === $failures,
|
||||
'success' => 0 === (int)$failures,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,20 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
|
||||
class WCS_Report_Dashboard {
|
||||
/**
|
||||
* Tracks whether the cache should be updated after generating report data.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $should_update_cache = false;
|
||||
|
||||
/**
|
||||
* Cached report results for performance optimization.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $cached_report_results = array();
|
||||
|
||||
/**
|
||||
* Hook in additional reporting to WooCommerce dashboard widget
|
||||
|
|
@ -31,170 +45,35 @@ class WCS_Report_Dashboard {
|
|||
|
||||
/**
|
||||
* Get all data needed for this report and store in the class
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager to update the cache.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return object The report data.
|
||||
*/
|
||||
public static function get_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$default_args = array(
|
||||
'no_cache' => false,
|
||||
);
|
||||
|
||||
$args = apply_filters( 'wcs_reports_subscription_dashboard_args', $args );
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
$offset = get_option( 'gmt_offset' );
|
||||
$update_cache = false;
|
||||
$args = apply_filters( 'wcs_reports_subscription_dashboard_args', $args );
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
|
||||
// Use this once it is merged - wcs_get_gmt_offset_string();
|
||||
// Convert from Decimal format(eg. 11.5) to a suitable format(eg. +11:30) for CONVERT_TZ() of SQL query.
|
||||
$site_timezone = sprintf( '%+02d:%02d', (int) $offset, ( $offset - floor( $offset ) ) * 60 );
|
||||
self::init_cache();
|
||||
|
||||
$report_data = new stdClass;
|
||||
// Use current month as default date range.
|
||||
$start_date = $args['start_date'] ?? date( 'Y-m-01', current_time( 'timestamp' ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date,WordPress.DateTime.CurrentTimeTimestamp.Requested -- Keep default date values for backward compatibility.
|
||||
$end_date = $args['end_date'] ?? date( 'Y-m-d', strtotime( '+1 DAY', current_time( 'timestamp' ) ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date,WordPress.DateTime.CurrentTimeTimestamp.Requested -- Keep default date values for backward compatibility.
|
||||
|
||||
$cached_results = get_transient( strtolower( __CLASS__ ) );
|
||||
$report_data = new stdClass();
|
||||
$report_data->signup_count = self::fetch_signup_count( $start_date, $end_date, $args['no_cache'] );
|
||||
$report_data->signup_revenue = self::fetch_signup_revenue( $start_date, $end_date, $args['no_cache'] );
|
||||
$report_data->renewal_count = self::fetch_renewal_count( $start_date, $end_date, $args['no_cache'] );
|
||||
$report_data->renewal_revenue = self::fetch_renewal_revenue( $start_date, $end_date, $args['no_cache'] );
|
||||
$report_data->cancel_count = self::fetch_cancel_count( $start_date, $end_date, $args['no_cache'] );
|
||||
|
||||
// Subscription signups this month
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcsubs.ID) AS count
|
||||
FROM {$wpdb->posts} AS wcsubs
|
||||
INNER JOIN {$wpdb->posts} AS wcorder
|
||||
ON wcsubs.post_parent = wcorder.ID
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcsubs.post_type IN ( 'shop_subscription' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= '%s'
|
||||
AND wcorder.post_date < '%s'",
|
||||
date( 'Y-m-01', current_time( 'timestamp' ) ),
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', current_time( 'timestamp' ) ) )
|
||||
);
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_signup_query', $query ) );
|
||||
$update_cache = true;
|
||||
}
|
||||
|
||||
$report_data->signup_count = $cached_results[ $query_hash ];
|
||||
|
||||
// Signup revenue this month
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT SUM(order_total_meta.meta_value)
|
||||
FROM {$wpdb->postmeta} AS order_total_meta
|
||||
RIGHT JOIN
|
||||
(
|
||||
SELECT DISTINCT wcorder.ID
|
||||
FROM {$wpdb->posts} AS wcsubs
|
||||
INNER JOIN {$wpdb->posts} AS wcorder
|
||||
ON wcsubs.post_parent = wcorder.ID
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcsubs.post_type IN ( 'shop_subscription' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= '%s'
|
||||
AND wcorder.post_date < '%s'
|
||||
) AS orders ON orders.ID = order_total_meta.post_id
|
||||
WHERE order_total_meta.meta_key = '_order_total'",
|
||||
date( 'Y-m-01', current_time( 'timestamp' ) ),
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', current_time( 'timestamp' ) ) )
|
||||
);
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_signup_revenue_query', $query ) );
|
||||
$update_cache = true;
|
||||
}
|
||||
|
||||
$report_data->signup_revenue = $cached_results[ $query_hash ];
|
||||
|
||||
// Subscription renewals this month
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcorder.ID) AS count
|
||||
FROM {$wpdb->posts} AS wcorder
|
||||
INNER JOIN {$wpdb->postmeta} AS meta__subscription_renewal
|
||||
ON (
|
||||
wcorder.id = meta__subscription_renewal.post_id
|
||||
AND
|
||||
meta__subscription_renewal.meta_key = '_subscription_renewal'
|
||||
)
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= '%s'
|
||||
AND wcorder.post_date < '%s'",
|
||||
date( 'Y-m-01', current_time( 'timestamp' ) ),
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', current_time( 'timestamp' ) ) )
|
||||
);
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_renewal_query', $query ) );
|
||||
$update_cache = true;
|
||||
}
|
||||
|
||||
$report_data->renewal_count = $cached_results[ $query_hash ];
|
||||
|
||||
// Renewal revenue this month
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT SUM(order_total_meta.meta_value)
|
||||
FROM {$wpdb->postmeta} as order_total_meta
|
||||
RIGHT JOIN
|
||||
(
|
||||
SELECT DISTINCT wcorder.ID
|
||||
FROM {$wpdb->posts} AS wcorder
|
||||
INNER JOIN {$wpdb->postmeta} AS meta__subscription_renewal
|
||||
ON (
|
||||
wcorder.id = meta__subscription_renewal.post_id
|
||||
AND
|
||||
meta__subscription_renewal.meta_key = '_subscription_renewal'
|
||||
)
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= '%s'
|
||||
AND wcorder.post_date < '%s'
|
||||
) AS orders ON orders.ID = order_total_meta.post_id
|
||||
WHERE order_total_meta.meta_key = '_order_total'",
|
||||
date( 'Y-m-01', current_time( 'timestamp' ) ),
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', current_time( 'timestamp' ) ) )
|
||||
);
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_renewal_revenue_query', $query ) );
|
||||
$update_cache = true;
|
||||
}
|
||||
|
||||
$report_data->renewal_revenue = $cached_results[ $query_hash ];
|
||||
|
||||
// Cancellation count this month
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcsubs.ID) AS count
|
||||
FROM {$wpdb->posts} AS wcsubs
|
||||
JOIN {$wpdb->postmeta} AS wcsmeta_cancel
|
||||
ON wcsubs.ID = wcsmeta_cancel.post_id
|
||||
AND wcsmeta_cancel.meta_key = '_schedule_cancelled'
|
||||
AND wcsubs.post_status NOT IN ( 'trash', 'auto-draft' )
|
||||
AND CONVERT_TZ( wcsmeta_cancel.meta_value, '+00:00', '{$site_timezone}' ) BETWEEN '%s' AND '%s'",
|
||||
date( 'Y-m-01', current_time( 'timestamp' ) ),
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', current_time( 'timestamp' ) ) )
|
||||
);
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_cancellation_query', $query ) );
|
||||
$update_cache = true;
|
||||
}
|
||||
|
||||
$report_data->cancel_count = $cached_results[ $query_hash ];
|
||||
|
||||
if ( $update_cache ) {
|
||||
set_transient( strtolower( __CLASS__ ), $cached_results, HOUR_IN_SECONDS );
|
||||
if ( self::$should_update_cache ) {
|
||||
set_transient( strtolower( __CLASS__ ), self::$cached_report_results, HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $report_data;
|
||||
|
|
@ -245,11 +124,11 @@ class WCS_Report_Dashboard {
|
|||
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-reports&tab=subscriptions&report=subscription_events_by_date&range=month' ) ); ?>">
|
||||
<?php
|
||||
// translators: 1$: count, 2$ and 3$ are opening and closing strong tags, respectively.
|
||||
echo wp_kses_post( sprintf( _n( '%2$s%1$s cancellation%3$s subscription cancellations this month', '%2$s%1$s cancellations%3$s subscription cancellations this month', $report_data->cancel_count, 'woocommerce-subscriptions' ), $report_data->cancel_count, '<strong>', '</strong>' ) ); ?>
|
||||
echo wp_kses_post( sprintf( _n( '%2$s%1$s cancellation%3$s subscription cancellations this month', '%2$s%1$s cancellations%3$s subscription cancellations this month', $report_data->cancel_count, 'woocommerce-subscriptions' ), $report_data->cancel_count, '<strong>', '</strong>' ) );
|
||||
?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -264,9 +143,374 @@ class WCS_Report_Dashboard {
|
|||
/**
|
||||
* Clears the cached report data.
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager before updating the cache.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
public static function clear_cache() {
|
||||
delete_transient( strtolower( __CLASS__ ) );
|
||||
self::$should_update_cache = false;
|
||||
self::$cached_report_results = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the signup count for the dashboard.
|
||||
*
|
||||
* @param string $start_date The start date.
|
||||
* @param string $end_date The end date.
|
||||
* @param bool $force_cache_update Whether to force update the cache.
|
||||
* @return int The signup count.
|
||||
*/
|
||||
private static function fetch_signup_count( $start_date, $end_date, $force_cache_update = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcsubs.ID) AS count
|
||||
FROM {$wpdb->prefix}wc_orders AS wcsubs
|
||||
INNER JOIN {$wpdb->prefix}wc_orders AS wcorder
|
||||
ON wcsubs.parent_order_id = wcorder.ID
|
||||
WHERE wcorder.type IN ( 'shop_order' )
|
||||
AND wcsubs.type IN ( 'shop_subscription' )
|
||||
AND wcorder.status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.date_created_gmt >= %s
|
||||
AND wcorder.date_created_gmt < %s",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcsubs.ID) AS count
|
||||
FROM {$wpdb->posts} AS wcsubs
|
||||
INNER JOIN {$wpdb->posts} AS wcorder
|
||||
ON wcsubs.post_parent = wcorder.ID
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcsubs.post_type IN ( 'shop_subscription' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= %s
|
||||
AND wcorder.post_date < %s",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
}
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $force_cache_update || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
/**
|
||||
* Filter the query for the signup count.
|
||||
*
|
||||
* @param string $query The query to execute.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
$query = apply_filters( 'woocommerce_subscription_dashboard_status_widget_signup_query', $query );
|
||||
$query_results = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the signup revenue for the dashboard.
|
||||
*
|
||||
* @param string $start_date The start date.
|
||||
* @param string $end_date The end date.
|
||||
* @param bool $force_cache_update Whether to force update the cache.
|
||||
* @return float The signup revenue.
|
||||
*/
|
||||
private static function fetch_signup_revenue( $start_date, $end_date, $force_cache_update = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT SUM(parent_orders.total_amount)
|
||||
FROM {$wpdb->prefix}wc_orders AS subscripitons
|
||||
INNER JOIN {$wpdb->prefix}wc_orders AS parent_orders
|
||||
ON subscripitons.parent_order_id = parent_orders.ID
|
||||
WHERE parent_orders.type IN ( 'shop_order' )
|
||||
AND subscripitons.type IN ( 'shop_subscription' )
|
||||
AND parent_orders.status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND parent_orders.date_created_gmt >= %s
|
||||
AND parent_orders.date_created_gmt < %s
|
||||
",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT SUM(order_total_meta.meta_value)
|
||||
FROM {$wpdb->postmeta} AS order_total_meta
|
||||
RIGHT JOIN
|
||||
(
|
||||
SELECT DISTINCT wcorder.ID
|
||||
FROM {$wpdb->posts} AS wcsubs
|
||||
INNER JOIN {$wpdb->posts} AS wcorder
|
||||
ON wcsubs.post_parent = wcorder.ID
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcsubs.post_type IN ( 'shop_subscription' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= %s
|
||||
AND wcorder.post_date < %s
|
||||
) AS orders ON orders.ID = order_total_meta.post_id
|
||||
WHERE order_total_meta.meta_key = '_order_total'",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
}
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $force_cache_update || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
/**
|
||||
* Filter the query for the signup revenue.
|
||||
*
|
||||
* @param string $query The query to execute.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
$query = apply_filters( 'woocommerce_subscription_dashboard_status_widget_signup_revenue_query', $query );
|
||||
$query_results = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the renewal count for the dashboard.
|
||||
*
|
||||
* @param string $start_date The start date.
|
||||
* @param string $end_date The end date.
|
||||
* @param bool $force_cache_update Whether to force update the cache.
|
||||
* @return int The renewal count.
|
||||
*/
|
||||
private static function fetch_renewal_count( $start_date, $end_date, $force_cache_update = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcorder.ID) AS count
|
||||
FROM {$wpdb->prefix}wc_orders AS wcorder
|
||||
INNER JOIN {$wpdb->prefix}wc_orders_meta AS meta__subscription_renewal
|
||||
ON (
|
||||
wcorder.id = meta__subscription_renewal.order_id
|
||||
AND
|
||||
meta__subscription_renewal.meta_key = '_subscription_renewal'
|
||||
)
|
||||
WHERE wcorder.type IN ( 'shop_order' )
|
||||
AND wcorder.status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.date_created_gmt >= %s
|
||||
AND wcorder.date_created_gmt < %s",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcorder.ID) AS count
|
||||
FROM {$wpdb->posts} AS wcorder
|
||||
INNER JOIN {$wpdb->postmeta} AS meta__subscription_renewal
|
||||
ON (
|
||||
wcorder.id = meta__subscription_renewal.post_id
|
||||
AND
|
||||
meta__subscription_renewal.meta_key = '_subscription_renewal'
|
||||
)
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= %s
|
||||
AND wcorder.post_date < %s",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
}
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $force_cache_update || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
/**
|
||||
* Filter the query for the renewal count.
|
||||
*
|
||||
* @param string $query The query to execute.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
$query = apply_filters( 'woocommerce_subscription_dashboard_status_widget_renewal_query', $query );
|
||||
$query_results = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the renewal revenue for the dashboard.
|
||||
*
|
||||
* @param string $start_date The start date.
|
||||
* @param string $end_date The end date.
|
||||
* @param bool $force_cache_update Whether to force update the cache.
|
||||
* @return float The renewal revenue.
|
||||
*/
|
||||
private static function fetch_renewal_revenue( $start_date, $end_date, $force_cache_update = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT SUM(wcorder.total_amount)
|
||||
FROM {$wpdb->prefix}wc_orders AS wcorder
|
||||
INNER JOIN {$wpdb->prefix}wc_orders_meta AS meta__subscription_renewal
|
||||
ON (
|
||||
wcorder.id = meta__subscription_renewal.order_id
|
||||
AND
|
||||
meta__subscription_renewal.meta_key = '_subscription_renewal'
|
||||
)
|
||||
WHERE wcorder.type IN ( 'shop_order' )
|
||||
AND wcorder.status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.date_created_gmt >= %s
|
||||
AND wcorder.date_created_gmt < %s",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT SUM(order_total_meta.meta_value)
|
||||
FROM {$wpdb->postmeta} as order_total_meta
|
||||
RIGHT JOIN
|
||||
(
|
||||
SELECT DISTINCT wcorder.ID
|
||||
FROM {$wpdb->posts} AS wcorder
|
||||
INNER JOIN {$wpdb->postmeta} AS meta__subscription_renewal
|
||||
ON (
|
||||
wcorder.id = meta__subscription_renewal.post_id
|
||||
AND
|
||||
meta__subscription_renewal.meta_key = '_subscription_renewal'
|
||||
)
|
||||
WHERE wcorder.post_type IN ( 'shop_order' )
|
||||
AND wcorder.post_status IN ( 'wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded' )
|
||||
AND wcorder.post_date >= %s
|
||||
AND wcorder.post_date < %s
|
||||
) AS orders ON orders.ID = order_total_meta.post_id
|
||||
WHERE order_total_meta.meta_key = '_order_total'",
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
}
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $force_cache_update || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
/**
|
||||
* Filter the query for the renewal revenue.
|
||||
*
|
||||
* @param string $query The query to execute.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
$query = apply_filters( 'woocommerce_subscription_dashboard_status_widget_renewal_revenue_query', $query );
|
||||
$query_results = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cancellation count for the dashboard.
|
||||
*
|
||||
* @param string $start_date The start date.
|
||||
* @param string $end_date The end date.
|
||||
* @param bool $force_cache_update Whether to force update the cache.
|
||||
* @return int The cancellation count.
|
||||
*/
|
||||
private static function fetch_cancel_count( $start_date, $end_date, $force_cache_update = false ) {
|
||||
global $wpdb;
|
||||
|
||||
$offset = get_option( 'gmt_offset' );
|
||||
|
||||
// Use this once it is merged - wcs_get_gmt_offset_string();
|
||||
// Convert from Decimal format(eg. 11.5) to a suitable format(eg. +11:30) for CONVERT_TZ() of SQL query.
|
||||
$site_timezone = sprintf( '%+02d:%02d', (int) $offset, ( $offset - floor( $offset ) ) * 60 );
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcsubs.ID) AS count
|
||||
FROM {$wpdb->prefix}wc_orders AS wcsubs
|
||||
JOIN {$wpdb->prefix}wc_orders_meta AS wcsmeta_cancel
|
||||
ON wcsubs.ID = wcsmeta_cancel.order_id
|
||||
AND wcsmeta_cancel.meta_key = '_schedule_cancelled'
|
||||
AND wcsubs.status NOT IN ( 'trash', 'auto-draft' )
|
||||
AND CONVERT_TZ( wcsmeta_cancel.meta_value, '+00:00', %s ) BETWEEN %s AND %s",
|
||||
$site_timezone,
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT(DISTINCT wcsubs.ID) AS count
|
||||
FROM {$wpdb->posts} AS wcsubs
|
||||
JOIN {$wpdb->postmeta} AS wcsmeta_cancel
|
||||
ON wcsubs.ID = wcsmeta_cancel.post_id
|
||||
AND wcsmeta_cancel.meta_key = '_schedule_cancelled'
|
||||
AND wcsubs.post_status NOT IN ( 'trash', 'auto-draft' )
|
||||
AND CONVERT_TZ( wcsmeta_cancel.meta_value, '+00:00', %s ) BETWEEN %s AND %s",
|
||||
$site_timezone,
|
||||
$start_date,
|
||||
$end_date
|
||||
);
|
||||
}
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $force_cache_update || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
/**
|
||||
* Filter the query for the cancellation count.
|
||||
*
|
||||
* @param string $query The query to execute.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
$query = apply_filters( 'woocommerce_subscription_dashboard_status_widget_cancellation_query', $query );
|
||||
$query_results = $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize cache for report results.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function init_cache() {
|
||||
self::$should_update_cache = false;
|
||||
self::$cached_report_results = get_transient( strtolower( __CLASS__ ) );
|
||||
|
||||
// Set a default value for cached results for PHP 8.2+ compatibility.
|
||||
if ( empty( self::$cached_report_results ) ) {
|
||||
self::$cached_report_results = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache report results for performance optimization.
|
||||
*
|
||||
* @param string $query_hash The hash of the query for caching.
|
||||
* @param array $report_data The report data to cache.
|
||||
* @return void
|
||||
*/
|
||||
private static function cache_report_results( $query_hash, $report_data ) {
|
||||
self::$cached_report_results[ $query_hash ] = $report_data;
|
||||
self::$should_update_cache = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
* Get report data
|
||||
*
|
||||
* @since 2.1
|
||||
* @return array
|
||||
* @return stdClass
|
||||
*/
|
||||
public function get_report_data() {
|
||||
if ( empty( $this->report_data ) ) {
|
||||
|
|
@ -38,25 +38,13 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
* subscription may not have been active all of that time. Instead, it may have been on-hold for part of it.
|
||||
*
|
||||
* @since 2.1
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
private function query_report_data() {
|
||||
global $wpdb;
|
||||
|
||||
$this->report_data = new stdClass;
|
||||
|
||||
// First, let's find the age of the longest living subscription in days
|
||||
$oldest_subscription_age_in_days = $wpdb->get_var( $wpdb->prepare(
|
||||
"SELECT MAX(DATEDIFF(CAST(postmeta.meta_value AS DATETIME),posts.post_date_gmt)) as age_in_days
|
||||
FROM {$wpdb->prefix}posts posts
|
||||
LEFT JOIN {$wpdb->prefix}postmeta postmeta ON posts.ID = postmeta.post_id
|
||||
WHERE posts.post_type = 'shop_subscription'
|
||||
AND postmeta.meta_key = %s
|
||||
AND postmeta.meta_value <> '0'
|
||||
ORDER BY age_in_days DESC
|
||||
LIMIT 1",
|
||||
wcs_get_date_meta_key( 'end' )
|
||||
) );
|
||||
$oldest_subscription_age_in_days = $this->get_max_subscription_age_in_days();
|
||||
|
||||
// Now determine what interval to use based on that length
|
||||
if ( $oldest_subscription_age_in_days > 365 ) {
|
||||
|
|
@ -74,32 +62,12 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
$oldest_subscription_age = floor( $oldest_subscription_age_in_days / $days_in_interval_period );
|
||||
|
||||
// Now get all subscriptions, not just those that have ended, and find out how long they have lived (or if they haven't ended yet, consider them as being alive for one period longer than the longest living subsription)
|
||||
$base_query = $wpdb->prepare(
|
||||
"SELECT
|
||||
IF(COALESCE(cancelled_date.meta_value,end_date.meta_value) <> '0',CEIL(DATEDIFF(CAST(COALESCE(cancelled_date.meta_value,end_date.meta_value) AS DATETIME),posts.post_date_gmt)/%d),%d) as periods_active,
|
||||
COUNT(posts.ID) as count
|
||||
FROM {$wpdb->prefix}posts posts
|
||||
LEFT JOIN {$wpdb->prefix}postmeta cancelled_date
|
||||
ON posts.ID = cancelled_date.post_id
|
||||
AND cancelled_date.meta_key = %s
|
||||
AND cancelled_date.meta_value <> '0'
|
||||
LEFT JOIN {$wpdb->prefix}postmeta end_date
|
||||
ON posts.ID = end_date.post_id
|
||||
AND end_date.meta_key = %s
|
||||
WHERE posts.post_type = 'shop_subscription'
|
||||
AND posts.post_status NOT IN( 'wc-pending', 'trash' )
|
||||
GROUP BY periods_active
|
||||
ORDER BY periods_active ASC",
|
||||
$days_in_interval_period,
|
||||
( $oldest_subscription_age + 1 ), // Consider living subscriptions as being alive for one period longer than the longest living subsription
|
||||
wcs_get_date_meta_key( 'cancelled' ), // If a subscription has a cancelled date, use that to determine a more accurate lifetime
|
||||
wcs_get_date_meta_key( 'end' ) // Otherwise, we want to use the end date for subscritions that have expired
|
||||
);
|
||||
$subscription_ages = $this->fetch_subscriptions_ages( $days_in_interval_period, $oldest_subscription_age );
|
||||
|
||||
$subscription_ages = $wpdb->get_results( $base_query, OBJECT_K );
|
||||
|
||||
$this->report_data->total_subscriptions = $this->report_data->unended_subscriptions = absint( array_sum( wp_list_pluck( $subscription_ages, 'count' ) ) );
|
||||
$this->report_data->living_subscriptions = array();
|
||||
// Set initial values for the report data.
|
||||
$this->report_data->total_subscriptions = absint( array_sum( wp_list_pluck( $subscription_ages, 'count' ) ) );
|
||||
$this->report_data->unended_subscriptions = $this->report_data->total_subscriptions;
|
||||
$this->report_data->living_subscriptions = array();
|
||||
|
||||
// At day zero, no subscriptions have ended
|
||||
$this->report_data->living_subscriptions[0] = $this->report_data->total_subscriptions;
|
||||
|
|
@ -120,13 +88,113 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the age of the longest living subscription in days.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function get_max_subscription_age_in_days() {
|
||||
global $wpdb;
|
||||
|
||||
$end_date_meta_key = wcs_get_date_meta_key( 'end' );
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT MAX(DATEDIFF(CAST(meta.meta_value AS DATETIME),orders.date_created_gmt)) as age_in_days
|
||||
FROM {$wpdb->prefix}wc_orders orders
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta meta ON orders.ID = meta.order_id
|
||||
WHERE orders.type = 'shop_subscription'
|
||||
AND meta.meta_key = %s
|
||||
AND meta.meta_value <> '0'
|
||||
ORDER BY age_in_days DESC
|
||||
LIMIT 1",
|
||||
$end_date_meta_key
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT MAX(DATEDIFF(CAST(postmeta.meta_value AS DATETIME),posts.post_date_gmt)) as age_in_days
|
||||
FROM {$wpdb->prefix}posts posts
|
||||
LEFT JOIN {$wpdb->prefix}postmeta postmeta ON posts.ID = postmeta.post_id
|
||||
WHERE posts.post_type = 'shop_subscription'
|
||||
AND postmeta.meta_key = %s
|
||||
AND postmeta.meta_value <> '0'
|
||||
ORDER BY age_in_days DESC
|
||||
LIMIT 1",
|
||||
$end_date_meta_key
|
||||
);
|
||||
}
|
||||
|
||||
return $wpdb->get_var( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- The query is prepared above.
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the number of periods each subscription has between creating and ending.
|
||||
*
|
||||
* @param int $days_in_interval_period
|
||||
* @param int $oldest_subscription_age
|
||||
* @return array
|
||||
*/
|
||||
private function fetch_subscriptions_ages( $days_in_interval_period, $oldest_subscription_age ) {
|
||||
global $wpdb;
|
||||
|
||||
$end_date_meta_key = wcs_get_date_meta_key( 'end' );
|
||||
$cancelled_date_meta_key = wcs_get_date_meta_key( 'cancelled' );
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT
|
||||
IF(COALESCE(cancelled_date.meta_value,end_date.meta_value) <> '0',CEIL(DATEDIFF(CAST(COALESCE(cancelled_date.meta_value,end_date.meta_value) AS DATETIME),orders.date_created_gmt)/%d),%d) as periods_active,
|
||||
COUNT(orders.ID) as count
|
||||
FROM {$wpdb->prefix}wc_orders orders
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta cancelled_date
|
||||
ON orders.ID = cancelled_date.order_id
|
||||
AND cancelled_date.meta_key = %s
|
||||
AND cancelled_date.meta_value <> '0'
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta end_date
|
||||
ON orders.ID = end_date.order_id
|
||||
AND end_date.meta_key = %s
|
||||
WHERE orders.type = 'shop_subscription'
|
||||
AND orders.status NOT IN( 'wc-pending', 'trash' )
|
||||
GROUP BY periods_active
|
||||
ORDER BY periods_active ASC",
|
||||
$days_in_interval_period,
|
||||
( $oldest_subscription_age + 1 ), // Consider living subscriptions as being alive for one period longer than the longest living subscription
|
||||
$cancelled_date_meta_key, // If a subscription has a cancelled date, use that to determine a more accurate lifetime
|
||||
$end_date_meta_key // Otherwise, we want to use the end date for subscriptions that have expired
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT
|
||||
IF(COALESCE(cancelled_date.meta_value,end_date.meta_value) <> '0',CEIL(DATEDIFF(CAST(COALESCE(cancelled_date.meta_value,end_date.meta_value) AS DATETIME),posts.post_date_gmt)/%d),%d) as periods_active,
|
||||
COUNT(posts.ID) as count
|
||||
FROM {$wpdb->prefix}posts posts
|
||||
LEFT JOIN {$wpdb->prefix}postmeta cancelled_date
|
||||
ON posts.ID = cancelled_date.post_id
|
||||
AND cancelled_date.meta_key = %s
|
||||
AND cancelled_date.meta_value <> '0'
|
||||
LEFT JOIN {$wpdb->prefix}postmeta end_date
|
||||
ON posts.ID = end_date.post_id
|
||||
AND end_date.meta_key = %s
|
||||
WHERE posts.post_type = 'shop_subscription'
|
||||
AND posts.post_status NOT IN( 'wc-pending', 'trash' )
|
||||
GROUP BY periods_active
|
||||
ORDER BY periods_active ASC",
|
||||
$days_in_interval_period,
|
||||
( $oldest_subscription_age + 1 ), // Consider living subscriptions as being alive for one period longer than the longest living subscription
|
||||
$cancelled_date_meta_key, // If a subscription has a cancelled date, use that to determine a more accurate lifetime
|
||||
$end_date_meta_key // Otherwise, we want to use the end date for subscriptions that have expired
|
||||
);
|
||||
}
|
||||
|
||||
return $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- The query is prepared above.
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report
|
||||
*
|
||||
* Use a custom report as we don't need the date filters provided by the WooCommerce html-report-by-date.php template.
|
||||
*
|
||||
* @since 2.1
|
||||
* @return null
|
||||
*/
|
||||
public function output_report() {
|
||||
include( WC_Subscriptions_Plugin::instance()->get_plugin_directory( 'includes/admin/views/html-report-by-period.php' ) );
|
||||
|
|
@ -136,7 +204,6 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
* Output the HTML and JavaScript to plot the chart
|
||||
*
|
||||
* @since 2.1
|
||||
* @return null
|
||||
*/
|
||||
public function get_main_chart() {
|
||||
|
||||
|
|
@ -151,6 +218,8 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
);
|
||||
}
|
||||
|
||||
$x_axes_label = '';
|
||||
|
||||
switch ( $this->report_data->interval_period ) {
|
||||
case 'day':
|
||||
$x_axes_label = _x( 'Number of days after sign-up', 'X axis label on retention rate graph', 'woocommerce-subscriptions' );
|
||||
|
|
@ -212,7 +281,7 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
|
|||
color: '#aaa',
|
||||
position: "bottom",
|
||||
tickDecimals: 0,
|
||||
axisLabel: "<?php echo esc_js( $x_axes_label ); ?>",
|
||||
axisLabel: "<?php esc_js( $x_axes_label ); ?>",
|
||||
axisLabelPadding: 18,
|
||||
font: {
|
||||
color: "#aaa"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@
|
|||
* @since 2.1
|
||||
*/
|
||||
class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
||||
/**
|
||||
* Cached report results.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $cached_report_results = array();
|
||||
|
||||
private $totals;
|
||||
|
||||
|
|
@ -25,6 +31,15 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
|||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the totals.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function get_totals() {
|
||||
return $this->totals;
|
||||
}
|
||||
|
||||
/**
|
||||
* No subscription products found text.
|
||||
*/
|
||||
|
|
@ -112,8 +127,6 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
|||
* Prepare subscription list items.
|
||||
*/
|
||||
public function prepare_items() {
|
||||
global $wpdb;
|
||||
|
||||
$this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
|
||||
$current_page = absint( $this->get_pagenum() );
|
||||
$per_page = absint( apply_filters( 'wcs_reports_customers_per_page', 20 ) );
|
||||
|
|
@ -121,105 +134,157 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
|||
|
||||
$this->totals = self::get_data();
|
||||
|
||||
$customer_query = apply_filters( 'wcs_reports_current_customer_query',
|
||||
"SELECT customer_ids.meta_value as customer_id,
|
||||
COUNT(subscription_posts.ID) as total_subscriptions,
|
||||
COALESCE( SUM(parent_total.meta_value), 0) as initial_order_total,
|
||||
COUNT(DISTINCT parent_order.ID) as initial_order_count,
|
||||
SUM(CASE
|
||||
WHEN subscription_posts.post_status
|
||||
IN ( 'wc-" . implode( "','wc-", apply_filters( 'wcs_reports_active_statuses', array( 'active', 'pending-cancel' ) ) ) . "' ) THEN 1
|
||||
ELSE 0
|
||||
END) AS active_subscriptions
|
||||
FROM {$wpdb->posts} subscription_posts
|
||||
INNER JOIN {$wpdb->postmeta} customer_ids
|
||||
ON customer_ids.post_id = subscription_posts.ID
|
||||
AND customer_ids.meta_key = '_customer_user'
|
||||
LEFT JOIN {$wpdb->posts} parent_order
|
||||
ON parent_order.ID = subscription_posts.post_parent
|
||||
AND parent_order.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_paid_order_statuses', array( 'completed', 'processing' ) ) ) . "' )
|
||||
LEFT JOIN {$wpdb->postmeta} parent_total
|
||||
ON parent_total.post_id = parent_order.ID
|
||||
AND parent_total.meta_key = '_order_total'
|
||||
WHERE subscription_posts.post_type = 'shop_subscription'
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'trash')
|
||||
GROUP BY customer_ids.meta_value
|
||||
ORDER BY customer_id DESC
|
||||
LIMIT {$offset}, {$per_page}" );
|
||||
|
||||
$this->items = $wpdb->get_results( $customer_query );
|
||||
|
||||
// Now get each customer's renewal and switch total
|
||||
$customer_renewal_switch_total_query = apply_filters( 'wcs_reports_current_customer_renewal_switch_total_query',
|
||||
"SELECT
|
||||
customer_ids.meta_value as customer_id,
|
||||
COALESCE( SUM(renewal_switch_totals.meta_value), 0) as renewal_switch_total,
|
||||
COUNT(DISTINCT renewal_order_posts.ID) as renewal_switch_count
|
||||
FROM {$wpdb->postmeta} renewal_order_ids
|
||||
INNER JOIN {$wpdb->posts} subscription_posts
|
||||
ON renewal_order_ids.meta_value = subscription_posts.ID
|
||||
AND subscription_posts.post_type = 'shop_subscription'
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'trash')
|
||||
INNER JOIN {$wpdb->postmeta} customer_ids
|
||||
ON renewal_order_ids.meta_value = customer_ids.post_id
|
||||
AND customer_ids.meta_key = '_customer_user'
|
||||
AND customer_ids.meta_value IN ('" . implode( "','", wp_list_pluck( $this->items, 'customer_id' ) ) . "' )
|
||||
INNER JOIN {$wpdb->posts} renewal_order_posts
|
||||
ON renewal_order_ids.post_id = renewal_order_posts.ID
|
||||
AND renewal_order_posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_paid_order_statuses', array( 'completed', 'processing' ) ) ) . "' )
|
||||
LEFT JOIN {$wpdb->postmeta} renewal_switch_totals
|
||||
ON renewal_switch_totals.post_id = renewal_order_ids.post_id
|
||||
AND renewal_switch_totals.meta_key = '_order_total'
|
||||
WHERE renewal_order_ids.meta_key = '_subscription_renewal'
|
||||
OR renewal_order_ids.meta_key = '_subscription_switch'
|
||||
GROUP BY customer_id
|
||||
ORDER BY customer_id"
|
||||
$active_statuses = wcs_maybe_prefix_key( apply_filters( 'wcs_reports_active_statuses', [ 'active', 'pending-cancel' ] ), 'wc-' );
|
||||
$paid_statuses = wcs_maybe_prefix_key( apply_filters( 'woocommerce_reports_paid_order_statuses', [ 'completed', 'processing' ] ), 'wc-' );
|
||||
$query_options = array(
|
||||
'active_statuses' => $active_statuses,
|
||||
'paid_statuses' => $paid_statuses,
|
||||
'offset' => $offset,
|
||||
'per_page' => $per_page,
|
||||
);
|
||||
|
||||
$customer_renewal_switch_totals = $wpdb->get_results( $customer_renewal_switch_total_query, OBJECT_K );
|
||||
$this->items = self::fetch_subscriptions_by_customer( $query_options );
|
||||
$customer_ids = wp_list_pluck( $this->items, 'customer_id' );
|
||||
|
||||
$related_orders_query_options = array(
|
||||
'order_status' => $paid_statuses,
|
||||
'customer_ids' => $customer_ids,
|
||||
);
|
||||
|
||||
$related_orders_totals_by_customer = self::fetch_subscriptions_related_orders_totals_by_customer( $related_orders_query_options );
|
||||
|
||||
foreach ( $this->items as $index => $item ) {
|
||||
if ( isset( $customer_renewal_switch_totals[ $item->customer_id ] ) ) {
|
||||
$this->items[ $index ]->renewal_switch_total = $customer_renewal_switch_totals[ $item->customer_id ]->renewal_switch_total;
|
||||
$this->items[ $index ]->renewal_switch_count = $customer_renewal_switch_totals[ $item->customer_id ]->renewal_switch_count;
|
||||
if ( isset( $related_orders_totals_by_customer[ $item->customer_id ] ) ) {
|
||||
$this->items[ $index ]->renewal_switch_total = $related_orders_totals_by_customer[ $item->customer_id ]->renewal_switch_total;
|
||||
$this->items[ $index ]->renewal_switch_count = $related_orders_totals_by_customer[ $item->customer_id ]->renewal_switch_count;
|
||||
} else {
|
||||
$this->items[ $index ]->renewal_switch_total = $this->items[ $index ]->renewal_switch_count = 0;
|
||||
$this->items[ $index ]->renewal_switch_total = 0;
|
||||
$this->items[ $index ]->renewal_switch_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pagination.
|
||||
*/
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $this->totals->total_customers,
|
||||
'per_page' => $per_page,
|
||||
'total_pages' => ceil( $this->totals->total_customers / $per_page ),
|
||||
) );
|
||||
|
||||
$this->set_pagination_args(
|
||||
array(
|
||||
'total_items' => $this->totals->total_customers,
|
||||
'per_page' => $per_page,
|
||||
'total_pages' => ceil( $this->totals->total_customers / $per_page ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather totals for customers
|
||||
*/
|
||||
* Gather totals for customers.
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager to update the cache.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return object The totals for customers.
|
||||
*/
|
||||
public static function get_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$default_args = array(
|
||||
'no_cache' => false,
|
||||
/**
|
||||
* Filter the order statuses considered as "paid" for the report.
|
||||
*
|
||||
* @param array $order_statuses The default paid order statuses: completed, processing.
|
||||
* @return array The filtered order statuses.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
'order_status' => apply_filters( 'woocommerce_reports_paid_order_statuses', array( 'completed', 'processing' ) ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the arguments for the totals of subscriptions by customer report.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return array The filtered arguments.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$args = apply_filters( 'wcs_reports_customer_total_args', $args );
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
|
||||
$total_query = apply_filters( 'wcs_reports_customer_total_query',
|
||||
"SELECT COUNT( DISTINCT customer_ids.meta_value) as total_customers,
|
||||
self::init_cache();
|
||||
$subscriptions_totals = self::fetch_customer_subscription_totals( $args );
|
||||
$related_orders_totals = self::fetch_customer_subscription_related_orders_totals( $args );
|
||||
|
||||
$subscriptions_totals->renewal_switch_total = $related_orders_totals->renewal_switch_total;
|
||||
$subscriptions_totals->renewal_switch_count = $related_orders_totals->renewal_switch_count;
|
||||
|
||||
return $subscriptions_totals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cached report data.
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager before updating the cache.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
public static function clear_cache() {
|
||||
delete_transient( strtolower( __CLASS__ ) );
|
||||
self::$cached_report_results = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch totals by customer for subscriptions.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return object The totals by customer for subscriptions.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public static function fetch_customer_subscription_totals( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
/**
|
||||
* Filter the active subscription statuses used for reporting.
|
||||
*
|
||||
* @param array $active_statuses The default active subscription statuses: active, pending-cancel.
|
||||
* @return array The filtered active statuses.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$active_statuses = wcs_maybe_prefix_key( apply_filters( 'wcs_reports_active_statuses', [ 'active', 'pending-cancel' ] ), 'wc-' );
|
||||
$order_statuses = wcs_maybe_prefix_key( $args['order_status'], 'wc-' );
|
||||
|
||||
$active_statuses_placeholders = implode( ',', array_fill( 0, count( $active_statuses ), '%s' ) );
|
||||
$order_statuses_placeholders = implode( ',', array_fill( 0, count( $order_statuses ), '%s' ) );
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Ignored for allowing interpolation in the IN statements.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT( DISTINCT subscriptions.customer_id) as total_customers,
|
||||
COUNT(subscriptions.ID) as total_subscriptions,
|
||||
COALESCE( SUM(parent_orders.total_amount), 0) as initial_order_total,
|
||||
COUNT(DISTINCT parent_orders.ID) as initial_order_count,
|
||||
COALESCE(SUM(CASE
|
||||
WHEN subscriptions.status
|
||||
IN ( {$active_statuses_placeholders} ) THEN 1
|
||||
ELSE 0
|
||||
END), 0) AS active_subscriptions
|
||||
FROM {$wpdb->prefix}wc_orders subscriptions
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders parent_orders
|
||||
ON parent_orders.ID = subscriptions.parent_order_id
|
||||
AND parent_orders.status IN ( {$order_statuses_placeholders} )
|
||||
WHERE subscriptions.type = 'shop_subscription'
|
||||
AND subscriptions.status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
", // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders are prepared above.
|
||||
array_merge( $active_statuses, $order_statuses )
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COUNT( DISTINCT customer_ids.meta_value) as total_customers,
|
||||
COUNT(subscription_posts.ID) as total_subscriptions,
|
||||
COALESCE( SUM(parent_total.meta_value), 0) as initial_order_total,
|
||||
COUNT(DISTINCT parent_order.ID) as initial_order_count,
|
||||
COALESCE(SUM(CASE
|
||||
WHEN subscription_posts.post_status
|
||||
IN ( 'wc-" . implode( "','wc-", apply_filters( 'wcs_reports_active_statuses', array( 'active', 'pending-cancel' ) ) ) . "' ) THEN 1
|
||||
IN ( {$active_statuses_placeholders} ) THEN 1
|
||||
ELSE 0
|
||||
END), 0) AS active_subscriptions
|
||||
FROM {$wpdb->posts} subscription_posts
|
||||
|
|
@ -228,65 +293,330 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
|||
AND customer_ids.meta_key = '_customer_user'
|
||||
LEFT JOIN {$wpdb->posts} parent_order
|
||||
ON parent_order.ID = subscription_posts.post_parent
|
||||
AND parent_order.post_status IN ( 'wc-" . implode( "','wc-", $args['order_status'] ) . "' )
|
||||
AND parent_order.post_status IN ( {$order_statuses_placeholders} )
|
||||
LEFT JOIN {$wpdb->postmeta} parent_total
|
||||
ON parent_total.post_id = parent_order.ID
|
||||
AND parent_total.meta_key = '_order_total'
|
||||
WHERE subscription_posts.post_type = 'shop_subscription'
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'trash')
|
||||
");
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
", // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders are prepared above.
|
||||
array_merge( $active_statuses, $order_statuses )
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared.
|
||||
|
||||
$cached_results = get_transient( strtolower( __CLASS__ ) );
|
||||
$query_hash = md5( $total_query );
|
||||
/**
|
||||
* Filter the query used to fetch the customer subscription totals.
|
||||
*
|
||||
* @param string $query The query to fetch the customer subscription totals.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query = apply_filters( 'wcs_reports_customer_total_query', $query );
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
// Enable big selects for reports
|
||||
// We expect that cache was initialized before calling this method.
|
||||
// Skip running the query if cache is available.
|
||||
if ( $args['no_cache'] || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = apply_filters( 'wcs_reports_customer_total_data', $wpdb->get_row( $total_query ) );
|
||||
set_transient( strtolower( __CLASS__ ), $cached_results, WEEK_IN_SECONDS );
|
||||
$query_results = $wpdb->get_row( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
|
||||
/**
|
||||
* Filter the query results for customer totals.
|
||||
*
|
||||
* @param object $query_results The query results.
|
||||
* @return object The filtered query results.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query_results = apply_filters( 'wcs_reports_customer_total_data', $query_results );
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
$customer_totals = $cached_results[ $query_hash ];
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
$renewal_switch_total_query = apply_filters( 'wcs_reports_customer_total_renewal_switch_query',
|
||||
"SELECT COALESCE( SUM(renewal_switch_totals.meta_value), 0) as renewal_switch_total,
|
||||
COUNT(DISTINCT renewal_order_posts.ID) as renewal_switch_count
|
||||
/**
|
||||
* Fetch totals by customer for related renewal and switch orders.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return object The totals by customer for related renewal and switch orders.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public static function fetch_customer_subscription_related_orders_totals( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$status_placeholders = implode( ',', array_fill( 0, count( $args['order_status'] ), '%s' ) );
|
||||
$statuses = wcs_maybe_prefix_key( $args['order_status'], 'wc-' );
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Ignored for allowing interpolation in the IN statements.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COALESCE( SUM(renewal_orders.total_amount), 0) as renewal_switch_total,
|
||||
COUNT(DISTINCT renewal_orders.ID) as renewal_switch_count
|
||||
FROM {$wpdb->prefix}wc_orders_meta renewal_order_ids
|
||||
INNER JOIN {$wpdb->prefix}wc_orders subscriptions
|
||||
ON renewal_order_ids.meta_value = subscriptions.ID
|
||||
AND subscriptions.type = 'shop_subscription'
|
||||
AND subscriptions.status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
INNER JOIN {$wpdb->prefix}wc_orders renewal_orders
|
||||
ON renewal_order_ids.order_id = renewal_orders.ID
|
||||
AND renewal_orders.status IN ( {$status_placeholders} )
|
||||
WHERE renewal_order_ids.meta_key = '_subscription_renewal'
|
||||
OR renewal_order_ids.meta_key = '_subscription_switch'
|
||||
", // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders are prepared above.
|
||||
$statuses
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT COALESCE( SUM(renewal_switch_totals.meta_value), 0) as renewal_switch_total,
|
||||
COUNT(DISTINCT renewal_order_posts.ID) as renewal_switch_count
|
||||
FROM {$wpdb->postmeta} renewal_order_ids
|
||||
INNER JOIN {$wpdb->posts} subscription_posts
|
||||
ON renewal_order_ids.meta_value = subscription_posts.ID
|
||||
AND subscription_posts.post_type = 'shop_subscription'
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'trash')
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
INNER JOIN {$wpdb->posts} renewal_order_posts
|
||||
ON renewal_order_ids.post_id = renewal_order_posts.ID
|
||||
AND renewal_order_posts.post_status IN ( 'wc-" . implode( "','wc-", $args['order_status'] ) . "' )
|
||||
AND renewal_order_posts.post_status IN ( {$status_placeholders} )
|
||||
LEFT JOIN {$wpdb->postmeta} renewal_switch_totals
|
||||
ON renewal_switch_totals.post_id = renewal_order_ids.post_id
|
||||
AND renewal_switch_totals.meta_key = '_order_total'
|
||||
WHERE renewal_order_ids.meta_key = '_subscription_renewal'
|
||||
OR renewal_order_ids.meta_key = '_subscription_switch'"
|
||||
);
|
||||
WHERE renewal_order_ids.meta_key = '_subscription_renewal'
|
||||
OR renewal_order_ids.meta_key = '_subscription_switch'
|
||||
", // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Placeholders are prepared above.
|
||||
$statuses
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared.
|
||||
|
||||
$query_hash = md5( $renewal_switch_total_query );
|
||||
/**
|
||||
* Filter the query used to fetch the customer subscription related orders totals.
|
||||
*
|
||||
* @param string $query The query to fetch the customer subscription related orders totals.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query = apply_filters( 'wcs_reports_customer_total_renewal_switch_query', $query );
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
if ( $args['no_cache'] || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
// Enable big selects for reports
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = apply_filters( 'wcs_reports_customer_total_renewal_switch_data', $wpdb->get_row( $renewal_switch_total_query ) );
|
||||
set_transient( strtolower( __CLASS__ ), $cached_results, WEEK_IN_SECONDS );
|
||||
$query_results = $wpdb->get_row( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
|
||||
/**
|
||||
* Filter the query results for customer subscription related orders totals.
|
||||
*
|
||||
* @param object $query_results The query results.
|
||||
* @return object The filtered query results.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query_results = apply_filters( 'wcs_reports_customer_total_renewal_switch_data', $query_results );
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
$customer_totals->renewal_switch_total = $cached_results[ $query_hash ]->renewal_switch_total;
|
||||
$customer_totals->renewal_switch_count = $cached_results[ $query_hash ]->renewal_switch_count;
|
||||
|
||||
return $customer_totals;
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cached report data.
|
||||
* Fetch subscriptions by customer.
|
||||
*
|
||||
* @since 3.0.10
|
||||
* @param array $query_options The query options.
|
||||
* @return array The subscriptions by customer.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public static function clear_cache() {
|
||||
delete_transient( strtolower( __CLASS__ ) );
|
||||
private static function fetch_subscriptions_by_customer( $query_options = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$active_statuses = $query_options['active_statuses'] ?? array();
|
||||
$paid_statuses = $query_options['paid_statuses'] ?? array();
|
||||
$offset = $query_options['offset'] ?? 0;
|
||||
$per_page = $query_options['per_page'] ?? 20;
|
||||
|
||||
$active_statuses_placeholders = implode( ',', array_fill( 0, count( $active_statuses ), '%s' ) );
|
||||
$paid_statuses_placeholders = implode( ',', array_fill( 0, count( $paid_statuses ), '%s' ) );
|
||||
|
||||
// Ignored for allowing interpolation in the IN statements.
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT subscriptions.customer_id as customer_id,
|
||||
COUNT(subscriptions.ID) as total_subscriptions,
|
||||
COALESCE( SUM(parent_order.total_amount), 0) as initial_order_total,
|
||||
COUNT(DISTINCT parent_order.ID) as initial_order_count,
|
||||
SUM(CASE
|
||||
WHEN subscriptions.status
|
||||
IN ( {$active_statuses_placeholders} ) THEN 1
|
||||
ELSE 0
|
||||
END) AS active_subscriptions
|
||||
FROM {$wpdb->prefix}wc_orders subscriptions
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders parent_order
|
||||
ON parent_order.ID = subscriptions.parent_order_id
|
||||
AND parent_order.status IN ( {$paid_statuses_placeholders} )
|
||||
WHERE subscriptions.type = 'shop_subscription'
|
||||
AND subscriptions.status NOT IN ('wc-pending','auto-draft', 'wc-checkout-draft', 'trash')
|
||||
GROUP BY subscriptions.customer_id
|
||||
ORDER BY customer_id DESC
|
||||
LIMIT %d, %d
|
||||
",
|
||||
array_merge( $active_statuses, $paid_statuses, array( $offset, $per_page ) )
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT customer_ids.meta_value as customer_id,
|
||||
COUNT(subscription_posts.ID) as total_subscriptions,
|
||||
COALESCE( SUM(parent_total.meta_value), 0) as initial_order_total,
|
||||
COUNT(DISTINCT parent_order.ID) as initial_order_count,
|
||||
SUM(CASE
|
||||
WHEN subscription_posts.post_status
|
||||
IN ( {$active_statuses_placeholders} ) THEN 1
|
||||
ELSE 0
|
||||
END) AS active_subscriptions
|
||||
FROM {$wpdb->posts} subscription_posts
|
||||
INNER JOIN {$wpdb->postmeta} customer_ids
|
||||
ON customer_ids.post_id = subscription_posts.ID
|
||||
AND customer_ids.meta_key = '_customer_user'
|
||||
LEFT JOIN {$wpdb->posts} parent_order
|
||||
ON parent_order.ID = subscription_posts.post_parent
|
||||
AND parent_order.post_status IN ( {$paid_statuses_placeholders} )
|
||||
LEFT JOIN {$wpdb->postmeta} parent_total
|
||||
ON parent_total.post_id = parent_order.ID
|
||||
AND parent_total.meta_key = '_order_total'
|
||||
WHERE subscription_posts.post_type = 'shop_subscription'
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
GROUP BY customer_ids.meta_value
|
||||
ORDER BY customer_id DESC
|
||||
LIMIT %d, %d
|
||||
",
|
||||
array_merge( $active_statuses, $paid_statuses, array( $offset, $per_page ) )
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
|
||||
|
||||
/**
|
||||
* Filter the query used to fetch the subscriptions by customer.
|
||||
*
|
||||
* @param string $query The query to fetch the subscriptions by customer.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query = apply_filters( 'wcs_reports_current_customer_query', $query );
|
||||
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
return $wpdb->get_results( $query );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch totals by customer for related renewal and switch orders.
|
||||
*
|
||||
* @param array $query_options The query options.
|
||||
* @return array The totals by customer for related renewal and switch orders.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
private static function fetch_subscriptions_related_orders_totals_by_customer( $query_options = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$paid_statuses = $query_options['order_status'] ?? array();
|
||||
$customer_ids = $query_options['customer_ids'] ?? array();
|
||||
|
||||
$customer_placeholders = implode( ',', array_fill( 0, count( $customer_ids ), '%s' ) );
|
||||
$status_placeholders = implode( ',', array_fill( 0, count( $paid_statuses ), '%s' ) );
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Ignored for allowing interpolation in the IN statements.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT
|
||||
renewal_orders.customer_id as customer_id,
|
||||
COALESCE( SUM(renewal_orders.total_amount), 0) as renewal_switch_total,
|
||||
COUNT(DISTINCT renewal_orders.ID) as renewal_switch_count
|
||||
FROM {$wpdb->prefix}wc_orders_meta renewal_order_ids
|
||||
INNER JOIN {$wpdb->prefix}wc_orders subscriptions
|
||||
ON renewal_order_ids.meta_value = subscriptions.ID
|
||||
AND subscriptions.type = 'shop_subscription'
|
||||
AND subscriptions.status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
INNER JOIN {$wpdb->prefix}wc_orders renewal_orders
|
||||
ON renewal_order_ids.order_id = renewal_orders.ID
|
||||
AND renewal_orders.status IN ( {$status_placeholders} )
|
||||
AND renewal_orders.customer_id IN ( {$customer_placeholders} )
|
||||
WHERE renewal_order_ids.meta_key = '_subscription_renewal'
|
||||
OR renewal_order_ids.meta_key = '_subscription_switch'
|
||||
GROUP BY renewal_orders.customer_id
|
||||
ORDER BY renewal_orders.customer_id
|
||||
",
|
||||
array_merge( $paid_statuses, $customer_ids )
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT
|
||||
customer_ids.meta_value as customer_id,
|
||||
COALESCE( SUM(renewal_switch_totals.meta_value), 0) as renewal_switch_total,
|
||||
COUNT(DISTINCT renewal_order_posts.ID) as renewal_switch_count
|
||||
FROM {$wpdb->postmeta} renewal_order_ids
|
||||
INNER JOIN {$wpdb->posts} subscription_posts
|
||||
ON renewal_order_ids.meta_value = subscription_posts.ID
|
||||
AND subscription_posts.post_type = 'shop_subscription'
|
||||
AND subscription_posts.post_status NOT IN ('wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash')
|
||||
INNER JOIN {$wpdb->postmeta} customer_ids
|
||||
ON renewal_order_ids.meta_value = customer_ids.post_id
|
||||
AND customer_ids.meta_key = '_customer_user'
|
||||
AND customer_ids.meta_value IN ( {$customer_placeholders} )
|
||||
INNER JOIN {$wpdb->posts} renewal_order_posts
|
||||
ON renewal_order_ids.post_id = renewal_order_posts.ID
|
||||
AND renewal_order_posts.post_status IN ( {$status_placeholders} )
|
||||
LEFT JOIN {$wpdb->postmeta} renewal_switch_totals
|
||||
ON renewal_switch_totals.post_id = renewal_order_ids.post_id
|
||||
AND renewal_switch_totals.meta_key = '_order_total'
|
||||
WHERE renewal_order_ids.meta_key = '_subscription_renewal'
|
||||
OR renewal_order_ids.meta_key = '_subscription_switch'
|
||||
GROUP BY customer_id
|
||||
ORDER BY customer_id
|
||||
",
|
||||
array_merge( $customer_ids, $paid_statuses )
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare.
|
||||
|
||||
/**
|
||||
* Filter the query used to fetch the totals by customer for related renewal and switch orders.
|
||||
*
|
||||
* @param string $query The query to fetch the totals by customer for related renewal and switch orders.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query = apply_filters( 'wcs_reports_current_customer_renewal_switch_total_query', $query );
|
||||
|
||||
return $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize cache for report results.
|
||||
*/
|
||||
private static function init_cache() {
|
||||
self::$cached_report_results = get_transient( strtolower( __CLASS__ ) );
|
||||
|
||||
// Set a default value for cached results for PHP 8.2+ compatibility.
|
||||
if ( empty( self::$cached_report_results ) ) {
|
||||
self::$cached_report_results = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache report results.
|
||||
*
|
||||
* @param string $query_hash The query hash.
|
||||
* @param array $report_data The report data.
|
||||
*/
|
||||
private static function cache_report_results( $query_hash, $report_data ) {
|
||||
self::$cached_report_results[ $query_hash ] = $report_data;
|
||||
set_transient( strtolower( __CLASS__ ), self::$cached_report_results, WEEK_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,15 +12,24 @@
|
|||
*/
|
||||
class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
||||
|
||||
/**
|
||||
* Cached report results.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $cached_report_results = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct( array(
|
||||
'singular' => __( 'Product', 'woocommerce-subscriptions' ),
|
||||
'plural' => __( 'Products', 'woocommerce-subscriptions' ),
|
||||
'ajax' => false,
|
||||
) );
|
||||
parent::__construct(
|
||||
array(
|
||||
'singular' => __( 'Product', 'woocommerce-subscriptions' ),
|
||||
'plural' => __( 'Products', 'woocommerce-subscriptions' ),
|
||||
'ajax' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -57,11 +66,11 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
|||
case 'product_name':
|
||||
// If the product is a subscription variation, use the parent product's edit post link
|
||||
if ( $report_item->parent_product_id > 0 ) {
|
||||
return edit_post_link( $report_item->product_name, ' - ', null, $report_item->parent_product_id );
|
||||
edit_post_link( $report_item->product_name, ' - ', null, $report_item->parent_product_id );
|
||||
} else {
|
||||
return edit_post_link( $report_item->product_name, null, null, $report_item->product_id );
|
||||
edit_post_link( $report_item->product_name, null, null, $report_item->product_id );
|
||||
}
|
||||
|
||||
break;
|
||||
case 'subscription_count':
|
||||
return sprintf( '<a href="%s%d">%d</a>', admin_url( 'edit.php?post_type=shop_subscription&_wcs_product=' ), $report_item->product_id, $report_item->subscription_count );
|
||||
|
||||
|
|
@ -108,121 +117,37 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
|||
|
||||
/**
|
||||
* Get subscription product data, either from the cache or the database.
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager to update the cache.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return array The subscription product data.
|
||||
*/
|
||||
public static function get_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$default_args = array(
|
||||
'no_cache' => false,
|
||||
'order_status' => apply_filters( 'woocommerce_reports_paid_order_statuses', array( 'completed', 'processing' ) ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the arguments for the subscription by product report.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return array The filtered arguments.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$args = apply_filters( 'wcs_reports_product_args', $args );
|
||||
$args = wp_parse_args( $args, $default_args );
|
||||
|
||||
$query = apply_filters( 'wcs_reports_product_query',
|
||||
"SELECT product.id as product_id,
|
||||
product.post_parent as parent_product_id,
|
||||
product.post_title as product_name,
|
||||
mo.product_type,
|
||||
COUNT(subscription_line_items.subscription_id) as subscription_count,
|
||||
SUM(subscription_line_items.product_total) as recurring_total
|
||||
FROM {$wpdb->posts} AS product
|
||||
LEFT JOIN (
|
||||
SELECT tr.object_id AS product_id, t.slug AS product_type
|
||||
FROM {$wpdb->prefix}term_relationships AS tr
|
||||
INNER JOIN {$wpdb->prefix}term_taxonomy AS x
|
||||
ON ( x.taxonomy = 'product_type' AND x.term_taxonomy_id = tr.term_taxonomy_id )
|
||||
INNER JOIN {$wpdb->prefix}terms AS t
|
||||
ON t.term_id = x.term_id
|
||||
) AS mo
|
||||
ON product.id = mo.product_id
|
||||
LEFT JOIN (
|
||||
SELECT wcoitems.order_id as subscription_id, wcoimeta.meta_value as product_id, wcoimeta.order_item_id, wcoimeta2.meta_value as product_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items AS wcoitems
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta
|
||||
ON wcoimeta.order_item_id = wcoitems.order_item_id
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2
|
||||
ON wcoimeta2.order_item_id = wcoitems.order_item_id
|
||||
WHERE wcoitems.order_item_type = 'line_item'
|
||||
AND ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' )
|
||||
AND wcoimeta2.meta_key = '_line_total'
|
||||
) as subscription_line_items
|
||||
ON product.id = subscription_line_items.product_id
|
||||
LEFT JOIN {$wpdb->posts} as subscriptions
|
||||
ON subscriptions.ID = subscription_line_items.subscription_id
|
||||
WHERE product.post_status = 'publish'
|
||||
AND ( product.post_type = 'product' OR product.post_type = 'product_variation' )
|
||||
AND subscriptions.post_type = 'shop_subscription'
|
||||
AND subscriptions.post_status NOT IN( 'wc-pending', 'trash' )
|
||||
GROUP BY product.id
|
||||
ORDER BY COUNT(subscription_line_items.subscription_id) DESC" );
|
||||
|
||||
$cached_results = get_transient( strtolower( __CLASS__ ) );
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = apply_filters( 'wcs_reports_product_data', $wpdb->get_results( $query, OBJECT_K ), $args );
|
||||
set_transient( strtolower( __CLASS__ ), $cached_results, WEEK_IN_SECONDS );
|
||||
}
|
||||
|
||||
$report_data = $cached_results[ $query_hash ];
|
||||
|
||||
// Organize subscription variations under the parent product in a tree structure
|
||||
$tree = array();
|
||||
foreach ( $report_data as $product_id => $product ) {
|
||||
if ( ! $product->parent_product_id ) {
|
||||
if ( isset( $tree[ $product_id ] ) ) {
|
||||
array_unshift( $tree[ $product_id ], $product_id );
|
||||
} else {
|
||||
$tree[ $product_id ][] = $product_id;
|
||||
}
|
||||
} else {
|
||||
$tree[ $product->parent_product_id ][] = $product_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Create an array with all the report data in the correct order
|
||||
$ordered_report_data = array();
|
||||
foreach ( $tree as $parent_id => $children ) {
|
||||
foreach ( $children as $child_id ) {
|
||||
$ordered_report_data[ $child_id ] = $report_data[ $child_id ];
|
||||
|
||||
// When there are variations, store the variation ids.
|
||||
if ( 'variable-subscription' === $report_data[ $child_id ]->product_type ) {
|
||||
$ordered_report_data[ $child_id ]->variations = array_diff( $children, array( $parent_id ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now let's get the total revenue for each product so we can provide an average lifetime value for that product
|
||||
$query = apply_filters( 'wcs_reports_product_lifetime_value_query',
|
||||
"SELECT wcoimeta.meta_value as product_id, SUM(wcoimeta2.meta_value) as product_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items AS wcoitems
|
||||
INNER JOIN {$wpdb->posts} AS wcorders
|
||||
ON wcoitems.order_id = wcorders.ID
|
||||
AND wcorders.post_type = 'shop_order'
|
||||
AND wcorders.post_status IN ( 'wc-" . implode( "','wc-", $args['order_status'] ) . "' )
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta
|
||||
ON wcoimeta.order_item_id = wcoitems.order_item_id
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2
|
||||
ON wcoimeta2.order_item_id = wcoitems.order_item_id
|
||||
WHERE ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' )
|
||||
AND wcoimeta2.meta_key = '_line_total'
|
||||
GROUP BY product_id" );
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = apply_filters( 'wcs_reports_product_lifetime_value_data', $wpdb->get_results( $query, OBJECT_K ), $args );
|
||||
set_transient( strtolower( __CLASS__ ), $cached_results, WEEK_IN_SECONDS );
|
||||
}
|
||||
self::init_cache();
|
||||
$subscriptions_by_product = self::fetch_subscription_products_data( $args );
|
||||
$subscription_product_totals = self::fetch_product_totals_data( $args );
|
||||
$ordered_report_data = self::organize_subscription_products_data( $subscriptions_by_product );
|
||||
|
||||
// Add the product total to each item
|
||||
foreach ( array_keys( $ordered_report_data ) as $product_id ) {
|
||||
$ordered_report_data[ $product_id ]->product_total = isset( $cached_results[ $query_hash ][ $product_id ] ) ? $cached_results[ $query_hash ][ $product_id ]->product_total : 0;
|
||||
$ordered_report_data[ $product_id ]->product_total = isset( $subscription_product_totals[ $product_id ] ) ? $subscription_product_totals[ $product_id ]->product_total : 0;
|
||||
}
|
||||
|
||||
return $ordered_report_data;
|
||||
|
|
@ -264,11 +189,11 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
|||
jQuery('.chart-placeholder.variation_breakdown_chart'),
|
||||
[
|
||||
<?php
|
||||
$colorindex = -1;
|
||||
$colorindex = -1;
|
||||
$last_parent_id = -1;
|
||||
foreach ( $variations as $product ) {
|
||||
if ( '0' === $product->parent_product_id || $last_parent_id !== $product->parent_product_id ) {
|
||||
$colorindex++;
|
||||
++$colorindex;
|
||||
$last_parent_id = $product->parent_product_id;
|
||||
}
|
||||
?>
|
||||
|
|
@ -318,7 +243,7 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
|||
color: '<?php echo esc_js( $chart_colors[ $i ] ); ?>'
|
||||
},
|
||||
<?php
|
||||
$i++;
|
||||
++$i;
|
||||
}
|
||||
?>
|
||||
],
|
||||
|
|
@ -355,9 +280,261 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
|||
/**
|
||||
* Clears the cached report data.
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager before updating the cache.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
public static function clear_cache() {
|
||||
delete_transient( strtolower( __CLASS__ ) );
|
||||
self::$cached_report_results = array();
|
||||
}
|
||||
|
||||
private static function fetch_subscription_products_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = "SELECT product.id as product_id,
|
||||
product.post_parent as parent_product_id,
|
||||
product.post_title as product_name,
|
||||
mo.product_type,
|
||||
COUNT(subscription_line_items.subscription_id) as subscription_count,
|
||||
SUM(subscription_line_items.product_total) as recurring_total
|
||||
FROM {$wpdb->posts} AS product
|
||||
LEFT JOIN (
|
||||
SELECT tr.object_id AS product_id, t.slug AS product_type
|
||||
FROM {$wpdb->prefix}term_relationships AS tr
|
||||
INNER JOIN {$wpdb->prefix}term_taxonomy AS x
|
||||
ON ( x.taxonomy = 'product_type' AND x.term_taxonomy_id = tr.term_taxonomy_id )
|
||||
INNER JOIN {$wpdb->prefix}terms AS t
|
||||
ON t.term_id = x.term_id
|
||||
) AS mo
|
||||
ON product.id = mo.product_id
|
||||
LEFT JOIN (
|
||||
SELECT wcoitems.order_id as subscription_id, wcoimeta.meta_value as product_id, wcoimeta.order_item_id, wcoimeta2.meta_value as product_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items AS wcoitems
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta
|
||||
ON wcoimeta.order_item_id = wcoitems.order_item_id
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2
|
||||
ON wcoimeta2.order_item_id = wcoitems.order_item_id
|
||||
WHERE wcoitems.order_item_type = 'line_item'
|
||||
AND ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' )
|
||||
AND wcoimeta2.meta_key = '_line_total'
|
||||
) as subscription_line_items
|
||||
ON product.id = subscription_line_items.product_id
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders as subscriptions
|
||||
ON subscriptions.ID = subscription_line_items.subscription_id
|
||||
WHERE product.post_status = 'publish'
|
||||
AND ( product.post_type = 'product' OR product.post_type = 'product_variation' )
|
||||
AND subscriptions.type = 'shop_subscription'
|
||||
AND subscriptions.status NOT IN( 'wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash' )
|
||||
GROUP BY product.id
|
||||
ORDER BY COUNT(subscription_line_items.subscription_id) DESC";
|
||||
} else {
|
||||
$query = "SELECT product.id as product_id,
|
||||
product.post_parent as parent_product_id,
|
||||
product.post_title as product_name,
|
||||
mo.product_type,
|
||||
COUNT(subscription_line_items.subscription_id) as subscription_count,
|
||||
SUM(subscription_line_items.product_total) as recurring_total
|
||||
FROM {$wpdb->posts} AS product
|
||||
LEFT JOIN (
|
||||
SELECT tr.object_id AS product_id, t.slug AS product_type
|
||||
FROM {$wpdb->prefix}term_relationships AS tr
|
||||
INNER JOIN {$wpdb->prefix}term_taxonomy AS x
|
||||
ON ( x.taxonomy = 'product_type' AND x.term_taxonomy_id = tr.term_taxonomy_id )
|
||||
INNER JOIN {$wpdb->prefix}terms AS t
|
||||
ON t.term_id = x.term_id
|
||||
) AS mo
|
||||
ON product.id = mo.product_id
|
||||
LEFT JOIN (
|
||||
SELECT wcoitems.order_id as subscription_id, wcoimeta.meta_value as product_id, wcoimeta.order_item_id, wcoimeta2.meta_value as product_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items AS wcoitems
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta
|
||||
ON wcoimeta.order_item_id = wcoitems.order_item_id
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2
|
||||
ON wcoimeta2.order_item_id = wcoitems.order_item_id
|
||||
WHERE wcoitems.order_item_type = 'line_item'
|
||||
AND ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' )
|
||||
AND wcoimeta2.meta_key = '_line_total'
|
||||
) as subscription_line_items
|
||||
ON product.id = subscription_line_items.product_id
|
||||
LEFT JOIN {$wpdb->posts} as subscriptions
|
||||
ON subscriptions.ID = subscription_line_items.subscription_id
|
||||
WHERE product.post_status = 'publish'
|
||||
AND ( product.post_type = 'product' OR product.post_type = 'product_variation' )
|
||||
AND subscriptions.post_type = 'shop_subscription'
|
||||
AND subscriptions.post_status NOT IN( 'wc-pending', 'auto-draft', 'wc-checkout-draft', 'trash' )
|
||||
GROUP BY product.id
|
||||
ORDER BY COUNT(subscription_line_items.subscription_id) DESC";
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query to get the subscription products data.
|
||||
*
|
||||
* @param string $query The query to get the subscription products data.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query = apply_filters( 'wcs_reports_product_query', $query );
|
||||
$query_hash = md5( $query );
|
||||
|
||||
// We expect that cache was initialized before calling this method.
|
||||
// Skip running the query if cache is available.
|
||||
if ( $args['no_cache'] || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$query_results = (array) $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
|
||||
/**
|
||||
* Filter the query results for subscription products.
|
||||
*
|
||||
* @param array $query_results The query results.
|
||||
* @param array $args The arguments for the report.
|
||||
* @return array The filtered query results.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query_results = apply_filters( 'wcs_reports_product_data', $query_results, $args );
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Organize subscription products data for futher reporting.
|
||||
*
|
||||
* Group subscription product variations under variable subscription products.
|
||||
*
|
||||
* @param array $report_data The report data.
|
||||
* @return array The organized report data.
|
||||
*/
|
||||
private static function organize_subscription_products_data( $report_data ) {
|
||||
$tree = array();
|
||||
foreach ( $report_data as $product_id => $product ) {
|
||||
if ( ! $product->parent_product_id ) {
|
||||
if ( isset( $tree[ $product_id ] ) ) {
|
||||
array_unshift( $tree[ $product_id ], $product_id );
|
||||
} else {
|
||||
$tree[ $product_id ][] = $product_id;
|
||||
}
|
||||
} else {
|
||||
$tree[ $product->parent_product_id ][] = $product_id;
|
||||
}
|
||||
}
|
||||
|
||||
// Create an array with all the report data in the correct order
|
||||
$ordered_report_data = array();
|
||||
foreach ( $tree as $parent_id => $children ) {
|
||||
foreach ( $children as $child_id ) {
|
||||
$ordered_report_data[ $child_id ] = $report_data[ $child_id ];
|
||||
|
||||
// When there are variations, store the variation ids.
|
||||
if ( 'variable-subscription' === $report_data[ $child_id ]->product_type ) {
|
||||
$ordered_report_data[ $child_id ]->variations = array_diff( $children, array( $parent_id ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ordered_report_data;
|
||||
}
|
||||
|
||||
private static function fetch_product_totals_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
$placeholders = implode( ',', array_fill( 0, count( $args['order_status'] ), '%s' ) );
|
||||
$statuses = wcs_maybe_prefix_key( $args['order_status'], 'wc-' );
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Ignored for allowing interpolation in the IN statements.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT wcoimeta.meta_value as product_id, SUM(wcoimeta2.meta_value) as product_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items AS wcoitems
|
||||
INNER JOIN {$wpdb->prefix}wc_orders AS wcorders
|
||||
ON wcoitems.order_id = wcorders.ID
|
||||
AND wcorders.type = 'shop_order'
|
||||
AND wcorders.status IN ( {$placeholders} )
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta
|
||||
ON wcoimeta.order_item_id = wcoitems.order_item_id
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2
|
||||
ON wcoimeta2.order_item_id = wcoitems.order_item_id
|
||||
WHERE ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' )
|
||||
AND wcoimeta2.meta_key = '_line_total'
|
||||
GROUP BY product_id",
|
||||
$statuses
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT wcoimeta.meta_value as product_id, SUM(wcoimeta2.meta_value) as product_total
|
||||
FROM {$wpdb->prefix}woocommerce_order_items AS wcoitems
|
||||
INNER JOIN {$wpdb->posts} AS wcorders
|
||||
ON wcoitems.order_id = wcorders.ID
|
||||
AND wcorders.post_type = 'shop_order'
|
||||
AND wcorders.post_status IN ( {$placeholders} )
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta
|
||||
ON wcoimeta.order_item_id = wcoitems.order_item_id
|
||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2
|
||||
ON wcoimeta2.order_item_id = wcoitems.order_item_id
|
||||
WHERE ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' )
|
||||
AND wcoimeta2.meta_key = '_line_total'
|
||||
GROUP BY product_id",
|
||||
$statuses
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
||||
|
||||
/**
|
||||
* Filter the query to get the product totals data.
|
||||
*
|
||||
* @param string $query The query to get the product totals data.
|
||||
* @return string The filtered query.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query = apply_filters( 'wcs_reports_product_lifetime_value_query', $query );
|
||||
|
||||
$query_hash = md5( $query );
|
||||
|
||||
// We expect that cache was initialized before calling this method.
|
||||
// Skip running the query if cache is available.
|
||||
if ( $args['no_cache'] || ! isset( self::$cached_report_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$query_results = (array) $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
/**
|
||||
* Filter the query results for product totals.
|
||||
*
|
||||
* @param array $query_results The query results.
|
||||
* @param array $args The arguments for the report.
|
||||
* @return array The filtered query results.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$query_results = apply_filters( 'wcs_reports_product_lifetime_value_data', $query_results, $args );
|
||||
self::cache_report_results( $query_hash, $query_results );
|
||||
}
|
||||
|
||||
return self::$cached_report_results[ $query_hash ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize cache for report results.
|
||||
*/
|
||||
private static function init_cache() {
|
||||
self::$cached_report_results = get_transient( strtolower( __CLASS__ ) );
|
||||
|
||||
// Set a default value for cached results for PHP 8.2+ compatibility.
|
||||
if ( empty( self::$cached_report_results ) ) {
|
||||
self::$cached_report_results = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache report results.
|
||||
*
|
||||
* @param string $query_hash The query hash.
|
||||
* @param array $report_data The report data.
|
||||
*/
|
||||
private static function cache_report_results( $query_hash, $report_data ) {
|
||||
self::$cached_report_results[ $query_hash ] = $report_data;
|
||||
set_transient( strtolower( __CLASS__ ), self::$cached_report_results, WEEK_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class WCS_Report_Subscription_Payment_Retry extends WC_Admin_Report {
|
|||
|
||||
/**
|
||||
* Get report data
|
||||
* @return array
|
||||
* @return stdClass
|
||||
*/
|
||||
public function get_report_data() {
|
||||
|
||||
|
|
@ -36,65 +36,35 @@ class WCS_Report_Subscription_Payment_Retry extends WC_Admin_Report {
|
|||
global $wpdb;
|
||||
|
||||
// Convert from Decimal format(eg. 11.5) to a suitable format(eg. +11:30) for CONVERT_TZ() of SQL query.
|
||||
$offset = get_option( 'gmt_offset' );
|
||||
$site_timezone = sprintf( '%+02d:%02d', (int) $offset, ( $offset - floor( $offset ) ) * 60 );
|
||||
$retry_date_in_local_time = $wpdb->prepare( "CONVERT_TZ(retries.date_gmt, '+00:00', %s)", $site_timezone );
|
||||
$offset = get_option( 'gmt_offset' );
|
||||
$site_timezone = sprintf( '%+02d:%02d', (int) $offset, ( $offset - floor( $offset ) ) * 60 );
|
||||
$retry_date_in_local_time_query = $wpdb->prepare( "CONVERT_TZ(retries.date_gmt, '+00:00', %s)", $site_timezone );
|
||||
|
||||
// We need to compute this on our own since 'group_by_query' from the parent class uses posts table column names.
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day':
|
||||
$this->group_by_query = "YEAR({$retry_date_in_local_time}), MONTH({$retry_date_in_local_time}), DAY({$retry_date_in_local_time})";
|
||||
$this->group_by_query = "YEAR({$retry_date_in_local_time_query}), MONTH({$retry_date_in_local_time_query}), DAY({$retry_date_in_local_time_query})";
|
||||
break;
|
||||
case 'month':
|
||||
$this->group_by_query = "YEAR({$retry_date_in_local_time}), MONTH({$retry_date_in_local_time})";
|
||||
$this->group_by_query = "YEAR({$retry_date_in_local_time_query}), MONTH({$retry_date_in_local_time_query})";
|
||||
break;
|
||||
}
|
||||
|
||||
$this->report_data = new stdClass;
|
||||
|
||||
$query_start_date = get_gmt_from_date( date( 'Y-m-d H:i:s', $this->start_date ) );
|
||||
$query_end_date = get_gmt_from_date( date( 'Y-m-d H:i:s', wcs_strtotime_dark_knight( '+1 day', $this->end_date ) ) );
|
||||
|
||||
// Get the sum of order totals for completed retries (i.e. retries which eventually succeeded in processing the failed payment)
|
||||
$renewal_query = $wpdb->prepare(
|
||||
"
|
||||
SELECT COUNT(DISTINCT retries.retry_id) as count, MIN(retries.date_gmt) AS retry_date_gmt, MIN({$retry_date_in_local_time}) AS retry_date, SUM(meta_order_total.meta_value) AS renewal_totals
|
||||
FROM {$wpdb->posts} AS orders
|
||||
INNER JOIN {$wpdb->prefix}wcs_payment_retries AS retries ON ( orders.ID = retries.order_id )
|
||||
LEFT JOIN {$wpdb->postmeta} AS meta_order_total ON ( orders.ID = meta_order_total.post_id AND meta_order_total.meta_key = '_order_total' )
|
||||
WHERE retries.status = 'complete'
|
||||
AND retries.date_gmt >= %s
|
||||
AND retries.date_gmt < %s
|
||||
GROUP BY {$this->group_by_query}
|
||||
ORDER BY retry_date_gmt ASC
|
||||
",
|
||||
$query_start_date,
|
||||
$query_end_date
|
||||
$query_options = array(
|
||||
'site_timezone' => $site_timezone,
|
||||
'query_start_date' => get_gmt_from_date( date( 'Y-m-d H:i:s', $this->start_date ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
'query_end_date' => get_gmt_from_date( date( 'Y-m-d H:i:s', wcs_strtotime_dark_knight( '+1 day', $this->end_date ) ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
);
|
||||
|
||||
$this->report_data->renewal_data = $wpdb->get_results( $renewal_query );
|
||||
|
||||
// Get the counts for all retries, grouped by day or month and status
|
||||
$retry_query = $wpdb->prepare(
|
||||
"
|
||||
SELECT COUNT(DISTINCT retries.retry_id) AS count, retries.status AS status, MIN(retries.date_gmt) AS retry_date_gmt, MIN({$retry_date_in_local_time}) AS retry_date
|
||||
FROM {$wpdb->prefix}wcs_payment_retries AS retries
|
||||
WHERE retries.status IN ( 'complete', 'failed', 'pending' )
|
||||
AND retries.date_gmt >= %s
|
||||
AND retries.date_gmt < %s
|
||||
GROUP BY {$this->group_by_query}, status
|
||||
ORDER BY retry_date_gmt ASC
|
||||
",
|
||||
$query_start_date,
|
||||
$query_end_date
|
||||
);
|
||||
|
||||
$this->report_data->retry_data = $wpdb->get_results( $retry_query );
|
||||
$this->fetch_renewal_data( $query_options );
|
||||
$this->fetch_retry_data( $query_options );
|
||||
|
||||
// Total up the query data
|
||||
$this->report_data->retry_failed_count = absint( array_sum( wp_list_pluck( wp_list_filter( $this->report_data->retry_data, array( 'status' => 'failed' ) ), 'count' ) ) );
|
||||
$this->report_data->retry_success_count = absint( array_sum( wp_list_pluck( wp_list_filter( $this->report_data->retry_data, array( 'status' => 'complete' ) ), 'count' ) ) );
|
||||
$this->report_data->retry_pending_count = absint( array_sum( wp_list_pluck( wp_list_filter( $this->report_data->retry_data, array( 'status' => 'pending' ) ), 'count' ) ) );
|
||||
$this->report_data->retry_failed_count = absint( array_sum( wp_list_pluck( wp_list_filter( $this->report_data->retry_data, array( 'status' => 'failed' ) ), 'count' ) ) );
|
||||
$this->report_data->retry_success_count = absint( array_sum( wp_list_pluck( wp_list_filter( $this->report_data->retry_data, array( 'status' => 'complete' ) ), 'count' ) ) );
|
||||
$this->report_data->retry_pending_count = absint( array_sum( wp_list_pluck( wp_list_filter( $this->report_data->retry_data, array( 'status' => 'pending' ) ), 'count' ) ) );
|
||||
|
||||
$this->report_data->renewal_total_count = absint( array_sum( wp_list_pluck( $this->report_data->renewal_data, 'count' ) ) );
|
||||
$this->report_data->renewal_total_amount = array_sum( wp_list_pluck( $this->report_data->renewal_data, 'renewal_totals' ) );
|
||||
|
|
@ -204,7 +174,7 @@ class WCS_Report_Subscription_Payment_Retry extends WC_Admin_Report {
|
|||
/**
|
||||
* Get the main chart
|
||||
*
|
||||
* @return string
|
||||
* @return void
|
||||
*/
|
||||
public function get_main_chart() {
|
||||
global $wp_locale;
|
||||
|
|
@ -408,4 +378,86 @@ class WCS_Report_Subscription_Payment_Retry extends WC_Admin_Report {
|
|||
return wc_format_decimal( $amount, wc_get_price_decimals() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sum of order totals for completed retries (i.e. retries which eventually succeeded in processing the failed payment)
|
||||
*
|
||||
* @param array $query_options Query options.
|
||||
*/
|
||||
private function fetch_renewal_data( $query_options ) {
|
||||
global $wpdb;
|
||||
$site_timezone = $query_options['site_timezone'];
|
||||
$query_start_date = $query_options['query_start_date'];
|
||||
$query_end_date = $query_options['query_end_date'];
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- The $this->group_by_query clause is hard coded.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"
|
||||
SELECT COUNT(DISTINCT retries.retry_id) as count, MIN(retries.date_gmt) AS retry_date_gmt, MIN(CONVERT_TZ(retries.date_gmt, '+00:00', %s)) AS retry_date, SUM(orders.total_amount) AS renewal_totals
|
||||
FROM {$wpdb->prefix}wcs_payment_retries AS retries
|
||||
INNER JOIN {$wpdb->prefix}wc_orders AS orders ON ( orders.id = retries.order_id )
|
||||
WHERE retries.status = 'complete'
|
||||
AND retries.date_gmt >= %s
|
||||
AND retries.date_gmt < %s
|
||||
GROUP BY {$this->group_by_query}
|
||||
ORDER BY retry_date_gmt ASC
|
||||
",
|
||||
$site_timezone,
|
||||
$query_start_date,
|
||||
$query_end_date
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"
|
||||
SELECT COUNT(DISTINCT retries.retry_id) as count, MIN(retries.date_gmt) AS retry_date_gmt, MIN(CONVERT_TZ(retries.date_gmt, '+00:00', %s)) AS retry_date, SUM(meta_order_total.meta_value) AS renewal_totals
|
||||
FROM {$wpdb->posts} AS orders
|
||||
INNER JOIN {$wpdb->prefix}wcs_payment_retries AS retries ON ( orders.ID = retries.order_id )
|
||||
LEFT JOIN {$wpdb->postmeta} AS meta_order_total ON ( orders.ID = meta_order_total.post_id AND meta_order_total.meta_key = '_order_total' )
|
||||
WHERE retries.status = 'complete'
|
||||
AND retries.date_gmt >= %s
|
||||
AND retries.date_gmt < %s
|
||||
GROUP BY {$this->group_by_query}
|
||||
ORDER BY retry_date_gmt ASC
|
||||
",
|
||||
$site_timezone,
|
||||
$query_start_date,
|
||||
$query_end_date
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
$this->report_data->renewal_data = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the counts for all retries, grouped by day or month and status
|
||||
*
|
||||
* @param array $query_options Query options.
|
||||
*/
|
||||
private function fetch_retry_data( $query_options ) {
|
||||
global $wpdb;
|
||||
$site_timezone = $query_options['site_timezone'];
|
||||
$query_start_date = $query_options['query_start_date'];
|
||||
$query_end_date = $query_options['query_end_date'];
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- The $this->group_by_query clause is hard coded.
|
||||
// We don't use HPOS tables here, so we can use it for both CPT and HPOS data stores.
|
||||
$query = $wpdb->prepare(
|
||||
"
|
||||
SELECT COUNT(DISTINCT retries.retry_id) AS count, retries.status AS status, MIN(retries.date_gmt) AS retry_date_gmt, MIN(CONVERT_TZ(retries.date_gmt, '+00:00', %s)) AS retry_date
|
||||
FROM {$wpdb->prefix}wcs_payment_retries AS retries
|
||||
WHERE retries.status IN ( 'complete', 'failed', 'pending' )
|
||||
AND retries.date_gmt >= %s
|
||||
AND retries.date_gmt < %s
|
||||
GROUP BY {$this->group_by_query}, status
|
||||
ORDER BY retry_date_gmt ASC
|
||||
",
|
||||
$site_timezone,
|
||||
$query_start_date,
|
||||
$query_end_date
|
||||
);
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$this->report_data->retry_data = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
|
||||
public $order_ids_recurring_totals = null;
|
||||
|
||||
public $average_sales = 0;
|
||||
|
||||
/**
|
||||
* Get the legend for the main chart sidebar
|
||||
* @return array
|
||||
|
|
@ -46,6 +48,10 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
$scheduled_ends[ $key ] = date( 'Y-m-d', strtotime( $scheduled_ends[ $key ] ) );
|
||||
}
|
||||
|
||||
if ( ! isset( $billing_intervals[ $key ] ) || ! isset( $billing_periods[ $key ] ) || ! in_array( $billing_periods[ $key ], array_keys( wcs_get_subscription_period_strings() ), true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Keep calculating all the new payments until we hit the end date of the search
|
||||
do {
|
||||
|
||||
|
|
@ -67,7 +73,9 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
$this->order_ids_recurring_totals[ $update_key ]->recurring_total += $subscription_totals[ $key ];
|
||||
}
|
||||
}
|
||||
} while ( $next_payment_timestamp <= $this->end_date && isset( $scheduled_ends[ $key ] ) && ( 0 == $scheduled_ends[ $key ] || $next_payment_timestamp < strtotime( $scheduled_ends[ $key ] ) ) );
|
||||
} while ( $next_payment_timestamp > 0 && $next_payment_timestamp <= $this->end_date
|
||||
&& isset( $scheduled_ends[ $key ] )
|
||||
&& ( 0 == $scheduled_ends[ $key ] || $next_payment_timestamp < strtotime( $scheduled_ends[ $key ] ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +117,11 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
|
||||
/**
|
||||
* Get report data.
|
||||
* @return stdClass
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager to update the cache.
|
||||
*
|
||||
* @param array $args The arguments for the report.
|
||||
* @return stdClass[] - Upcoming renewal data grouped by scheduled date.
|
||||
*/
|
||||
public function get_data( $args = array() ) {
|
||||
global $wpdb;
|
||||
|
|
@ -122,48 +134,100 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
$args = wp_parse_args( $args, $default_args );
|
||||
|
||||
// Query based on whole days, not minutes/hours so that we can cache the query for at least 24 hours
|
||||
$base_query = $wpdb->prepare(
|
||||
"SELECT
|
||||
DATE(ms.meta_value) as scheduled_date,
|
||||
SUM(mo.meta_value) as recurring_total,
|
||||
COUNT(mo.meta_value) as total_renewals,
|
||||
group_concat(p.ID) as subscription_ids,
|
||||
group_concat(mi.meta_value) as billing_intervals,
|
||||
group_concat(mp.meta_value) as billing_periods,
|
||||
group_concat(me.meta_value) as scheduled_ends,
|
||||
group_concat(mo.meta_value) as subscription_totals
|
||||
FROM {$wpdb->prefix}posts p
|
||||
LEFT JOIN {$wpdb->prefix}postmeta ms
|
||||
ON p.ID = ms.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta mo
|
||||
ON p.ID = mo.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta mi
|
||||
ON p.ID = mi.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta mp
|
||||
ON p.ID = mp.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta me
|
||||
ON p.ID = me.post_id
|
||||
WHERE p.post_type = 'shop_subscription'
|
||||
AND p.post_status = 'wc-active'
|
||||
AND mo.meta_key = '_order_total'
|
||||
AND ms.meta_key = '_schedule_next_payment'
|
||||
AND ( ( ms.meta_value < '%s' AND me.meta_value = 0 ) OR ( me.meta_value > '%s' AND ms.meta_value < '%s' ) )
|
||||
AND mi.meta_key = '_billing_interval'
|
||||
AND mp.meta_key = '_billing_period'
|
||||
AND me.meta_key = '_schedule_end '
|
||||
GROUP BY {$this->group_by_query}
|
||||
ORDER BY ms.meta_value ASC",
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', $this->end_date ) ),
|
||||
date( 'Y-m-d', $this->start_date ),
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', $this->end_date ) )
|
||||
);
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- The $this->group_by_query clause is hard coded.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT
|
||||
DATE(meta_next_payment.meta_value) as scheduled_date,
|
||||
SUM(subscriptions.total_amount) as recurring_total,
|
||||
COUNT(subscriptions.total_amount) as total_renewals,
|
||||
group_concat(subscriptions.ID) as subscription_ids,
|
||||
group_concat(meta_billing_interval.meta_value) as billing_intervals,
|
||||
group_concat(meta_billing_period.meta_value) as billing_periods,
|
||||
group_concat(meta_schedule_end.meta_value) as scheduled_ends,
|
||||
group_concat(subscriptions.total_amount) as subscription_totals
|
||||
FROM {$wpdb->prefix}wc_orders subscriptions
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta meta_next_payment
|
||||
ON subscriptions.ID = meta_next_payment.order_id
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta meta_billing_interval
|
||||
ON subscriptions.ID = meta_billing_interval.order_id
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta meta_billing_period
|
||||
ON subscriptions.ID = meta_billing_period.order_id
|
||||
LEFT JOIN {$wpdb->prefix}wc_orders_meta meta_schedule_end
|
||||
ON subscriptions.ID = meta_schedule_end.order_id
|
||||
WHERE subscriptions.type = 'shop_subscription'
|
||||
AND subscriptions.status = 'wc-active'
|
||||
AND meta_next_payment.meta_key = '_schedule_next_payment'
|
||||
AND ( ( meta_next_payment.meta_value < %s AND meta_schedule_end.meta_value = 0 ) OR ( meta_schedule_end.meta_value > %s AND meta_next_payment.meta_value < %s ) )
|
||||
AND meta_billing_interval.meta_key = '_billing_interval'
|
||||
AND meta_billing_period.meta_key = '_billing_period'
|
||||
AND meta_schedule_end.meta_key = '_schedule_end'
|
||||
GROUP BY {$this->group_by_query}
|
||||
ORDER BY meta_next_payment.meta_value ASC",
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', $this->end_date ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Keep date formatting from original report.
|
||||
date( 'Y-m-d', $this->start_date ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Keep date formatting from original report.
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', $this->end_date ) ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Keep date formatting from original report.
|
||||
);
|
||||
} else {
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT
|
||||
DATE(meta_next_payment.meta_value) as scheduled_date,
|
||||
SUM(meta_order_total.meta_value) as recurring_total,
|
||||
COUNT(meta_order_total.meta_value) as total_renewals,
|
||||
group_concat(posts.ID) as subscription_ids,
|
||||
group_concat(meta_billing_interval.meta_value) as billing_intervals,
|
||||
group_concat(meta_billing_period.meta_value) as billing_periods,
|
||||
group_concat(meta_schedule_end.meta_value) as scheduled_ends,
|
||||
group_concat(meta_order_total.meta_value) as subscription_totals
|
||||
FROM {$wpdb->prefix}posts posts
|
||||
LEFT JOIN {$wpdb->prefix}postmeta meta_next_payment
|
||||
ON posts.ID = meta_next_payment.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta meta_order_total
|
||||
ON posts.ID = meta_order_total.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta meta_billing_interval
|
||||
ON posts.ID = meta_billing_interval.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta meta_billing_period
|
||||
ON posts.ID = meta_billing_period.post_id
|
||||
LEFT JOIN {$wpdb->prefix}postmeta meta_schedule_end
|
||||
ON posts.ID = meta_schedule_end.post_id
|
||||
WHERE posts.post_type = 'shop_subscription'
|
||||
AND posts.post_status = 'wc-active'
|
||||
AND meta_order_total.meta_key = '_order_total'
|
||||
AND meta_next_payment.meta_key = '_schedule_next_payment'
|
||||
AND ( ( meta_next_payment.meta_value < %s AND meta_schedule_end.meta_value = 0 ) OR ( meta_schedule_end.meta_value > %s AND meta_next_payment.meta_value < %s ) )
|
||||
AND meta_billing_interval.meta_key = '_billing_interval'
|
||||
AND meta_billing_period.meta_key = '_billing_period'
|
||||
AND meta_schedule_end.meta_key = '_schedule_end'
|
||||
GROUP BY {$this->group_by_query}
|
||||
ORDER BY meta_next_payment.meta_value ASC",
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', $this->end_date ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Keep date formatting from original report.
|
||||
date( 'Y-m-d', $this->start_date ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Keep date formatting from original report.
|
||||
date( 'Y-m-d', strtotime( '+1 DAY', $this->end_date ) ) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- Keep date formatting from original report.
|
||||
);
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
$cached_results = get_transient( strtolower( get_class( $this ) ) );
|
||||
$query_hash = md5( $base_query );
|
||||
$query_hash = md5( $query );
|
||||
|
||||
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
// Set a default value for cached results for PHP 8.2+ compatibility.
|
||||
if ( empty( $cached_results ) ) {
|
||||
$cached_results = array();
|
||||
}
|
||||
|
||||
if ( $args['no_cache'] || ! isset( $cached_results[ $query_hash ] ) ) {
|
||||
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
|
||||
$cached_results[ $query_hash ] = apply_filters( 'wcs_reports_upcoming_recurring_revenue_data', $wpdb->get_results( $base_query, OBJECT_K ), $args );
|
||||
$results = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- This query is prepared above.
|
||||
/**
|
||||
* Filter the upcoming recurring revenue data.
|
||||
*
|
||||
* @param array $results The upcoming recurring revenue data.
|
||||
* @param array $args The arguments for the report.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$results = apply_filters( 'wcs_reports_upcoming_recurring_revenue_data', $results, $args );
|
||||
|
||||
$cached_results[ $query_hash ] = $results;
|
||||
set_transient( strtolower( get_class( $this ) ), $cached_results, WEEK_IN_SECONDS );
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +281,7 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
|
||||
/**
|
||||
* Get the main chart
|
||||
* @return string
|
||||
* @return void
|
||||
*/
|
||||
public function get_main_chart() {
|
||||
global $wp_locale;
|
||||
|
|
@ -402,12 +466,12 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
// Group by
|
||||
switch ( $this->chart_groupby ) {
|
||||
case 'day':
|
||||
$this->group_by_query = 'YEAR(ms.meta_value), MONTH(ms.meta_value), DAY(ms.meta_value)';
|
||||
$this->group_by_query = 'YEAR(meta_next_payment.meta_value), MONTH(meta_next_payment.meta_value), DAY(meta_next_payment.meta_value)';
|
||||
$this->chart_interval = ceil( max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ) );
|
||||
$this->barwidth = 60 * 60 * 24 * 1000;
|
||||
break;
|
||||
case 'month':
|
||||
$this->group_by_query = 'YEAR(ms.meta_value), MONTH(ms.meta_value), DAY(ms.meta_value)';
|
||||
$this->group_by_query = 'YEAR(meta_next_payment.meta_value), MONTH(meta_next_payment.meta_value), DAY(meta_next_payment.meta_value)';
|
||||
$this->chart_interval = 0;
|
||||
$min_date = $this->start_date;
|
||||
while ( ( $min_date = wcs_add_months( $min_date, '1' ) ) <= $this->end_date ) {
|
||||
|
|
@ -434,6 +498,8 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
|
|||
/**
|
||||
* Clears the cached query results.
|
||||
*
|
||||
* @see WCS_Report_Cache_Manager::update_cache() - This method is called by the cache manager before updating the cache.
|
||||
*
|
||||
* @since 3.0.10
|
||||
*/
|
||||
public function clear_cache() {
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Subscriptions Admin Report - Retention Rate
|
||||
*
|
||||
* Find the number of periods between when each subscription is created and ends or ended
|
||||
* then plot all subscriptions using this data to provide a curve of retention rates.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin_Reports
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.1
|
||||
* @deprecated in favor of WCS_Report_Retention_Rate
|
||||
*/
|
||||
class WC_Report_Retention_Rate extends WCS_Report_Retention_Rate {
|
||||
public function __construct() {
|
||||
wcs_deprecated_function( __CLASS__, '2.4.0', get_parent_class( __CLASS__ ) );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Subscriptions Admin Report - Subscriptions by customer
|
||||
*
|
||||
* Creates the subscription admin reports area.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin_Reports
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.1
|
||||
* @deprecated in favor of WCS_Report_Subscription_By_Customer
|
||||
*/
|
||||
class WC_Report_Subscription_By_Customer extends WCS_Report_Subscription_By_Customer {
|
||||
public function __construct() {
|
||||
wcs_deprecated_function( __CLASS__, '2.4.0', get_parent_class( __CLASS__ ) );
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Subscriptions Admin Report - Subscriptions by product
|
||||
*
|
||||
* Creates the subscription admin reports area.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin_Reports
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.1
|
||||
* @deprecated In favor of WCS_Report_Subscription_By_Product
|
||||
*/
|
||||
class WC_Report_Subscription_By_Product extends WCS_Report_Subscription_By_Product {
|
||||
public function __construct() {
|
||||
wcs_deprecated_function( __CLASS__, '2.4.0', get_parent_class( __CLASS__ ) );
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Subscriptions Admin Report - Subscription Events by Date
|
||||
*
|
||||
* Display important historical data for subscription revenue and events, like switches and cancellations.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin_Reports
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.1
|
||||
* @deprecated In favor of WCS_Report_Subscription_Events_By_Date
|
||||
*/
|
||||
class WC_Report_Subscription_Events_By_Date extends WCS_Report_Subscription_Events_By_Date {
|
||||
public function __construct() {
|
||||
wcs_deprecated_function( __CLASS__, '2.4.0', get_parent_class( __CLASS__ ) );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Subscriptions Admin Report - Subscription Events by Date
|
||||
*
|
||||
* Creates the subscription admin reports area.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin_Reports
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.1
|
||||
* @deprecated In favor of WCS_Report_Subscription_Payment_Retry
|
||||
*/
|
||||
class WC_Report_Subscription_Payment_Retry extends WCS_Report_Subscription_Payment_Retry {
|
||||
public function __construct() {
|
||||
wcs_deprecated_function( __CLASS__, '2.4.0', get_parent_class( __CLASS__ ) );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Subscriptions Admin Report - Upcoming Recurring Revenue
|
||||
*
|
||||
* Display the renewal order count and revenue that will be processed for all currently active subscriptions
|
||||
* for a given period of time in the future.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin_Reports
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.1
|
||||
* @deprecated In favor of WCS_Report_Upcoming_Recurring_Revenue
|
||||
*/
|
||||
class WC_Report_Upcoming_Recurring_Revenue extends WCS_Report_Upcoming_Recurring_Revenue {
|
||||
public function __construct() {
|
||||
wcs_deprecated_function( __CLASS__, '2.4.0', get_parent_class( __CLASS__ ) );
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ class WC_REST_Subscription_System_Status_Manager {
|
|||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function add_subscription_fields_to_response( $response ) {
|
||||
$count_by_status = array_filter( (array) WC_Data_Store::load( 'subscription' )->get_subscriptions_count_by_status() );
|
||||
$count_by_status = WCS_Admin_System_Status::get_subscription_status_counts();
|
||||
|
||||
$response->data['subscriptions'] = array(
|
||||
'wcs_debug' => defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false,
|
||||
|
|
@ -79,6 +79,7 @@ class WC_REST_Subscription_System_Status_Manager {
|
|||
private static function get_payment_gateway_feature_support() {
|
||||
$gateway_features = array();
|
||||
|
||||
// @phpstan-ignore property.notFound
|
||||
foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway_id => $gateway ) {
|
||||
// Some gateways include array keys. For consistency, only send the values.
|
||||
$gateway_features[ $gateway_id ] = array_values( (array) apply_filters( 'woocommerce_subscriptions_payment_gateway_features_list', $gateway->supports, $gateway ) );
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
* -- Subscription specific --
|
||||
* GET /subscriptions/status
|
||||
* GET /subscriptions/<subscription_id>/orders
|
||||
* GET /orders/<order_id>/subscriptions
|
||||
* POST /orders/<order_id>/subscriptions
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
|
|
@ -60,6 +62,26 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
"/orders/(?P<id>[\d]+)/{$this->rest_base}",
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_order_subscriptions' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_subscriptions_from_order' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,7 +106,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param WC_Data $object Subscription object.
|
||||
* @param WC_Subscription $object Subscription object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
|
|
@ -97,8 +119,11 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
}
|
||||
|
||||
// Add subscription specific data to the base order response data.
|
||||
$response->data['billing_period'] = $object->get_billing_period();
|
||||
$response->data['billing_interval'] = $object->get_billing_interval();
|
||||
$response->data['billing_period'] = $object->get_billing_period();
|
||||
$response->data['billing_interval'] = $object->get_billing_interval();
|
||||
$response->data['trial_period'] = $object->get_trial_period();
|
||||
$response->data['suspension_count'] = $object->get_suspension_count();
|
||||
$response->data['requires_manual_renewal'] = $object->get_requires_manual_renewal();
|
||||
|
||||
foreach ( wcs_get_subscription_date_types() as $date_type => $date_name ) {
|
||||
$date = $object->get_date( wcs_normalise_date_type_key( $date_type ) );
|
||||
|
|
@ -193,6 +218,76 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
return apply_filters( 'wcs_rest_subscription_orders_response', $response, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the /orders/[id]/subscriptions response.
|
||||
*
|
||||
* @since 7.9.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
* @return WP_Error|WP_REST_Response $response The response or an error if one occurs.
|
||||
*/
|
||||
public function get_order_subscriptions( $request ) {
|
||||
$order_id = absint( $request['id'] );
|
||||
|
||||
if ( empty( $order_id ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( ! $order ) {
|
||||
return new WP_Error(
|
||||
'woocommerce_rest_invalid_order_id',
|
||||
// translators: %d is the order ID.
|
||||
sprintf( __( 'Failed to load order object with the ID %d.', 'woocommerce-subscriptions' ), $order_id ),
|
||||
array( 'status' => 404 )
|
||||
);
|
||||
}
|
||||
|
||||
// Build arguments for wcs_get_subscriptions_for_order()x
|
||||
$args = array(
|
||||
'order_type' => 'any', // Return all subscriptions for the order.
|
||||
);
|
||||
|
||||
// Set arguments from request.
|
||||
if ( ! empty( $request['orderby'] ) ) {
|
||||
$args['orderby'] = $request['orderby'];
|
||||
}
|
||||
|
||||
if ( ! empty( $request['order'] ) ) {
|
||||
$args['order'] = $request['order'];
|
||||
}
|
||||
|
||||
// Map standard request parameters to wcs_get_subscriptions_for_order() arguments.
|
||||
if ( ! empty( $request['customer'] ) ) {
|
||||
$args['customer_id'] = $request['customer'];
|
||||
}
|
||||
|
||||
if ( ! empty( $request['status'] ) ) {
|
||||
$args['subscription_status'] = $request['status'];
|
||||
}
|
||||
|
||||
$subscriptions = wcs_get_subscriptions_for_order( $order, $args );
|
||||
|
||||
$response_data = array();
|
||||
|
||||
foreach ( $subscriptions as $subscription ) {
|
||||
if ( is_a( $subscription, 'WC_Subscription' ) && ! wc_rest_check_post_permissions( 'shop_subscription', 'read', $subscription->get_id() ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response = $this->prepare_object_for_response( $subscription, $request );
|
||||
$response_data[] = $this->prepare_response_for_collection( $response );
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $response_data );
|
||||
// Pagination is not fully supported, so we manually set the total.
|
||||
$response->header( 'X-WP-Total', count( $response_data ) );
|
||||
$response->header( 'X-WP-TotalPages', 1 );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides WC_REST_Orders_Controller::get_order_statuses() so that subscription statuses are
|
||||
* validated correctly.
|
||||
|
|
@ -231,11 +326,6 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
$payment_meta = array();
|
||||
$dates = array();
|
||||
|
||||
// If the start date is not set in the request, set its default to now.
|
||||
if ( ! isset( $request['start_date'] ) ) {
|
||||
$request['start_date'] = gmdate( 'Y-m-d H:i:s' );
|
||||
}
|
||||
|
||||
// Both setting (set_status()) and updating (update_status()) are valid ways for requests to set a subscription's status.
|
||||
$status_transition = 'set';
|
||||
|
||||
|
|
@ -261,7 +351,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
$this->update_address( $subscription, $value, $key );
|
||||
break;
|
||||
case 'start_date':
|
||||
case 'trial_end':
|
||||
case 'trial_end_date':
|
||||
case 'next_payment_date':
|
||||
case 'cancelled_date':
|
||||
case 'end_date':
|
||||
|
|
@ -312,8 +402,8 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
}
|
||||
|
||||
if ( ! empty( $dates ) ) {
|
||||
// If the start date is not set in the request when a subscription is created with an active status, set its default to now.
|
||||
if ( 'active' === $status && empty( $id ) && ! isset( $dates['start_date'] ) ) {
|
||||
// If the start date is not set in the request when a subscription is being created, set its default to now.
|
||||
if ( empty( $id ) && ! isset( $dates['start_date'] ) ) {
|
||||
$dates['start_date'] = gmdate( 'Y-m-d H:i:s' );
|
||||
}
|
||||
|
||||
|
|
@ -391,6 +481,22 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
'enum' => array_keys( wcs_get_subscription_period_strings() ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'trial_period' => array(
|
||||
'description' => __( 'Trial period for the subscription.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( wcs_get_subscription_period_strings() ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'suspension_count' => array(
|
||||
'description' => __( 'The number of times the subscription has been suspended since the last payment.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'requires_manual_renewal' => array(
|
||||
'description' => __( 'Whether the subscription requires manual renewal.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'payment_details' => array(
|
||||
'description' => __( 'Subscription payment details.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'object',
|
||||
|
|
@ -413,8 +519,8 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'trial_date' => array(
|
||||
'description' => __( "The subscription's trial date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'trial_end_date' => array(
|
||||
'description' => __( "The subscription's trial end date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
|
|
@ -512,4 +618,205 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
throw new WC_REST_Exception( 'woocommerce_rest_invalid_payment_data', sprintf( __( 'Subscription payment method could not be set to %1$s with error message: %2$s', 'woocommerce-subscriptions' ), $payment_method, $e->getMessage() ), 400 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates subscriptions from an order.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @return array Subscriptions created from the order.
|
||||
*/
|
||||
public function create_subscriptions_from_order( $request ) {
|
||||
$order_id = absint( $request->get_param( 'id' ) );
|
||||
|
||||
if ( empty( $order_id ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( ! $order || ! wcs_is_order( $order ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_order_invalid_id', sprintf( __( 'Failed to load order object with the ID %d.', 'woocommerce-subscriptions' ), $order_id ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
if ( ! $order->get_customer_id() ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order does not have a customer associated with it. Subscriptions require a customer.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
if ( wcs_order_contains_subscription( $order, 'any' ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order already has subscriptions associated with it.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$subscription_groups = [];
|
||||
$subscriptions = [];
|
||||
|
||||
// Group the order items into subscription groups.
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( ! WC_Subscriptions_Product::is_subscription( $product ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subscription_groups[ wcs_get_subscription_item_grouping_key( $item ) ][] = $item;
|
||||
}
|
||||
|
||||
// Return a 204 if there are no subscriptions to be created.
|
||||
if ( empty( $subscription_groups ) ) {
|
||||
$response = rest_ensure_response( $subscriptions );
|
||||
$response->set_status( 204 );
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start creating any subscriptions start transaction if available.
|
||||
*
|
||||
* To ensure data integrity, if any subscription fails to be created, the transaction will be rolled back. This will enable
|
||||
* the client to resubmit the request without having to worry about duplicate subscriptions being created.
|
||||
*/
|
||||
$transaction = new WCS_SQL_Transaction();
|
||||
$transaction->start();
|
||||
|
||||
try {
|
||||
// Create subscriptions.
|
||||
foreach ( $subscription_groups as $items ) {
|
||||
// Get the first item in the group to use as the base for the subscription.
|
||||
$product = $items[0]->get_product();
|
||||
$start_date = wcs_get_datetime_utc_string( $order->get_date_created( 'edit' ) );
|
||||
$subscription = wcs_create_subscription( [
|
||||
'order_id' => $order_id,
|
||||
'created_via' => 'rest-api',
|
||||
'start_date' => $start_date,
|
||||
'status' => $order->is_paid() ? 'active' : 'pending',
|
||||
'billing_period' => WC_Subscriptions_Product::get_period( $product ),
|
||||
'billing_interval' => WC_Subscriptions_Product::get_interval( $product ),
|
||||
'customer_note' => $order->get_customer_note(),
|
||||
] );
|
||||
|
||||
if ( is_wp_error( $subscription ) ) {
|
||||
throw new Exception( $subscription->get_error_message() );
|
||||
}
|
||||
|
||||
wcs_copy_order_address( $order, $subscription );
|
||||
|
||||
$subscription->update_dates(
|
||||
array(
|
||||
'trial_end' => WC_Subscriptions_Product::get_trial_expiration_date( $product, $start_date ),
|
||||
'next_payment' => WC_Subscriptions_Product::get_first_renewal_payment_date( $product, $start_date ),
|
||||
'end' => WC_Subscriptions_Product::get_expiration_date( $product, $start_date ),
|
||||
)
|
||||
);
|
||||
|
||||
$subscription->set_payment_method( $order->get_payment_method() );
|
||||
|
||||
wcs_copy_order_meta( $order, $subscription, 'subscription' );
|
||||
|
||||
// Add items.
|
||||
$subscription_needs_shipping = false;
|
||||
foreach ( $items as $item ) {
|
||||
// Create order line item.
|
||||
$item_id = wc_add_order_item(
|
||||
$subscription->get_id(),
|
||||
[
|
||||
'order_item_name' => $item->get_name(),
|
||||
'order_item_type' => $item->get_type(),
|
||||
]
|
||||
);
|
||||
|
||||
$subscription_item = $subscription->get_item( $item_id );
|
||||
|
||||
wcs_copy_order_item( $item, $subscription_item );
|
||||
|
||||
// Don't include sign-up fees or $0 trial periods when setting the subscriptions item totals.
|
||||
wcs_set_recurring_item_total( $subscription_item );
|
||||
|
||||
$subscription_item->save();
|
||||
|
||||
// Check if this subscription will need shipping.
|
||||
if ( ! $subscription_needs_shipping ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( $product ) {
|
||||
$subscription_needs_shipping = $product->needs_shipping() && ! WC_Subscriptions_Product::needs_one_time_shipping( $product );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add coupons.
|
||||
foreach ( $order->get_coupons() as $coupon_item ) {
|
||||
$coupon = new WC_Coupon( $coupon_item->get_code() );
|
||||
|
||||
try {
|
||||
// validate_subscription_coupon_for_order will throw an exception if the coupon cannot be applied to the subscription.
|
||||
WC_Subscriptions_Coupon::validate_subscription_coupon_for_order( true, $coupon, $subscription );
|
||||
|
||||
$subscription->apply_coupon( $coupon->get_code() );
|
||||
} catch ( Exception $e ) {
|
||||
// Do nothing. The coupon will not be applied to the subscription.
|
||||
}
|
||||
}
|
||||
|
||||
// Add shipping.
|
||||
if ( $subscription_needs_shipping ) {
|
||||
foreach ( $order->get_shipping_methods() as $shipping_item ) {
|
||||
$rate = new WC_Shipping_Rate( $shipping_item->get_method_id(), $shipping_item->get_method_title(), $shipping_item->get_total(), $shipping_item->get_taxes(), $shipping_item->get_instance_id() );
|
||||
|
||||
$item = new WC_Order_Item_Shipping();
|
||||
$item->set_order_id( $subscription->get_id() );
|
||||
$item->set_shipping_rate( $rate );
|
||||
|
||||
$subscription->add_item( $item );
|
||||
}
|
||||
}
|
||||
|
||||
// Add fees.
|
||||
foreach ( $order->get_fees() as $fee_item ) {
|
||||
if ( ! apply_filters( 'wcs_should_copy_fee_item_to_subscription', true, $fee_item, $subscription, $order ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item = new WC_Order_Item_Fee();
|
||||
$item->set_props(
|
||||
array(
|
||||
'name' => $fee_item->get_name(),
|
||||
'tax_class' => $fee_item->get_tax_class(),
|
||||
'amount' => $fee_item->get_amount(),
|
||||
'total' => $fee_item->get_total(),
|
||||
'total_tax' => $fee_item->get_total_tax(),
|
||||
'taxes' => $fee_item->get_taxes(),
|
||||
)
|
||||
);
|
||||
|
||||
$subscription->add_item( $item );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fetch a fresh instance of the subscription because the current instance has an empty line item cache generated before we had copied the line items.
|
||||
* Fetching a new instance will ensure the line items are used when calculating totals.
|
||||
*/
|
||||
$subscription = wcs_get_subscription( $subscription->get_id() );
|
||||
$subscription->calculate_totals();
|
||||
|
||||
/**
|
||||
* Fires after a single subscription is created or updated via the REST API.
|
||||
*
|
||||
* @param WC_Subscription $object Inserted subscription.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param boolean $creating True when creating object, false when updating.
|
||||
*/
|
||||
do_action( "woocommerce_rest_insert_{$this->post_type}_object", $subscription, $request, true );
|
||||
|
||||
$response = $this->prepare_object_for_response( wcs_get_subscription( $subscription->get_id() ), $request );
|
||||
$subscriptions[] = $this->prepare_response_for_collection( $response );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback();
|
||||
return new WP_Error( 'woocommerce_rest_invalid_subscription_data', $e->getMessage(), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
// If we got here, the subscription was created without problems
|
||||
$transaction->commit();
|
||||
|
||||
return rest_ensure_response( $subscriptions );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* Class WC_REST_Subscriptions_Settings_Option_Controller
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST controller for settings options.
|
||||
*/
|
||||
class WC_REST_Subscriptions_Settings_Option_Controller extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v3';
|
||||
|
||||
/**
|
||||
* List of allowed option names that can be updated via the REST API.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private const ALLOWED_OPTIONS = [
|
||||
'woocommerce_subscriptions_gifting_is_welcome_announcement_dismissed',
|
||||
'woocommerce_subscriptions_downloads_is_welcome_announcement_dismissed',
|
||||
];
|
||||
|
||||
/**
|
||||
* Endpoint path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'subscriptions/settings';
|
||||
|
||||
/**
|
||||
* Configure REST API routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<option_name>[a-zA-Z0-9_-]+)',
|
||||
[
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => [ $this, 'update_option' ],
|
||||
'permission_callback' => [ $this, 'check_permission' ],
|
||||
'args' => [
|
||||
'option_name' => [
|
||||
'required' => true,
|
||||
'validate_callback' => [ $this, 'validate_option_name' ],
|
||||
],
|
||||
'value' => [
|
||||
'required' => true,
|
||||
'validate_callback' => [ $this, 'validate_value' ],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the option name.
|
||||
*
|
||||
* @param string $option_name The option name to validate.
|
||||
* @return bool
|
||||
*/
|
||||
public function validate_option_name( string $option_name ): bool {
|
||||
return in_array( $option_name, self::ALLOWED_OPTIONS, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the value parameter.
|
||||
*
|
||||
* @param mixed $value The value to validate.
|
||||
* @return bool|WP_Error True if valid, WP_Error if invalid.
|
||||
*/
|
||||
public function validate_value( $value ) {
|
||||
if ( is_bool( $value ) || is_array( $value ) ) {
|
||||
return true;
|
||||
}
|
||||
return new WP_Error(
|
||||
'rest_invalid_param',
|
||||
__( 'Invalid value type; must be either boolean or array', 'woocommerce-subscriptions' ),
|
||||
[ 'status' => 400 ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the option value.
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function update_option( WP_REST_Request $request ) {
|
||||
$option_name = $request->get_param( 'option_name' );
|
||||
$value = $request->get_param( 'value' );
|
||||
|
||||
update_option( $option_name, $value );
|
||||
|
||||
return rest_ensure_response(
|
||||
[
|
||||
'success' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify access.
|
||||
*
|
||||
* Override this method if custom permissions required.
|
||||
*/
|
||||
public function check_permission() {
|
||||
return current_user_can( 'manage_woocommerce' );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC REST API Subscriptions Settings class.
|
||||
*
|
||||
* Adds subscription settings to the wc/<version>/settings and wc/<version>/settings/{group_id} endpoint.
|
||||
*/
|
||||
class WC_REST_Subscriptions_Settings {
|
||||
|
||||
/**
|
||||
* Init class and attach callbacks.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'woocommerce_settings_groups', [ $this, 'add_settings_group' ] );
|
||||
add_filter( 'woocommerce_settings-subscriptions', [ $this, 'add_settings' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the subscriptions settings group for use in the WC REST API /settings endpoint
|
||||
*
|
||||
* @param array $groups Array of setting groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_settings_group( $groups ) {
|
||||
$groups[] = [
|
||||
'id' => 'subscriptions',
|
||||
'label' => __( 'Subscriptions', 'woocommerce-subscriptions' ),
|
||||
];
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add subscriptions specific settings to the WC REST API /settings/subscriptions endpoint.
|
||||
*
|
||||
* @param array $settings Array of settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_settings( $settings ) {
|
||||
$subscription_settings = WC_Subscriptions_Admin::get_settings();
|
||||
|
||||
foreach( $subscription_settings as $setting ) {
|
||||
// Skip settings that don't have a id, type or are an invalid setting type i.e. skip over title, sectionend, etc.
|
||||
if ( empty( $setting['id'] ) || empty( $setting['type'] ) || ! $this->is_setting_type_valid( $setting['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$settings[] = $this->format_setting( $setting );
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a setting type is a valid supported setting type.
|
||||
*
|
||||
* @param string $type Type.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_setting_type_valid( $type ) {
|
||||
return in_array( $type, [ 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'checkbox', 'image_width', 'thumbnail_cropping' ], true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subscriptions setting in the format expected by the WC /settings REST API.
|
||||
*
|
||||
* @param array $setting Subscription setting.
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
private function format_setting( $setting ) {
|
||||
$description = '';
|
||||
|
||||
if ( ! empty( $setting['desc'] ) ) {
|
||||
$description = $setting['desc'];
|
||||
} elseif ( ! empty( $setting['description'] ) ) {
|
||||
$description = $setting['description'];
|
||||
}
|
||||
|
||||
$new_setting = [
|
||||
'id' => $setting['id'],
|
||||
'label' => ! empty( $setting['title'] ) ? $setting['title'] : '',
|
||||
'description' => $description,
|
||||
'type' => $setting['type'],
|
||||
'option_key' => $setting['id'],
|
||||
'default' => ! empty( $setting['default'] ) ? $setting['default'] : '',
|
||||
];
|
||||
|
||||
if ( isset( $setting['options'] ) ) {
|
||||
$new_setting['options'] = $setting['options'];
|
||||
}
|
||||
|
||||
if ( isset( $setting['desc_tip'] ) ) {
|
||||
if ( true === $setting['desc_tip'] ) {
|
||||
$new_setting['tip'] = $description;
|
||||
} elseif ( ! empty( $setting['desc_tip'] ) ) {
|
||||
$new_setting['tip'] = $setting['desc_tip'];
|
||||
}
|
||||
}
|
||||
|
||||
return $new_setting;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* REST API Subscription Notes controller class.
|
||||
*
|
||||
* @package WooCommerce_Subscriptions/API
|
||||
* @extends WC_REST_Order_Notes_Controller
|
||||
*/
|
||||
class WC_REST_Subscription_Notes_Controller extends WC_REST_Order_Notes_Controller {
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* REST API Subscriptions controller class.
|
||||
*
|
||||
* @package WooCommerce_Subscriptions/API
|
||||
* @extends WC_REST_Orders_Controller
|
||||
*/
|
||||
class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
*
|
||||
* @since 2.1
|
||||
* @param WP_REST_Response $response
|
||||
* @param WP_POST $post
|
||||
* @param WP_Post $post
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public function filter_get_subscription_response( $response, $post, $request ) {
|
||||
|
|
@ -123,7 +122,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
|||
*
|
||||
* @since 2.1
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_POST $post
|
||||
* @param WP_Post $post
|
||||
*/
|
||||
protected function update_order( $request, $post ) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* REST API Subscription Notes controller class.
|
||||
*
|
||||
* @package WooCommerce_Subscriptions/API
|
||||
* @extends WC_REST_Order_Notes_Controller
|
||||
*/
|
||||
class WC_REST_Subscription_Notes_V1_Controller extends WC_REST_Order_Notes_V1_Controller {
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* REST API Subscriptions controller class.
|
||||
*
|
||||
* @package WooCommerce_Subscriptions/API
|
||||
* @extends WC_REST_Orders_Controller
|
||||
*/
|
||||
class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
|||
*
|
||||
* @since 2.1
|
||||
* @param WP_REST_Response $response
|
||||
* @param WP_POST $post
|
||||
* @param WP_Post $post
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public function filter_get_subscription_response( $response, $post, $request ) {
|
||||
|
|
@ -84,6 +83,10 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
|||
if ( ! empty( $post->post_type ) && ! empty( $post->ID ) && 'shop_subscription' == $post->post_type ) {
|
||||
$subscription = wcs_get_subscription( $post->ID );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->data['billing_period'] = $subscription->get_billing_period();
|
||||
$response->data['billing_interval'] = $subscription->get_billing_interval();
|
||||
|
||||
|
|
@ -232,7 +235,6 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
|||
*
|
||||
* @since 2.1
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_POST $post
|
||||
*/
|
||||
protected function update_order( $request ) {
|
||||
try {
|
||||
|
|
@ -294,8 +296,13 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
|||
return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription id.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$this->post_type = 'shop_order';
|
||||
$subscription = wcs_get_subscription( $id );
|
||||
$this->post_type = 'shop_order';
|
||||
$subscription = wcs_get_subscription( $id );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription id.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$subscription_orders = $subscription->get_related_orders();
|
||||
|
||||
$orders = array();
|
||||
|
|
@ -373,6 +380,10 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
|||
// In particular, the update_post_meta() called while _stripe_card_id is updated to _stripe_source_id
|
||||
$subscription = wcs_get_subscription( $subscription->get_id() );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
throw new WC_REST_Exception( 'woocommerce_rest_payment_update_failed', __( 'Subscription payment method could not be set updated due to technical issues.', 'woocommerce-subscriptions' ), 500 );
|
||||
}
|
||||
|
||||
if ( isset( $payment_method_meta[ $payment_method ] ) ) {
|
||||
$payment_method_meta = $payment_method_meta[ $payment_method ];
|
||||
|
||||
|
|
@ -707,78 +718,4 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
|||
$schema['properties'] += $subscriptions_schema;
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prepare subscription data for create.
|
||||
*
|
||||
* Now that we override WC_REST_Orders_V1_Controller::prepare_item_for_database() function,
|
||||
* we no longer need to prepare these args
|
||||
*
|
||||
* @since 2.1
|
||||
* @param stdClass $data
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return stdClass
|
||||
* @deprecated 2.2
|
||||
*/
|
||||
public function prepare_subscription_args( $data, $request ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.2' );
|
||||
|
||||
$data->billing_interval = $request['billing_interval'];
|
||||
$data->billing_period = $request['billing_period'];
|
||||
|
||||
foreach ( array( 'start', 'trial_end', 'end', 'next_payment' ) as $date_type ) {
|
||||
if ( ! empty( $request[ $date_type . '_date' ] ) ) {
|
||||
$date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type . '_date';
|
||||
$data->{$date_type_key} = $request[ $date_type . '_date' ];
|
||||
}
|
||||
}
|
||||
|
||||
$data->payment_details = ! empty( $request['payment_details'] ) ? $request['payment_details'] : '';
|
||||
$data->payment_method = ! empty( $request['payment_method'] ) ? $request['payment_method'] : '';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or set the subscription schedule with the request data.
|
||||
*
|
||||
*
|
||||
* @since 2.1
|
||||
* @param WC_Subscription $subscription
|
||||
* @param array $data
|
||||
* @deprecated 2.2
|
||||
*/
|
||||
public function update_schedule( $subscription, $data ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.2', 'WC_REST_Subscriptions_Controller::prepare_item_for_database() now prepares the billing interval/period and dates' );
|
||||
|
||||
if ( isset( $data['billing_interval'] ) ) {
|
||||
$subscription->set_billing_interval( absint( $data['billing_interval'] ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $data['billing_period'] ) ) {
|
||||
$subscription->set_billing_period( $data['billing_period'] );
|
||||
}
|
||||
|
||||
try {
|
||||
$dates_to_update = array();
|
||||
|
||||
foreach ( array( 'start', 'trial_end', 'end', 'next_payment' ) as $date_type ) {
|
||||
if ( isset( $data[ $date_type . '_date' ] ) ) {
|
||||
$date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type;
|
||||
$dates_to_update[ $date_type_key ] = $data[ $date_type . '_date' ];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $dates_to_update ) ) {
|
||||
$subscription->update_dates( $dates_to_update );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
// translators: placeholder is an error message.
|
||||
throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_subscription_dates', sprintf( __( 'Updating subscription dates errored with message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API subscription notes controller
|
||||
*
|
||||
* Handles requests to the /subscription/<id>/notes endpoint.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
/**
|
||||
* REST API Subscription Notes controller class.
|
||||
*
|
||||
* @package WooCommerce_Subscriptions/API
|
||||
*/
|
||||
class WC_REST_Subscription_Notes_V2_Controller extends WC_REST_Order_Notes_V2_Controller {
|
||||
|
||||
/**
|
||||
* Route base.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = 'subscriptions/(?P<order_id>[\d]+)/notes';
|
||||
|
||||
/**
|
||||
* Post type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $post_type = 'shop_subscription';
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,797 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API Subscriptions V2 Controller
|
||||
*
|
||||
* Handles requests to the wc/v2/subscriptions and wc/v2/orders/ID/subscriptions endpoint.
|
||||
*
|
||||
* @since 6.4.0
|
||||
* @package WooCommerce Subscriptions\Rest Api
|
||||
*/
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class WC_REST_Subscriptions_V2_Controller extends WC_REST_Orders_V2_Controller {
|
||||
|
||||
/**
|
||||
* @var string Route base.
|
||||
*/
|
||||
protected $rest_base = 'subscriptions';
|
||||
|
||||
/**
|
||||
* @var string The post type.
|
||||
*/
|
||||
protected $post_type = 'shop_subscription';
|
||||
|
||||
/**
|
||||
* Register the routes for the subscriptions endpoint.
|
||||
*
|
||||
* GET|POST /subscriptions
|
||||
* GET|PUT|DELETE /subscriptions/<subscription_id>
|
||||
* GET /subscriptions/status
|
||||
* GET /subscriptions/<subscription_id>/orders
|
||||
* POST /orders/<order_id>/subscriptions
|
||||
*
|
||||
* @since 6.4.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
parent::register_routes();
|
||||
|
||||
register_rest_route( $this->namespace, "/{$this->rest_base}/statuses", [ // nosemgrep: audit.php.wp.security.rest-route.permission-callback.return-true -- /subscriptions/statuses is a public endpoint and doesn't need any permission checks.
|
||||
[
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => [ $this, 'get_statuses' ],
|
||||
'permission_callback' => '__return_true',
|
||||
],
|
||||
'schema' => [ $this, 'get_statuses_schema' ],
|
||||
] );
|
||||
|
||||
register_rest_route( $this->namespace, "/{$this->rest_base}/(?P<id>[\d]+)/orders", [
|
||||
[
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => [ $this, 'get_subscription_orders' ],
|
||||
'permission_callback' => [ $this, 'get_items_permissions_check' ],
|
||||
'args' => $this->get_collection_params(),
|
||||
],
|
||||
'schema' => [ $this, 'get_subscription_orders_schema' ],
|
||||
] );
|
||||
|
||||
register_rest_route( $this->namespace, "/orders/(?P<id>[\d]+)/{$this->rest_base}", [
|
||||
[
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => [ $this, 'create_subscriptions_from_order' ],
|
||||
'permission_callback' => [ $this, 'create_item_permissions_check' ],
|
||||
'args' => $this->get_collection_params(),
|
||||
],
|
||||
'schema' => [ $this, 'create_subscriptions_from_order_schema' ],
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request object. Return false if the ID is not a subscription.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param int $id Object ID.
|
||||
*
|
||||
* @return WC_Subscription|bool
|
||||
*/
|
||||
protected function get_object( $id ) {
|
||||
$subscription = wcs_get_subscription( $id );
|
||||
|
||||
if ( ! $subscription || ! is_a( $subscription, 'WC_Subscription' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $subscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a single subscription output for response.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param WC_Subscription $object Subscription object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$response = parent::prepare_object_for_response( $object, $request );
|
||||
|
||||
// When generating the `/subscriptions/[id]/orders` response this function is called to generate related-order data so exit early if this isn't a subscription.
|
||||
if ( ! wcs_is_subscription( $object ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Add subscription specific data to the base order response data.
|
||||
$response->data['billing_period'] = $object->get_billing_period();
|
||||
$response->data['billing_interval'] = $object->get_billing_interval();
|
||||
|
||||
foreach ( wcs_get_subscription_date_types() as $date_type => $date_name ) {
|
||||
$date = $object->get_date( wcs_normalise_date_type_key( $date_type ) );
|
||||
$response->data[ $date_type . '_date' ] = ( ! empty( $date ) ) ? wc_rest_prepare_date_response( $date, false ) : '';
|
||||
$response->data[ $date_type . '_date_gmt' ] = ( ! empty( $date ) ) ? wc_rest_prepare_date_response( $date ) : '';
|
||||
}
|
||||
|
||||
// Some base WC_Order dates need to be pulled from the subscription object to be correct.
|
||||
$response->data['date_paid'] = wc_rest_prepare_date_response( $object->get_date_paid(), false );
|
||||
$response->data['date_paid_gmt'] = wc_rest_prepare_date_response( $object->get_date_paid() );
|
||||
$response->data['date_completed'] = wc_rest_prepare_date_response( $object->get_date_completed(), false );
|
||||
$response->data['date_completed_gmt'] = wc_rest_prepare_date_response( $object->get_date_completed() );
|
||||
|
||||
// Include resubscribe data.
|
||||
$resubscribed_subscriptions = array_filter( $object->get_related_orders( 'ids', 'resubscribe' ), 'wcs_is_subscription' );
|
||||
$response->data['resubscribed_from'] = strval( $object->get_meta( '_subscription_resubscribe' ) );
|
||||
$response->data['resubscribed_subscription'] = strval( reset( $resubscribed_subscriptions ) ); // Subscriptions can only be resubscribed to once so return the first and only element.
|
||||
|
||||
// Include the removed line items.
|
||||
$response->data['removed_line_items'] = [];
|
||||
|
||||
foreach ( $object->get_items( 'line_item_removed' ) as $item ) {
|
||||
$response->data['removed_line_items'][] = $this->get_order_item_data( $item );
|
||||
}
|
||||
|
||||
// Remove non-subscription properties
|
||||
unset( $response->data['cart_hash'] );
|
||||
unset( $response->data['transaction_id'] );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the /subscriptions/statuses response.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @return WP_REST_Response The response object.
|
||||
*/
|
||||
public function get_statuses() {
|
||||
return rest_ensure_response( wcs_get_subscription_statuses() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the /subscriptions/[id]/orders response.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return WP_Error|WP_REST_Response $response The response or an error if one occurs.
|
||||
*/
|
||||
public function get_subscription_orders( $request ) {
|
||||
$id = absint( $request['id'] );
|
||||
|
||||
if ( empty( $id ) || ! wcs_is_subscription( $id ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription ID.', 'woocommerce-subscriptions' ), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
$subscription = wcs_get_subscription( $id );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', sprintf( __( 'Failed to load subscription object with the ID %d.', 'woocommerce-subscriptions' ), $id ), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
$orders = [];
|
||||
|
||||
foreach ( [ 'parent', 'renewal', 'switch' ] as $order_type ) {
|
||||
foreach ( $subscription->get_related_orders( 'ids', $order_type ) as $order_id ) {
|
||||
|
||||
if ( ! wc_rest_check_post_permissions( 'shop_order', 'read', $order_id ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate that the order can be loaded before trying to generate a response object for it.
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( ! $order ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response = parent::prepare_object_for_response( $order, $request );
|
||||
|
||||
// Add the order's relationship to the response.
|
||||
$response->data['order_type'] = $order_type . '_order';
|
||||
|
||||
$orders[] = $this->prepare_response_for_collection( $response );
|
||||
}
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $orders );
|
||||
$response->header( 'X-WP-Total', count( $orders ) );
|
||||
$response->header( 'X-WP-TotalPages', 1 );
|
||||
|
||||
return apply_filters( 'wcs_rest_subscription_orders_response', $response, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides WC_REST_Orders_V2_Controller::get_order_statuses() so that subscription statuses are
|
||||
* validated correctly.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @return array An array of valid subscription statuses.
|
||||
*/
|
||||
protected function get_order_statuses() {
|
||||
$subscription_statuses = [];
|
||||
|
||||
foreach ( wcs_get_subscription_statuses() as $status => $status_name ) {
|
||||
$subscription_statuses[] = str_replace( 'wc-', '', $status );
|
||||
}
|
||||
|
||||
return $subscription_statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a single subscription for creation or update.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param bool $creating If the request is for creating a new object.
|
||||
*
|
||||
* @return WP_Error|WC_Subscription
|
||||
*/
|
||||
public function prepare_object_for_database( $request, $creating = false ) {
|
||||
$id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
|
||||
$subscription = new WC_Subscription( $id );
|
||||
$schema = $this->get_item_schema();
|
||||
$data_keys = array_keys( array_filter( $schema['properties'], [ $this, 'filter_writable_props' ] ) );
|
||||
|
||||
// Prepare variables for properties which need to be saved late (like status) or in a group (dates and payment data).
|
||||
$status = '';
|
||||
$payment_method = '';
|
||||
$payment_meta = [];
|
||||
$dates = [];
|
||||
|
||||
// Both setting (set_status()) and updating (update_status()) are valid ways for requests to set a subscription's status.
|
||||
$status_transition = 'set';
|
||||
|
||||
foreach ( $data_keys as $i => $key ) {
|
||||
$value = $request[ $key ];
|
||||
|
||||
if ( is_null( $value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ( $key ) {
|
||||
case 'parent_id':
|
||||
$subscription->set_parent_id( $value );
|
||||
break;
|
||||
case 'transition_status':
|
||||
$status_transition = 'update';
|
||||
case 'status':
|
||||
// This needs to be done later so status changes take into account other data like dates.
|
||||
$status = $value;
|
||||
break;
|
||||
case 'billing':
|
||||
case 'shipping':
|
||||
$this->update_address( $subscription, $value, $key );
|
||||
break;
|
||||
case 'start_date':
|
||||
case 'trial_end_date':
|
||||
case 'next_payment_date':
|
||||
case 'cancelled_date':
|
||||
case 'end_date':
|
||||
// Group all the subscription date properties so they can be validated together.
|
||||
$dates[ $key ] = $value;
|
||||
break;
|
||||
case 'payment_method':
|
||||
$payment_method = $value;
|
||||
break;
|
||||
case 'payment_details':
|
||||
// Format the value in a way payment gateways expect so it can be validated.
|
||||
$payment_meta = $value;
|
||||
break;
|
||||
case 'line_items':
|
||||
case 'shipping_lines':
|
||||
case 'fee_lines':
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $item ) {
|
||||
if ( is_array( $item ) ) {
|
||||
if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
|
||||
if ( isset( $item['id'] ) ) {
|
||||
$subscription->remove_item( $item['id'] );
|
||||
}
|
||||
} else {
|
||||
$this->set_item( $subscription, $key, $item );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'meta_data':
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $meta ) {
|
||||
$subscription->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ( is_callable( [ $subscription, "set_{$key}" ] ) ) {
|
||||
$subscription->{"set_{$key}"}( $value );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $payment_method ) ) {
|
||||
$this->update_payment_method( $subscription, $payment_method, $payment_meta );
|
||||
}
|
||||
|
||||
if ( ! empty( $dates ) ) {
|
||||
// If the start date is not set in the request when a subscription is being created, set its default to now.
|
||||
if ( empty( $id ) && ! isset( $dates['start_date'] ) ) {
|
||||
$dates['start_date'] = gmdate( 'Y-m-d H:i:s' );
|
||||
}
|
||||
|
||||
try {
|
||||
$subscription->update_dates( $dates );
|
||||
} catch ( Exception $e ) {
|
||||
throw new WC_REST_Exception( 'woocommerce_rest_invalid_payment_data', sprintf( __( 'Subscription dates could not be set. Error message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $status ) ) {
|
||||
if ( 'set' === $status_transition ) {
|
||||
$subscription->set_status( $status );
|
||||
} else {
|
||||
$subscription->update_status( $status );
|
||||
$request['status'] = $status; // Set the request status so parent::save_object() doesn't set it to the default 'pending' status.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an object before it is inserted via the REST API.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$this->post_type`,
|
||||
* refers to the object type slug.
|
||||
*
|
||||
* @param WC_Subscription $subscription The subscription object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param bool $creating If is creating a new object.
|
||||
*/
|
||||
return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $subscription, $request, $creating );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds additional item schema information for subscription requests.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
// If this is a request for a subscription's orders, return the subscription orders schema.
|
||||
if ( $this->request instanceof WP_REST_Request && preg_match( "#/{$this->rest_base}/(?P<id>[\d]+)/orders#", $this->request->get_route() ) ) {
|
||||
return $this->get_subscription_orders_schema();
|
||||
}
|
||||
|
||||
$schema = parent::get_item_schema();
|
||||
|
||||
// Base order schema overrides.
|
||||
$schema['properties']['status']['description'] = __( 'Subscription status.', 'woocommerce-subscriptions' );
|
||||
$schema['properties']['status']['enum'] = $this->get_order_statuses();
|
||||
|
||||
$schema['properties']['created_via']['description'] = __( 'Where the subscription was created.', 'woocommerce-subscriptions' );
|
||||
$schema['properties']['currency']['description'] = __( 'Currency the subscription was created with, in ISO format.', 'woocommerce-subscriptions' );
|
||||
$schema['properties']['date_created']['description'] = __( "The date the subscription was created, in the site's timezone.", 'woocommerce-subscriptions' );
|
||||
$schema['properties']['date_created_gmt']['description'] = __( 'The date the subscription was created, as GMT.', 'woocommerce-subscriptions' );
|
||||
$schema['properties']['date_modified']['description'] = __( "The date the subscription was last modified, in the site's timezone.", 'woocommerce-subscriptions' );
|
||||
$schema['properties']['date_modified_gmt']['description'] = __( 'The date the subscription was last modified, as GMT.', 'woocommerce-subscriptions' );
|
||||
$schema['properties']['customer_id']['description'] = __( 'User ID who owns the subscription.', 'woocommerce-subscriptions' );
|
||||
|
||||
unset( $schema['properties']['transaction_id'] );
|
||||
unset( $schema['properties']['refunds'] );
|
||||
unset( $schema['properties']['set_paid'] );
|
||||
unset( $schema['properties']['cart_hash'] );
|
||||
|
||||
// Add subscription schema.
|
||||
$schema['properties'] += [
|
||||
'transition_status' => [
|
||||
'description' => __( 'The status to transition a subscription to.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'string',
|
||||
'context' => [ 'edit' ],
|
||||
'enum' => $this->get_order_statuses(),
|
||||
],
|
||||
'billing_interval' => [
|
||||
'description' => __( 'The number of billing periods between subscription renewals.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'integer',
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
'billing_period' => [
|
||||
'description' => __( 'Billing period for the subscription.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( wcs_get_subscription_period_strings() ),
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
'payment_details' => [
|
||||
'description' => __( 'Subscription payment details.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'object',
|
||||
'context' => [ 'edit' ],
|
||||
'properties' => [
|
||||
'post_meta' => [
|
||||
'description' => __( 'Payment method meta and token in a post_meta_key: token format.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'object',
|
||||
'context' => [ 'edit' ],
|
||||
],
|
||||
'user_meta' => [
|
||||
'description' => __( 'Payment method meta and token in a user_meta_key : token format.', 'woocommerce-subscriptions' ),
|
||||
'type' => 'object',
|
||||
'context' => [ 'view' ],
|
||||
],
|
||||
],
|
||||
],
|
||||
'start_date' => [
|
||||
'description' => __( "The subscription's start date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'type' => 'date-time',
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
'trial_end_date' => [
|
||||
'description' => __( "The subscription's trial end date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'type' => 'date-time',
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
'next_payment_date' => [
|
||||
'description' => __( "The subscription's next payment date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'type' => 'date-time',
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
'cancelled_date' => [
|
||||
'description' => __( "The subscription's cancelled date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'type' => 'date-time',
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
'end_date' => [
|
||||
'description' => __( "The subscription's end date, as GMT.", 'woocommerce-subscriptions' ),
|
||||
'type' => 'date-time',
|
||||
'context' => [ 'view', 'edit' ],
|
||||
],
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query params for collections.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_collection_params() {
|
||||
$params = parent::get_collection_params();
|
||||
|
||||
// Override the base order status description to be subscription specific.
|
||||
$params['status']['description'] = __( 'Limit result set to subscriptions which have specific statuses.', 'woocommerce-subscriptions' );
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object's links to include in the response.
|
||||
*
|
||||
* Because this class also handles retrieving order data, we need
|
||||
* to edit the links generated so the correct REST API href is included
|
||||
* when its generated for an order.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param WC_Data $object Object data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
*
|
||||
* @return array Links for the given object.
|
||||
*/
|
||||
protected function prepare_links( $object, $request ) {
|
||||
$links = parent::prepare_links( $object, $request );
|
||||
|
||||
if ( isset( $links['self'] ) && wcs_is_order( $object ) ) {
|
||||
$links['self'] = [
|
||||
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, 'orders', $object->get_id() ) ),
|
||||
];
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a subscription's payment method and meta from data provided in a REST API request.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param WC_Subscription $subscription The subscription to update.
|
||||
* @param string $payment_method The ID of the payment method to set.
|
||||
* @param array $payment_meta The payment method meta.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update_payment_method( $subscription, $payment_method, $payment_meta ) {
|
||||
$updating_subscription = (bool) $subscription->get_id();
|
||||
|
||||
try {
|
||||
if ( $updating_subscription && ! array_key_exists( $payment_method, WCS_Change_Payment_Method_Admin::get_valid_payment_methods( $subscription ) ) ) {
|
||||
// translators: placeholder is the payment method ID.
|
||||
throw new Exception( sprintf( __( 'The %s payment gateway does not support admin changing the payment method.', 'woocommerce-subscriptions' ), $payment_method ) );
|
||||
}
|
||||
|
||||
// Format the payment meta in the way payment gateways expect so it can be validated.
|
||||
$payment_method_meta = [];
|
||||
|
||||
foreach ( $payment_meta as $table => $meta ) {
|
||||
foreach ( $meta as $meta_key => $value ) {
|
||||
$payment_method_meta[ $table ][ $meta_key ] = [ 'value' => $value ];
|
||||
}
|
||||
}
|
||||
|
||||
$subscription->set_payment_method( $payment_method, $payment_method_meta );
|
||||
} catch ( Exception $e ) {
|
||||
$subscription->set_payment_method();
|
||||
$subscription->save();
|
||||
// translators: 1$: gateway id, 2$: error message
|
||||
throw new WC_REST_Exception( 'woocommerce_rest_invalid_payment_data', sprintf( __( 'Subscription payment method could not be set to %1$s with error message: %2$s', 'woocommerce-subscriptions' ), $payment_method, $e->getMessage() ), 400 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates subscriptions from an order.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return array Subscriptions created from the order.
|
||||
*/
|
||||
public function create_subscriptions_from_order( $request ) {
|
||||
$order_id = absint( $request->get_param( 'id' ) );
|
||||
|
||||
if ( empty( $order_id ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce-subscriptions' ), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( ! $order || ! wcs_is_order( $order ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_order_invalid_id', sprintf( __( 'Failed to load order object with the ID %d.', 'woocommerce-subscriptions' ), $order_id ), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
if ( ! $order->get_customer_id() ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order does not have a customer associated with it. Subscriptions require a customer.', 'woocommerce-subscriptions' ), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
if ( wcs_order_contains_subscription( $order, 'any' ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order already has subscriptions associated with it.', 'woocommerce-subscriptions' ), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
$subscription_groups = [];
|
||||
$subscriptions = [];
|
||||
|
||||
// Group the order items into subscription groups.
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( ! WC_Subscriptions_Product::is_subscription( $product ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subscription_groups[ wcs_get_subscription_item_grouping_key( $item ) ][] = $item;
|
||||
}
|
||||
|
||||
// Return a 204 if there are no subscriptions to be created.
|
||||
if ( empty( $subscription_groups ) ) {
|
||||
$response = rest_ensure_response( $subscriptions );
|
||||
$response->set_status( 204 );
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start creating any subscriptions start transaction if available.
|
||||
*
|
||||
* To ensure data integrity, if any subscription fails to be created, the transaction will be rolled back. This will enable
|
||||
* the client to resubmit the request without having to worry about duplicate subscriptions being created.
|
||||
*/
|
||||
$transaction = new WCS_SQL_Transaction();
|
||||
$transaction->start();
|
||||
|
||||
try {
|
||||
// Create subscriptions.
|
||||
foreach ( $subscription_groups as $items ) {
|
||||
// Get the first item in the group to use as the base for the subscription.
|
||||
$product = $items[0]->get_product();
|
||||
$start_date = wcs_get_datetime_utc_string( $order->get_date_created( 'edit' ) );
|
||||
$subscription = wcs_create_subscription( [
|
||||
'order_id' => $order_id,
|
||||
'created_via' => 'rest-api',
|
||||
'start_date' => $start_date,
|
||||
'status' => $order->is_paid() ? 'active' : 'pending',
|
||||
'billing_period' => WC_Subscriptions_Product::get_period( $product ),
|
||||
'billing_interval' => WC_Subscriptions_Product::get_interval( $product ),
|
||||
'customer_note' => $order->get_customer_note(),
|
||||
] );
|
||||
|
||||
if ( is_wp_error( $subscription ) ) {
|
||||
throw new Exception( $subscription->get_error_message() );
|
||||
}
|
||||
|
||||
wcs_copy_order_address( $order, $subscription );
|
||||
|
||||
$subscription->update_dates(
|
||||
[
|
||||
'trial_end' => WC_Subscriptions_Product::get_trial_expiration_date( $product, $start_date ),
|
||||
'next_payment' => WC_Subscriptions_Product::get_first_renewal_payment_date( $product, $start_date ),
|
||||
'end' => WC_Subscriptions_Product::get_expiration_date( $product, $start_date ),
|
||||
]
|
||||
);
|
||||
|
||||
$subscription->set_payment_method( $order->get_payment_method() );
|
||||
|
||||
wcs_copy_order_meta( $order, $subscription, 'subscription' );
|
||||
|
||||
// Add items.
|
||||
$subscription_needs_shipping = false;
|
||||
foreach ( $items as $item ) {
|
||||
// Create order line item.
|
||||
$item_id = wc_add_order_item(
|
||||
$subscription->get_id(),
|
||||
[
|
||||
'order_item_name' => $item->get_name(),
|
||||
'order_item_type' => $item->get_type(),
|
||||
]
|
||||
);
|
||||
|
||||
$subscription_item = $subscription->get_item( $item_id );
|
||||
|
||||
wcs_copy_order_item( $item, $subscription_item );
|
||||
|
||||
// Don't include sign-up fees or $0 trial periods when setting the subscriptions item totals.
|
||||
wcs_set_recurring_item_total( $subscription_item );
|
||||
|
||||
$subscription_item->save();
|
||||
|
||||
// Check if this subscription will need shipping.
|
||||
if ( ! $subscription_needs_shipping ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( $product ) {
|
||||
$subscription_needs_shipping = $product->needs_shipping() && ! WC_Subscriptions_Product::needs_one_time_shipping( $product );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add coupons.
|
||||
foreach ( $order->get_coupons() as $coupon_item ) {
|
||||
$coupon = new WC_Coupon( $coupon_item->get_code() );
|
||||
|
||||
try {
|
||||
// validate_subscription_coupon_for_order will throw an exception if the coupon cannot be applied to the subscription.
|
||||
WC_Subscriptions_Coupon::validate_subscription_coupon_for_order( true, $coupon, $subscription );
|
||||
|
||||
$subscription->apply_coupon( $coupon->get_code() );
|
||||
} catch ( Exception $e ) {
|
||||
// Do nothing. The coupon will not be applied to the subscription.
|
||||
}
|
||||
}
|
||||
|
||||
// Add shipping.
|
||||
if ( $subscription_needs_shipping ) {
|
||||
foreach ( $order->get_shipping_methods() as $shipping_item ) {
|
||||
$rate = new WC_Shipping_Rate( $shipping_item->get_method_id(), $shipping_item->get_method_title(), $shipping_item->get_total(), $shipping_item->get_taxes(), $shipping_item->get_instance_id() );
|
||||
|
||||
$item = new WC_Order_Item_Shipping();
|
||||
$item->set_order_id( $subscription->get_id() );
|
||||
$item->set_shipping_rate( $rate );
|
||||
|
||||
$subscription->add_item( $item );
|
||||
}
|
||||
}
|
||||
|
||||
// Add fees.
|
||||
foreach ( $order->get_fees() as $fee_item ) {
|
||||
if ( ! apply_filters( 'wcs_should_copy_fee_item_to_subscription', true, $fee_item, $subscription, $order ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item = new WC_Order_Item_Fee();
|
||||
$item->set_props(
|
||||
[
|
||||
'name' => $fee_item->get_name(),
|
||||
'tax_class' => $fee_item->get_tax_class(),
|
||||
'amount' => $fee_item->get_amount(),
|
||||
'total' => $fee_item->get_total(),
|
||||
'total_tax' => $fee_item->get_total_tax(),
|
||||
'taxes' => $fee_item->get_taxes(),
|
||||
]
|
||||
);
|
||||
|
||||
$subscription->add_item( $item );
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch a fresh instance of the subscription because the current instance has an empty line item cache generated before we had copied the line items.
|
||||
* Fetching a new instance will ensure the line items are used when calculating totals.
|
||||
*/
|
||||
$subscription = wcs_get_subscription( $subscription->get_id() );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
throw new Exception( __( 'There was a problem completing this request. The subscription may have been deleted by another process.', 'woocommerce-subscriptions' ) );
|
||||
}
|
||||
|
||||
$subscription->calculate_totals();
|
||||
|
||||
/**
|
||||
* Fires after a single subscription is created or updated via the REST API.
|
||||
*
|
||||
* @param WC_Subscription $object Inserted subscription.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param boolean $creating True when creating object, false when updating.
|
||||
*/
|
||||
do_action( "woocommerce_rest_insert_{$this->post_type}_object", $subscription, $request, true );
|
||||
|
||||
$fresh_subscription = wcs_get_subscription( $subscription->get_id() );
|
||||
|
||||
if ( ! $fresh_subscription ) {
|
||||
throw new Exception( __( 'There was a problem completing this request. The subscription may have been deleted by another process.', 'woocommerce-subscriptions' ) );
|
||||
}
|
||||
|
||||
$response = $this->prepare_object_for_response( $fresh_subscription, $request );
|
||||
$subscriptions[] = $this->prepare_response_for_collection( $response );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback();
|
||||
return new WP_Error( 'woocommerce_rest_invalid_subscription_data', $e->getMessage(), [ 'status' => 404 ] );
|
||||
}
|
||||
|
||||
// If we got here, the subscription was created without problems
|
||||
$transaction->commit();
|
||||
|
||||
return rest_ensure_response( $subscriptions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscriptions statuses schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_statuses_schema() {
|
||||
$schema = [
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'shop_subscription statuses', // Use a unique title for the schema so that CLI commands aren't overridden.
|
||||
'type' => 'object',
|
||||
'properties' => [],
|
||||
];
|
||||
|
||||
// Add the subscription statuses to the schema.
|
||||
foreach ( wcs_get_subscription_statuses() as $status => $status_name ) {
|
||||
$schema['properties'][ $status ] = [
|
||||
'type' => 'string',
|
||||
'description' => sprintf( __( 'Subscription status: %s', 'woocommerce-subscription' ), $status_name ),
|
||||
];
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscriptions orders schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_subscription_orders_schema() {
|
||||
$schema = parent::get_item_schema(); // Fetch the order schema.
|
||||
$schema['title'] = 'shop_subscription orders'; // Use a unique title for the schema so that CLI commands aren't overridden.
|
||||
$schema['properties']['order_type'] = [
|
||||
'type' => 'string',
|
||||
'description' => __( 'The type of order related to the subscription.', 'woocommerce-subscriptions' ),
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscriptions schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function create_subscriptions_from_order_schema() {
|
||||
$schema = $this->get_public_item_schema();
|
||||
$schema['title'] = 'shop_order subscriptions'; // Use a unique title for the schema so that CLI commands aren't overridden and we can target this endpoint specifically.
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Subscriptions CLI class.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*/
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
class WC_Subscriptions_CLI {
|
||||
|
||||
/**
|
||||
* Loads WooCommerce Subscriptions CLI related hooks.
|
||||
*/
|
||||
public function __construct() {
|
||||
WP_CLI::add_hook( 'before_invoke:wc shop_order subscriptions create', [ $this, 'abort_create_subscriptions_from_order' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an error when the `wc shop_order subscriptions create` WP CLI command is used.
|
||||
*
|
||||
* WooCommerce core adds WP CLI commands for each WC REST API endpoints beginning with /wc/v2. This means all of our subscription
|
||||
* REST API endpoints are added. While the `wc shop_order subscriptions create` CLI command technically works, WooCommerce doesn't have support for
|
||||
* batch creation via CLI and results in the success message not being displayed correctly.
|
||||
*
|
||||
* @param string $command The command name.
|
||||
*/
|
||||
public function abort_create_subscriptions_from_order( $command ) {
|
||||
WP_CLI::error( "The '{$command}' command isn't supported via WP CLI." );
|
||||
}
|
||||
}
|
||||
|
|
@ -27,11 +27,28 @@ class WC_Subscriptions_Dependency_Manager {
|
|||
*/
|
||||
private $wc_version_cached = false;
|
||||
|
||||
/**
|
||||
* @var boolean Whether to skip the class_exists and WC_VERSION constant checks.
|
||||
*/
|
||||
private $skip_class_exists_and_wc_version_constant_checks = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct( $minimum_supported_wc_version ) {
|
||||
$this->minimum_supported_wc_version = $minimum_supported_wc_version;
|
||||
/**
|
||||
* Filter allows to skip the class_exists and WC_VERSION constant checks.
|
||||
*
|
||||
* @since 7.8.0
|
||||
*
|
||||
* @param bool $use_class_exists Whether to use the class_exists and WC_VERSION constant checks.
|
||||
*
|
||||
* @return bool false to use the class_exists and WC_VERSION checks, true to skip them.
|
||||
*/
|
||||
if ( defined( 'WCS_ENVIRONMENT_TYPE' ) && WCS_ENVIRONMENT_TYPE === 'tests' && apply_filters( 'woocommerce_subscriptions_skip_class_exists_and_wc_version_constant_checks', false ) ) {
|
||||
$this->skip_class_exists_and_wc_version_constant_checks = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,7 +69,7 @@ class WC_Subscriptions_Dependency_Manager {
|
|||
* @return bool True if the plugin is active, false otherwise.
|
||||
*/
|
||||
public function is_woocommerce_active() {
|
||||
if ( class_exists( 'WooCommerce' ) ) {
|
||||
if ( class_exists( 'WooCommerce' ) && ! $this->skip_class_exists_and_wc_version_constant_checks ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -79,13 +96,20 @@ class WC_Subscriptions_Dependency_Manager {
|
|||
/**
|
||||
* This method detects the active version of WooCommerce.
|
||||
*
|
||||
* The resulting version is based on the WooCommerce plugin data. The WooCommerce plugin is determined by this logic:
|
||||
* If the WC_VERSION constant is already defined, use that as a first preference.
|
||||
* If it's not defined, fetch the version based on the WooCommerce plugin data.
|
||||
*
|
||||
* The WooCommerce plugin is determined by this logic:
|
||||
* 1. Installed at 'woocommerce/woocommerce.php'
|
||||
* 2. Installed at any '{x}/woocommerce.php' where the plugin name is 'WooCommerce'
|
||||
*
|
||||
* @return string|null The active WooCommerce version, or null if WooCommerce is not active.
|
||||
*/
|
||||
private function get_woocommerce_active_version() {
|
||||
if ( defined( 'WC_VERSION' ) && ! $this->skip_class_exists_and_wc_version_constant_checks ) {
|
||||
return WC_VERSION;
|
||||
}
|
||||
|
||||
// Use a cached value to avoid calling get_plugins() and looping multiple times.
|
||||
if ( true === $this->wc_version_cached ) {
|
||||
return $this->wc_active_version;
|
||||
|
|
@ -93,6 +117,13 @@ class WC_Subscriptions_Dependency_Manager {
|
|||
|
||||
$this->wc_version_cached = true;
|
||||
|
||||
// Try to get version from transient first
|
||||
$this->wc_active_version = get_transient( 'wcs_woocommerce_active_version' );
|
||||
|
||||
if ( false !== $this->wc_active_version ) {
|
||||
return $this->wc_active_version;
|
||||
}
|
||||
|
||||
// Load plugin.php if it's not already loaded.
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
|
@ -115,9 +146,15 @@ class WC_Subscriptions_Dependency_Manager {
|
|||
|
||||
if ( $is_woocommerce && is_plugin_active( $plugin_slug ) ) {
|
||||
$this->wc_active_version = $plugin_data['Version'];
|
||||
break; // Found it, no need to continue looping
|
||||
}
|
||||
}
|
||||
|
||||
// Cache the result in a transient for 1 hour
|
||||
if ( ! empty( $this->wc_active_version ) ) {
|
||||
set_transient( 'wcs_woocommerce_active_version', $this->wc_active_version, HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $this->wc_active_version;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Automattic\WooCommerce_Subscriptions\Internal\Telemetry\Events as WC_Tracks_Events;
|
||||
|
||||
/**
|
||||
* @method static WC_Subscriptions_Plugin instance()
|
||||
*/
|
||||
|
|
@ -21,7 +23,7 @@ class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
|||
public function init() {
|
||||
parent::init();
|
||||
WC_Subscriptions_Switcher::init();
|
||||
new WCS_Cart_Switch();
|
||||
$this->add_cart_handler( new WCS_Cart_Switch() );
|
||||
WCS_Manual_Renewal_Manager::init();
|
||||
WCS_Customer_Suspension_Manager::init();
|
||||
WCS_Drip_Downloads_Manager::init();
|
||||
|
|
@ -32,8 +34,19 @@ class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
|||
WCS_Call_To_Action_Button_Text_Manager::init();
|
||||
WCS_Subscriber_Role_Manager::init();
|
||||
WCS_Upgrade_Notice_Manager::init();
|
||||
WCS_Admin_Assets::init();
|
||||
|
||||
$tracks_events = new WC_Tracks_Events();
|
||||
$tracks_events->setup();
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
new WC_Subscriptions_CLI();
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'maybe_show_welcome_message' ) );
|
||||
add_action( 'plugins_loaded', array( $this, 'init_gifting' ) );
|
||||
add_action( 'plugins_loaded', array( $this, 'init_downloads' ) );
|
||||
add_action( 'admin_notices', array( WC_Subscription_Downloads_Settings::class, 'add_notice_about_bundled_feature' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,7 +85,7 @@ class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
|||
require_once $this->get_plugin_directory( 'includes/early-renewal/wcs-early-renewal-functions.php' );
|
||||
|
||||
if ( WCS_Early_Renewal_Manager::is_early_renewal_enabled() ) {
|
||||
new WCS_Cart_Early_Renewal();
|
||||
$this->add_cart_handler( new WCS_Cart_Early_Renewal() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -228,4 +241,142 @@ class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
|||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to initialize gifting functionality.
|
||||
*
|
||||
* Before doing this, the method tries to determine if the standalone WooCommerce Gifting plugin is active and has
|
||||
* already loaded (if the standalone plugin is active, we do not proceed). To accomplish this, this method expects
|
||||
* to run during plugins_loaded at priority 20 (whereas the equivalent code from the standalone plugin will run at
|
||||
* priority 11).
|
||||
*/
|
||||
public function init_gifting() {
|
||||
if ( ! WCSG_Admin_Welcome_Announcement::is_welcome_announcement_dismissed() ) {
|
||||
WCSG_Admin_Welcome_Announcement::init();
|
||||
}
|
||||
|
||||
if (
|
||||
$this->is_plugin_being_activated( 'woocommerce-subscriptions-gifting' )
|
||||
|| function_exists( 'wcsg_load' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gifting_includes = trailingslashit( $this->get_plugin_directory( 'includes/gifting' ) );
|
||||
|
||||
require_once $gifting_includes . 'wcsg-compatibility-functions.php';
|
||||
|
||||
WCSG_Admin_Order::init();
|
||||
WCSG_Product::init();
|
||||
WCSG_Cart::init();
|
||||
WCSG_Checkout::init();
|
||||
WCSG_Recipient_Management::init();
|
||||
WCSG_Recipient_Details::init();
|
||||
WCSG_Email::init();
|
||||
WCSG_Download_Handler::init();
|
||||
WCSG_Admin::init();
|
||||
WCSG_Recipient_Addresses::init();
|
||||
WCSG_Template_Loader::init();
|
||||
WCSG_Admin_System_Status::init();
|
||||
|
||||
add_action(
|
||||
'init',
|
||||
function () {
|
||||
new WCSG_Privacy();
|
||||
}
|
||||
);
|
||||
|
||||
WCS_Gifting::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to initialize additional downloads functionality.
|
||||
*
|
||||
* This functionality makes it possible to link downloadable products with a subscription
|
||||
* product. Purchasers of the subscription product then automatically get access to the files associated with downloadable product.
|
||||
*
|
||||
* Previously, this functionality existed as a standalone plugin (WooCommerce Subscription Downnloads) and so,
|
||||
* before initializing, we try to determine if the standalone plugin is active and has already loaded (if it is
|
||||
* active, we do not proceed).
|
||||
*/
|
||||
public function init_downloads() {
|
||||
if (
|
||||
$this->is_plugin_being_activated( 'woocommerce-subscription-downloads' )
|
||||
|| class_exists( WC_Subscription_Downloads::class, false )
|
||||
) {
|
||||
if ( class_exists( WC_Subscription_Downloads::class, false ) ) {
|
||||
// Will show the welcome announcement if the standalone plugin is active and the welcome announcement has not been dismissed.
|
||||
if ( ! WC_Subscription_Downloads_Admin_Welcome_Announcement::is_welcome_announcement_dismissed() ) {
|
||||
WC_Subscription_Downloads_Admin_Welcome_Announcement::init();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
WC_Subscription_Downloads::setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to determine if the specified plugin is being activated.
|
||||
*
|
||||
* The provided plugin slug can be either the complete relative plugin path (ie, 'plugin-slug/plugin-slug.php') or
|
||||
* just a part of the path (ie, 'plugin-slug'). So long as the plugin which is actually being activated contains
|
||||
* that string, then we consider ourselves to have a match and will return true.
|
||||
*
|
||||
* Therefore, consider with care how precise you need to be: something highly specific like our first example will
|
||||
* fail if the plugin directory has been renamed. A shorter fragment, on the other hand, will potentially match the
|
||||
* wrong plugin.
|
||||
*
|
||||
* This method is only useful as a means of detecting when a plugin is activated through 'conventional' means (via
|
||||
* the plugin admin screen, or via WP CLI), but it will not provide protection if, for example, third party code
|
||||
* makes its own arbitrary calls to activate_plugin().
|
||||
*
|
||||
* @param string $plugin_slug Plugin slug.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_plugin_being_activated( string $plugin_slug ): bool {
|
||||
// Try to determine if a plugin is in the process of being activated via the plugin admin screen.
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$action = isset( $_REQUEST['action'] ) ? wc_clean( wp_unslash( $_REQUEST['action'] ) ) : '';
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$plugin = isset( $_REQUEST['plugin'] ) ? wc_clean( wp_unslash( $_REQUEST['plugin'] ) ) : '';
|
||||
|
||||
if (
|
||||
'activate' === $action
|
||||
&& str_contains( $plugin, $plugin_slug )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Try to determine if a plugin is being activated via WP CLI.
|
||||
if ( class_exists( WP_CLI::class ) ) {
|
||||
// Note that flags such as `--no-color` are filtered out of this array.
|
||||
$args = WP_CLI::get_runner()->arguments;
|
||||
|
||||
if ( ! is_countable( $args ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
( count( $args ) < 3
|
||||
|| 'plugin' !== $args[0]
|
||||
|| 'activate' !== $args[1] )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The remaining arguments are the list of plugin slugs to be activated.
|
||||
$plugins_to_be_activated = array_slice( $args, 2 );
|
||||
|
||||
foreach ( $plugins_to_be_activated as $plugin ) {
|
||||
if ( str_contains( $plugin, $plugin_slug ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
* @since 2.0
|
||||
*/
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
|
@ -18,6 +20,7 @@ class WCS_API {
|
|||
add_filter( 'woocommerce_api_classes', array( __CLASS__, 'includes' ) );
|
||||
add_action( 'rest_api_init', array( __CLASS__, 'register_routes' ), 15 );
|
||||
add_action( 'rest_api_init', array( __CLASS__, 'register_route_overrides' ), 15 );
|
||||
add_action( 'woocommerce_rest_set_order_item', array( __CLASS__, 'add_sign_up_fee_to_order_item' ), 15, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,12 +56,17 @@ class WCS_API {
|
|||
// V1
|
||||
'WC_REST_Subscriptions_V1_Controller',
|
||||
'WC_REST_Subscription_Notes_V1_Controller',
|
||||
// V2
|
||||
'WC_REST_Subscriptions_V2_Controller',
|
||||
'WC_REST_Subscription_Notes_V2_Controller',
|
||||
// V3 (latest)
|
||||
'WC_REST_Subscriptions_Controller',
|
||||
'WC_REST_Subscription_notes_Controller',
|
||||
'WC_REST_Subscriptions_Settings_Option_Controller',
|
||||
);
|
||||
|
||||
foreach ( $endpoint_classes as $class ) {
|
||||
// @phpstan-ignore class.nameCase
|
||||
$controller = new $class();
|
||||
$controller->register_routes();
|
||||
}
|
||||
|
|
@ -75,6 +83,57 @@ class WCS_API {
|
|||
}
|
||||
|
||||
WC_REST_Subscription_System_Status_Manager::init();
|
||||
new WC_REST_Subscriptions_Settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds sign-up fees to order items added/edited via the REST API.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @param WC_Order_Item_Product $item Order item object.
|
||||
* @param array $item_request_data Data posted to the API about the order item.
|
||||
*/
|
||||
public static function add_sign_up_fee_to_order_item( $item, $item_request_data = array() ) {
|
||||
if ( 'line_item' !== $item->get_type() || ! self::is_orders_api_request() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the request includes an item subtotal or total, we don't want to override the provided total.
|
||||
if ( isset( $item_request_data['subtotal'] ) || isset( $item_request_data['total'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( ! WC_Subscriptions_Product::is_subscription( $product ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product );
|
||||
$sign_up_fee = is_numeric( $sign_up_fee ) ? (float) $sign_up_fee : 0;
|
||||
|
||||
if ( 0 < $sign_up_fee ) {
|
||||
// Recalculate the totals as in `prepare_line_items`, but including the sign up fee in the price.
|
||||
$trial_length = WC_Subscriptions_Product::get_trial_length( $product );
|
||||
|
||||
if ( $trial_length > 0 ) {
|
||||
$price = $sign_up_fee;
|
||||
} else {
|
||||
$price = (float) $product->get_price() + $sign_up_fee;
|
||||
}
|
||||
|
||||
$total = wc_get_price_excluding_tax(
|
||||
$product,
|
||||
array(
|
||||
'qty' => $item->get_quantity(),
|
||||
'price' => $price,
|
||||
)
|
||||
);
|
||||
|
||||
$item->set_total( $total );
|
||||
$item->set_subtotal( $total );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -87,4 +146,39 @@ class WCS_API {
|
|||
global $wp_version;
|
||||
return version_compare( $wp_version, '4.4', '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current request is a REST API request for orders.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected static function is_orders_api_request() {
|
||||
if ( ! Constants::is_true( 'REST_REQUEST' ) || empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) preg_match( '/\/wc\/v[1-3]\/orders\b/', $GLOBALS['wp']->query_vars['rest_route'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches WooCommerce API endpoint data in a WooCommerce version compatible way.
|
||||
*
|
||||
* This method is a wrapper for the WooCommerce API get_endpoint_data method. In WooCommerce 9.0.0 and later, the
|
||||
* WC()->api was deprecated in favor of the new Automattic\WooCommerce\Utilities\RestApiUtil class.
|
||||
*
|
||||
* @since 6.4.1
|
||||
*
|
||||
* @param string $endpoint The endpoint to get data for.
|
||||
* @return array|\WP_Error The endpoint data or WP_Error if the request fails.
|
||||
*/
|
||||
public static function get_wc_api_endpoint_data( $endpoint ) {
|
||||
if ( wcs_is_woocommerce_pre( '9.0.0' ) ) {
|
||||
// @phpstan-ignore-next-line Call to deprecated method.
|
||||
return WC()->api->get_endpoint_data( $endpoint );
|
||||
}
|
||||
|
||||
return wc_get_container()->get( Automattic\WooCommerce\Utilities\RestApiUtil::class )->get_endpoint_data( $endpoint );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ class WCS_Autoloader extends WCS_Core_Autoloader {
|
|||
'wcs_webhooks' => true,
|
||||
'wcs_auth' => true,
|
||||
'wcs_upgrade_notice_manager' => true,
|
||||
'wcs_admin_assets' => true,
|
||||
'wc_subscriptions_cli' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -92,8 +94,6 @@ class WCS_Autoloader extends WCS_Core_Autoloader {
|
|||
|
||||
if ( stripos( $class, 'switch' ) !== false || 'wcs_add_cart_item' === $class ) {
|
||||
$path .= '/switching';
|
||||
} elseif ( false !== strpos( $class, 'wc_report' ) ) {
|
||||
$path .= '/admin/reports/deprecated';
|
||||
} elseif ( false !== strpos( $class, 'wcs_report' ) ) {
|
||||
$path .= '/admin/reports';
|
||||
} elseif ( false !== strpos( $class, 'retry' ) || false !== strpos( $class, 'retries' ) ) {
|
||||
|
|
@ -121,13 +121,10 @@ class WCS_Autoloader extends WCS_Core_Autoloader {
|
|||
*/
|
||||
protected function should_autoload( $class ) {
|
||||
static $legacy = array(
|
||||
'wc_order_item_pending_switch' => 1,
|
||||
'wc_report_retention_rate' => 1,
|
||||
'wc_report_upcoming_recurring_revenue' => 1,
|
||||
'wc_order_item_pending_switch' => 1,
|
||||
);
|
||||
|
||||
return isset( $legacy[ $class ] ) ? true : parent::should_autoload( $class );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class WCS_Call_To_Action_Button_Text_Manager {
|
|||
*/
|
||||
public static function init() {
|
||||
add_filter( 'woocommerce_subscription_settings', array( __CLASS__, 'add_settings' ), 5 );
|
||||
add_filter( 'wc_subscription_product_add_to_cart_text', array( __CLASS__, 'filter_add_to_cart_text' ), 10, 2 );
|
||||
add_filter( 'wc_subscription_product_add_to_cart_text', array( __CLASS__, 'filter_add_to_cart_text' ) );
|
||||
add_filter( 'wcs_place_subscription_order_text', array( __CLASS__, 'filter_place_subscription_order_text' ) );
|
||||
}
|
||||
|
||||
|
|
@ -30,32 +30,32 @@ class WCS_Call_To_Action_Button_Text_Manager {
|
|||
public static function add_settings( $settings ) {
|
||||
$button_text_settings = array(
|
||||
array(
|
||||
'name' => __( 'Button Text', 'woocommerce-subscriptions' ),
|
||||
'name' => __( 'Button text', 'woocommerce-subscriptions' ),
|
||||
'type' => 'title',
|
||||
'desc' => '',
|
||||
'id' => WC_Subscriptions_Admin::$option_prefix . '_button_text',
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Add to Cart Button Text', 'woocommerce-subscriptions' ),
|
||||
'desc' => __( 'A product displays a button with the text "Add to cart". By default, a subscription changes this to "Sign up now". You can customise the button text for subscriptions here.', 'woocommerce-subscriptions' ),
|
||||
'desc' => __( 'A product displays a button with the text "Add to cart". You can customise the button text for subscriptions here.', 'woocommerce-subscriptions' ),
|
||||
'tip' => '',
|
||||
'id' => WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => __( 'Sign up now', 'woocommerce-subscriptions' ),
|
||||
'default' => __( 'Add to cart', 'woocommerce-subscriptions' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'placeholder' => __( 'Sign up now', 'woocommerce-subscriptions' ),
|
||||
'placeholder' => __( 'Add to cart', 'woocommerce-subscriptions' ),
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Place Order Button Text', 'woocommerce-subscriptions' ),
|
||||
'desc' => __( 'Use this field to customise the text displayed on the checkout button when an order contains a subscription. Normally the checkout submission button displays "Place order". When the cart contains a subscription, this is changed to "Sign up now".', 'woocommerce-subscriptions' ),
|
||||
'desc' => __( 'Use this field to customise the text displayed on the checkout button when an order contains a subscription.', 'woocommerce-subscriptions' ),
|
||||
'tip' => '',
|
||||
'id' => WC_Subscriptions_Admin::$option_prefix . '_order_button_text',
|
||||
'css' => 'min-width:150px;',
|
||||
'default' => __( 'Sign up now', 'woocommerce-subscriptions' ),
|
||||
'default' => __( 'Place order', 'woocommerce-subscriptions' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'placeholder' => __( 'Sign up now', 'woocommerce-subscriptions' ),
|
||||
'placeholder' => __( 'Place order', 'woocommerce-subscriptions' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
|
|
@ -71,8 +71,7 @@ class WCS_Call_To_Action_Button_Text_Manager {
|
|||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $add_to_cart_text The product's add to cart text.
|
||||
* @param WC_Abstract_Product $product The product.
|
||||
* @param string $add_to_cart_text The product's add to cart text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class WCS_Customer_Suspension_Manager {
|
|||
'css' => 'min-width:50px;',
|
||||
'default' => 0,
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'options' => apply_filters( 'woocommerce_subscriptions_max_customer_suspension_range', array_merge( range( 0, 12 ), array( 'unlimited' => 'Unlimited' ) ) ),
|
||||
'desc_tip' => __( 'Set a maximum number of times a customer can suspend their account for each billing period. For example, for a value of 3 and a subscription billed yearly, if the customer has suspended their account 3 times, they will not be presented with the option to suspend their account until the next year. Store managers will always be able to suspend an active subscription. Set this to 0 to turn off the customer suspension feature completely.', 'woocommerce-subscriptions' ),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -77,28 +77,33 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
|||
* Get the number of renewals for a limited coupon.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @param string $code The coupon code.
|
||||
* @param string|WC_Coupon $coupon The coupon or coupon code.
|
||||
* @return false|int False for non-recurring coupons, or the limit number for recurring coupons.
|
||||
* A value of 0 is for unlimited usage.
|
||||
*/
|
||||
public static function get_coupon_limit( $code ) {
|
||||
if ( wcs_is_woocommerce_pre( '3.2' ) ) {
|
||||
public static function get_coupon_limit( $coupon ) {
|
||||
// If we have a coupon code, attempt to get the coupon object.
|
||||
if ( is_string( $coupon ) ) {
|
||||
$coupon = new WC_Coupon( $coupon );
|
||||
}
|
||||
|
||||
if ( ! $coupon instanceof WC_Coupon ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve the coupon data.
|
||||
$coupon = new WC_Coupon( $code );
|
||||
$coupon_type = $coupon->get_discount_type();
|
||||
|
||||
// If we have a virtual coupon, attempt to get the original coupon.
|
||||
if ( WC_Subscriptions_Coupon::is_renewal_cart_coupon( $coupon_type ) ) {
|
||||
$coupon = WC_Subscriptions_Coupon::map_virtual_coupon( $code );
|
||||
$coupon = WC_Subscriptions_Coupon::map_virtual_coupon( $coupon->get_code() );
|
||||
$coupon_type = $coupon->get_discount_type();
|
||||
}
|
||||
|
||||
$limited = $coupon->get_meta( self::$coupons_renewals );
|
||||
if ( ! WC_Subscriptions_Coupon::is_recurring_coupon( $coupon_type ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return WC_Subscriptions_Coupon::is_recurring_coupon( $coupon_type ) ? intval( $limited ) : false;
|
||||
return intval( $coupon->get_meta( self::$coupons_renewals ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -266,11 +271,16 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
|||
* @param int $id The coupon ID.
|
||||
*/
|
||||
public static function add_limit_to_list_table( $column_name, $id ) {
|
||||
global $the_coupon;
|
||||
|
||||
if ( 'usage' !== $column_name ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limit = self::get_coupon_limit( wc_get_coupon_code_by_id( $id ) );
|
||||
// Confirm the global coupon object is the one we're looking for, otherwise fetch it.
|
||||
$coupon = empty( $the_coupon ) || $the_coupon->get_id() !== $id ? new WC_Coupon( $id ) : $the_coupon;
|
||||
$limit = self::get_coupon_limit( $coupon );
|
||||
|
||||
if ( false === $limit ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -303,13 +313,14 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
|||
}
|
||||
|
||||
// Bail early if there are no limited coupons applied to the recurring cart or if there is no discount provided.
|
||||
// @phpstan-ignore property.notFound
|
||||
if ( empty( $limited_recurring_coupons ) || ! $recurring_cart->discount_cart ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$has_expiring_coupon = false;
|
||||
$subscription_length = wcs_cart_pluck( $recurring_cart, 'subscription_length' );
|
||||
$subscription_payments = $subscription_length / wcs_cart_pluck( $recurring_cart, 'subscription_period_interval' );
|
||||
$subscription_payments = (int) $subscription_length / (int) wcs_cart_pluck( $recurring_cart, 'subscription_period_interval' );
|
||||
|
||||
// Limited recurring coupons will always expire at some point on subscriptions with no length.
|
||||
if ( empty( $subscription_length ) ) {
|
||||
|
|
@ -346,7 +357,12 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
|||
$has_limited_coupon = false;
|
||||
|
||||
if ( $change_payment && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) ) ) {
|
||||
$subscription = wcs_get_subscription( $change_payment );
|
||||
$subscription = wcs_get_subscription( $change_payment );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
return $gateways;
|
||||
}
|
||||
|
||||
$has_limited_coupon = self::order_has_limited_recurring_coupon( $subscription );
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +387,6 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
|||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $message The current message indicating there are no payment methods available..
|
||||
* @return string The filtered message indicating there are no payment methods available.
|
||||
*/
|
||||
public static function no_available_payment_methods_message() {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class WCS_Manual_Renewal_Manager {
|
|||
*
|
||||
* @since 4.0.0
|
||||
* @param $settings The full subscription settings array.
|
||||
* @return $settings.
|
||||
* @return array
|
||||
*/
|
||||
public static function add_settings( $settings ) {
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class WCS_Manual_Renewal_Manager {
|
|||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
// translators: placeholders are opening and closing link tags
|
||||
'desc_tip' => sprintf( __( 'With manual renewals, a customer\'s subscription is put on-hold until they login and pay to renew it. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '<a href="http://docs.woocommerce.com/document/subscriptions/store-manager-guide/#accept-manual-renewals">', '</a>' ),
|
||||
'desc_tip' => sprintf( __( 'With manual renewals, a customer\'s subscription is put on-hold until they login and pay to renew it. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '<a href="https://woocommerce.com/document/subscriptions/store-manager-guide/#accept-manual-renewals">', '</a>' ),
|
||||
'checkboxgroup' => 'start',
|
||||
'show_if_checked' => 'option',
|
||||
),
|
||||
|
|
@ -51,7 +51,7 @@ class WCS_Manual_Renewal_Manager {
|
|||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
// translators: placeholders are opening and closing link tags
|
||||
'desc_tip' => sprintf( __( 'If you don\'t want new subscription purchases to automatically charge renewal payments, you can turn off automatic payments. Existing automatic subscriptions will continue to charge customers automatically. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '<a href="http://docs.woocommerce.com/document/subscriptions/store-manager-guide/#turn-off-automatic-payments">', '</a>' ),
|
||||
'desc_tip' => sprintf( __( 'If you don\'t want new subscription purchases to automatically charge renewal payments, you can turn off automatic payments. Existing automatic subscriptions will continue to charge customers automatically. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '<a href="https://woocommerce.com/document/subscriptions/store-manager-guide/#turn-off-automatic-payments">', '</a>' ),
|
||||
'checkboxgroup' => 'end',
|
||||
'show_if_checked' => 'yes',
|
||||
),
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ class WCS_Subscriber_Role_Manager {
|
|||
* @return array Subscriptions settings.
|
||||
*/
|
||||
public static function add_settings( $settings ) {
|
||||
$roles_options = array();
|
||||
|
||||
if ( ! function_exists( 'get_editable_roles' ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/user.php' );
|
||||
require_once ABSPATH . 'wp-admin/includes/user.php';
|
||||
}
|
||||
|
||||
foreach ( get_editable_roles() as $role => $details ) {
|
||||
|
|
@ -50,6 +52,7 @@ class WCS_Subscriber_Role_Manager {
|
|||
'css' => 'min-width:150px;',
|
||||
'default' => 'subscriber',
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'options' => $roles_options,
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
|
@ -61,6 +64,7 @@ class WCS_Subscriber_Role_Manager {
|
|||
'css' => 'min-width:150px;',
|
||||
'default' => 'customer',
|
||||
'type' => 'select',
|
||||
'class' => 'wc-enhanced-select',
|
||||
'options' => $roles_options,
|
||||
'desc_tip' => true,
|
||||
),
|
||||
|
|
@ -70,7 +74,10 @@ class WCS_Subscriber_Role_Manager {
|
|||
),
|
||||
);
|
||||
|
||||
WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_button_text', $role_settings, 'multiple_settings', 'sectionend' );
|
||||
if ( ! WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_button_text', $role_settings, 'multiple_settings', 'sectionend' ) ) {
|
||||
$settings = array_merge( $settings, $role_settings );
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class WCS_Upgrade_Notice_Manager {
|
|||
'description' => sprintf(
|
||||
// translators: 1-3: opening/closing <a> tags - link to documentation.
|
||||
__( 'Webhook and REST API users can now use v3 subscription endpoints. Click here to %1$slearn more%2$s about the REST API and check out the technical API docs %3$shere%2$s.', 'woocommerce-subscriptions' ),
|
||||
'<a href="https://docs.woocommerce.com/document/woocommerce-rest-api/">',
|
||||
'<a href="https://woocommerce.com/document/woocommerce-rest-api/">',
|
||||
'</a>',
|
||||
'<a href="https://woocommerce.github.io/subscriptions-rest-api-docs/">'
|
||||
),
|
||||
|
|
@ -96,14 +96,14 @@ class WCS_Upgrade_Notice_Manager {
|
|||
'description' => sprintf(
|
||||
// translators: 1-2: opening/closing <a> tags - link to documentation.
|
||||
__( 'Subscriptions is now compatible with the WooCommerce cart and checkout blocks. You can learn more about the compatibility status of the cart & checkout blocks %1$shere%2$s.', 'woocommerce-subscriptions' ),
|
||||
'<a href="https://docs.woocommerce.com/document/cart-checkout-blocks-support-status/">', '</a>'
|
||||
'<a href="https://woocommerce.com/document/woocommerce-store-editing/customizing-cart-and-checkout/#compatible-extensions">', '</a>'
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// translators: placeholder is Subscription version string ('3.1')
|
||||
$notice->set_heading( sprintf( __( 'Welcome to WooCommerce Subscriptions %s!', 'woocommerce-subscriptions' ), $version ) );
|
||||
$notice->set_content_template( 'update-welcome-notice.php', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory() . '/includes/upgrades/templates/', array(
|
||||
$notice->set_content_template( 'update-welcome-notice.php', WC_Subscriptions_Plugin::instance()->get_plugin_directory() . '/includes/upgrades/templates/', array(
|
||||
'version' => $version,
|
||||
'features' => $features,
|
||||
) );
|
||||
|
|
|
|||
|
|
@ -79,10 +79,8 @@ class WCS_Webhooks {
|
|||
'woocommerce_process_shop_subscription_meta',
|
||||
),
|
||||
'subscription.updated' => array(
|
||||
'wcs_api_subscription_updated',
|
||||
'woocommerce_subscription_status_changed',
|
||||
'wcs_webhook_subscription_updated',
|
||||
'woocommerce_process_shop_subscription_meta',
|
||||
'woocommerce_update_subscription',
|
||||
),
|
||||
'subscription.deleted' => array(
|
||||
'woocommerce_subscription_trashed',
|
||||
|
|
@ -134,6 +132,12 @@ class WCS_Webhooks {
|
|||
|
||||
switch ( $webhook->get_api_version() ) {
|
||||
case 'legacy_v3':
|
||||
|
||||
// @phpstan-ignore-next-line Ignore legacy referencies.
|
||||
if ( is_null( wc()->api ) ) {
|
||||
throw new \Exception( 'The Legacy REST API plugin is not installed on this site. More information: https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/ ' );
|
||||
}
|
||||
|
||||
WC()->api->WC_API_Subscriptions->register_routes( array() );
|
||||
$payload = WC()->api->WC_API_Subscriptions->get_subscription( $resource_id );
|
||||
break;
|
||||
|
|
@ -141,6 +145,7 @@ class WCS_Webhooks {
|
|||
case 'wp_api_v2':
|
||||
// There is no v2 subscritpion endpoint support so they fall back to v1.
|
||||
$request = new WP_REST_Request( 'GET' );
|
||||
// @phpstan-ignore class.nameCase
|
||||
$controller = new WC_REST_Subscriptions_v1_Controller();
|
||||
|
||||
$request->set_param( 'id', $resource_id );
|
||||
|
|
@ -149,7 +154,7 @@ class WCS_Webhooks {
|
|||
|
||||
break;
|
||||
case 'wp_api_v3':
|
||||
$payload = wc()->api->get_endpoint_data( "/wc/v3/subscriptions/{$resource_id}" );
|
||||
$payload = WCS_API::get_wc_api_endpoint_data( "/wc/v3/subscriptions/{$resource_id}" );
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class WCS_Zero_Initial_Payment_Checkout_Manager {
|
|||
*/
|
||||
public static function cart_needs_payment( $cart_needs_payment ) {
|
||||
if ( ! self::zero_initial_checkout_requires_payment() ) {
|
||||
remove_filter( 'woocommerce_cart_needs_payment', 'WC_Subscriptions_Cart::cart_needs_payment', 10, 2 );
|
||||
remove_filter( 'woocommerce_cart_needs_payment', 'WC_Subscriptions_Cart::cart_needs_payment' );
|
||||
}
|
||||
|
||||
return $cart_needs_payment;
|
||||
|
|
@ -77,7 +77,7 @@ class WCS_Zero_Initial_Payment_Checkout_Manager {
|
|||
*/
|
||||
public static function order_needs_payment( $needs_payment ) {
|
||||
if ( ! self::zero_initial_checkout_requires_payment() ) {
|
||||
remove_filter( 'woocommerce_order_needs_payment', 'WC_Subscriptions_Order::order_needs_payment', 10, 3 );
|
||||
remove_filter( 'woocommerce_order_needs_payment', 'WC_Subscriptions_Order::order_needs_payment' );
|
||||
}
|
||||
|
||||
return $needs_payment;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
|||
*/
|
||||
protected function update_item( $item ) {
|
||||
// Schedule the individual repair actions to run in 1 hr to give us the best chance at scheduling all the actions before they start running and clogging up the queue.
|
||||
as_schedule_single_action( gmdate( 'U' ) + HOUR_IN_SECONDS, $this->repair_hook, array( 'repair_object' => $item ) );
|
||||
as_schedule_single_action( (int) gmdate( 'U' ) + HOUR_IN_SECONDS, $this->repair_hook, array( 'repair_object' => $item ) );
|
||||
unset( $this->items_to_repair[ $item ] );
|
||||
}
|
||||
|
||||