mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-17 23:02:56 +00:00
Updates to 5.2.0
This commit is contained in:
205
bin/install-wp-tests.sh
Executable file
205
bin/install-wp-tests.sh
Executable file
@@ -0,0 +1,205 @@
|
||||
#!/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
|
146
changelog.txt
146
changelog.txt
@@ -1,4 +1,150 @@
|
||||
*** WooCommerce Subscriptions Changelog ***
|
||||
|
||||
2023-07-05 - version 5.2.0
|
||||
* Fix: Resolved an issue that prevented the selected Shipping Method from being saved when switching an assembled Product Bundle.
|
||||
* Fix: When HPOS is enabled, permanently deleting a subscription related order wasn't updating the related orders cache properly.
|
||||
* Fix: Added logic to check if the recurring cart array is present before displaying the recurring totals section in the cart.
|
||||
* Dev: Updated subscriptions-core to 5.8.0
|
||||
|
||||
2023-06-05 - version 5.1.3
|
||||
* Fix: Resolved an issue with customers being redirected to an incorrect Pay for Order URL after login.
|
||||
* Dev: Updated subscriptions-core to 5.7.2
|
||||
|
||||
2023-05-11 - version 5.1.2
|
||||
* Fix: Resolve errors for third-party code using the URLs returned from WC_Subscriptions_Admin::add_subscription_url() and WCS_Cart_Renewal::get_checkout_payment_url() because they were erroneously escaped. #4526
|
||||
* Dev: Enable third-party code to alter the delete payment token URL returned from flag_subscription_payment_token_deletions. #4526
|
||||
* Dev: Update subscriptions-core to 5.7.1. #4526
|
||||
|
||||
2023-05-05 - version 5.1.1
|
||||
* Fix: Error when third-party extensions use the `woocommerce_subscriptions_add_switch_query_args` filter. #4522
|
||||
|
||||
2023-05-04 - version 5.1.0
|
||||
* Fix: Correctly determine subscription free shipping eligibility when the initial payment cart isn't eligible. Fixes erroneous "Invalid recurring shipping method" errors on checkout. #4513
|
||||
* Fix: Fatal error from third-party extensions using the `woocommerce_update_order` expecting the second parameter. #4519
|
||||
* Dev: Fixed precision loss notice that occurs when running PHP 8.1. #4513
|
||||
* Dev: Fix phpcs and semgrep warnings to improve code quality. #4513 #4514
|
||||
* Dev: Use `wp_safe_redirect()` when processing a payment method change request. #4513
|
||||
* Dev: Update subscriptions-core to 5.7.0. #4519
|
||||
* Dev: Pass the subscription object as the second parameter to `woocommerce_update_subscription` hook (and `woocommerce_update_order` for backwards compatibility). #4519
|
||||
* Dev: Return a response from the WC_Subscription::set_status() function in line with the parent WC_Order::set_status() function. #4519
|
||||
* Dev: Add the 'wcs_recurring_shipping_package_rates_match_standard_rates' filter to enable third-parties to override whether the subscription packages match during checkout validation. #4519
|
||||
|
||||
2023-03-31 - version 5.0.1
|
||||
* Fix: WooCommerce dependency check was erroneously failing on stores with other plugins including a woocommerce.php file. #4497
|
||||
|
||||
2023-03-10 - version 5.0.0
|
||||
* Fix: When a customer changes their address during a subscription switch, don't save their new address in the postmeta table when HPOS is enabled. #4489
|
||||
* Fix: When HPOS is enabled, changing your address while paying for a renewal order will update the address on the subscription. #4491
|
||||
* Fix: Prevent admin error notices being shown for the "subscription trial end" event that was caused by no callbacks being attached to this scheduled action. #4491
|
||||
* Fix: Prevent fatal error when copying the `_shipping_address` meta data where the value is not an array. #4495
|
||||
* Update: Use the WC installed version to determine if Subscription dependencies are met rather than the database version.
|
||||
* Dev: Update subscriptions-core to 5.5.0. #4491
|
||||
|
||||
2023-02-22 - version 4.9.1
|
||||
* Fix: Revert minimum required version of WooCommerce to 6.5 due to fatal errors on some sites.
|
||||
|
||||
2023-02-22 - version 4.9.0
|
||||
* Add: Declare WooCommerce Subscriptions compatible with High-Performance Order Storage.
|
||||
* Dev: Update subscriptions-core to 5.4.0.
|
||||
* Dev: Remove the recurring shipping method cache that caused bugs for third-party plugins like Conditional Shipping and Payments.
|
||||
* Dev: Bump minimum required version of WooCommerce to 7.0.
|
||||
|
||||
2023-02-01 - version 4.8.1
|
||||
* Fix: Fatal error when loading the Edit Subscription page with custom admin billing or shipping fields.
|
||||
* Dev: Update subscriptions-core to 5.3.1.
|
||||
|
||||
2023-01-30 - version 4.8.0
|
||||
* Add: Highlight subscriptions with overdue payment in list view with red icon & tooltip.
|
||||
* Add: New wcs_set_order_address() helper function to set an array of address fields on an order or subscription.
|
||||
* Update: Admin subscription reports are disabled on stores that have opted into HPOS without data syncing enabled.
|
||||
* Fix: Shipping address correctly set when resubscribing or switching subscriptions that contain different billing and shipping addresses.
|
||||
* Fix: When processing customer requests to update all their subscription payment methods, ensure the updated subscription is used to fetch the new payment meta, not and old instance.
|
||||
* Fix: Catch exceptions when changing payment method associated with a subscription to avoid fatal errors.
|
||||
* Fix: Show the payment retries metabox for renewal orders that have retry attempts on stores that have HPOS enabled.
|
||||
* Fix: Scheduled retry actions are now cancelled when trashing/deleting a renewal order on stores that have HPOS enabled.
|
||||
* Fix: On HPOS stores, return the correct count per subscription status from the `/system_status` WC API endpoint.
|
||||
* Fix: Refactor `WC_Subscriptions_Switcher::process_checkout()` to support stores with HPOS enabled.
|
||||
* Fix: Refactor `WC_REST_Subscriptions_V1_Controller::get_subscription_orders()` to support stores with HPOS enabled.
|
||||
* Fix: Edit, add, and list Subscription admin pages now work when HPOS is enabled.
|
||||
* Fix: Fixed issues where multiple subscription purchases wouldn't appear on the My Account > Subscriptions screen, on HPOS environments.
|
||||
* Fix: Refactor `WCS_Meta_Box_Subscription_Data::save` to support HPOS stores, fixing a PHP warning notice when updating an order via the Edit Order screen.
|
||||
* Fix: Set the `download_permissions_granted` value when purchasing a downloadable subscription product when HPOS is enabled.
|
||||
* Fix: When a customer changes their address on their account or subscription, make sure the new address is saved when HPOS is enabled.
|
||||
* Fix: Removed the potential for an infinite loop when getting a subscription's related orders while the subscription is being loaded.
|
||||
* Fix: Refactor `WC_Subscriptions_Renewal_Order` and `WC_Subscriptions_Tracker` classes to support HPOS stores.
|
||||
* Fix: "Subscriptions by Payment Gateway" in WooCommerce → Status now shows the correct values when HPOS is enabled.
|
||||
* Fix: Check whether the order actually exists before accessing order properties in wcs_order_contains_subscription().
|
||||
* Fix: When a subscription's parent order is trashed or deleted, make sure the related subscription is also trashed or deleted on stores with HPOS enabled.
|
||||
* Fix: When a subscription is trashed or deleted, make sure it is cancelled first on stores with HPOS enabled.
|
||||
* Fix: Merge any custom meta_query args passed to wcs_get_orders_with_meta_query() to avoid overriding WC core args that map onto meta_query.
|
||||
* Fix: Prevent erroneously resyncing a subscription every time it is loaded from the database on HPOS environments.
|
||||
* Fix: On HPOS environments, ensure subscription related order caches are updated when relationship order meta (eg `_subscription_renewal` or `_subscription_switch`) is updated.
|
||||
* Fix: On HPOS environments, update related orders cache when subscription is trashed, deleted, or restored / untrashed.
|
||||
* Fix: Replace code using wp_count_posts(), get_post_type(), get_posts and wp_delete_post() with equivalent WC Data Store functions to support stores that have HPOS enabled.
|
||||
* Dev: Add subscriptions-core library version to the WooCommerce system status report.
|
||||
* Dev: Introduced a WCS_Object_Data_Cache_Manager and WCS_Object_Data_Cache_Manager_Many_To_One class as HPOS equivalents of the WCS_Post_Meta_Cache_Manager classes.
|
||||
* Dev: Introduced a new `untrash_order()` in the `WCS_Orders_Table_Subscription_Data_Store` class to fix untrashing subscriptions on stores that have HPOS enabled.
|
||||
* Dev: Moved the trash, untrash & delete related `add_actions()` in the `WC_Subscriptions_Manager` class to be added on the `woocommerce_loaded` action.
|
||||
* Dev: Fix phpcs violations in the `WC_Subscriptions_Tracker` and `WCS_Admin_System_Status` classes to improve code quality.
|
||||
* Dev: Deprecate the `WC_Subscriptions_Switcher::update_shipping_methods()` function.
|
||||
* Dev: Fix phpcs violations in the `WC_REST_Subscription_System_Status_Manager` class to improve code quality.
|
||||
* Dev: Remove deprecated `strptime` function in favour of `DateTime::createFromFormat`.
|
||||
* Dev: Update subscriptions-core to 5.3.0.
|
||||
* Dev: Bump minimum required version of WooCommerce to 6.5.
|
||||
|
||||
2022-12-06 - version 4.7.0
|
||||
* Add: New wcs_get_orders_with_meta_query() helper function to query for orders and subscriptions.
|
||||
* Add: New WCS_Orders_Table_Subscription_Data_Store class to support subscriptions stored in High-Performance Order Storage (HPOS).
|
||||
* Add: New WCS_Orders_Table_Data_Store_Controller class to load the proper subscriptions data store when the store has HPOS enabled.
|
||||
* Add: New data copier class to copy data to subscriptions and related orders in place of direct database queries in prepraration for HPOS support.
|
||||
* Fix: Set payment tokens when copying data between orders and subscriptions in a CRUD compatible way. Fixes PHP notices during renewal order process.
|
||||
* Fix: Infinite loop that can occur with `WCS_Orders_Table_Subscription_Data_Store::read_multiple()` on HPOS-enabled stores.
|
||||
* Fix: On HPOS stores, when querying for subscriptions with wcs_get_orders_with_meta_query() with status 'any', ensure that wc_get_orders() queries for subscription statuses.
|
||||
* Fix: On HPOS stores, when saving a subscription make sure subscription properties (ie `_requires_manual_renewal`) are saved to the database.
|
||||
* Fix: On HPOS stores, when a subscription is loaded from the database, make sure all core subscription properties are read directly from meta.
|
||||
* Fix: When viewing My Account > Subscriptions, fix an issue where no subscriptions were listed when HPOS is enabled.
|
||||
* Fix: On HPOS stores, ensure payment tokens are copied from the subscription to the renewal order.
|
||||
* Fix: Refactor `WCS_Meta_Box_Schedule::save` to support HPOS stores, fixing a PHP warning notice when updating an order via the Edit Order screen.
|
||||
* Fix: Return a fresh instance of the renewal order after creating it. Fixes caching issues on HPOS sites where the returned order has no line items.
|
||||
* Fix: Processing a manual renewal order with HPOS and data syncing enabled correctly saves the related order cache metadata on the subscription and prevents the post and order meta data getting out of sync.
|
||||
* Fix: Use supported CRUD apis to determine if subscriptions are present on store (`wcs_do_subscriptions_exist`)
|
||||
* Fix: With HPOS and data syncing enabled, updating the status of a pending manual renewal order to a paid status correctly activates the related subscription.
|
||||
* Fix: Switch orders not appearing in related orders table on edit subscription screen when HPOS is active.
|
||||
* Fix: On HPOS stores, make sure the links in the related-orders table redirect to the new Edit Order URL.
|
||||
* Fix: When saving sync meta data on a new subscription, use 'woocommerce_new_subscription' instead of 'save_post'. This is to prevent errors when purchasing a subscription on stores that have HPOS enabled.
|
||||
* Fix: When WooCommerce is network activated on multisites, don't show the "WooCommerce Subscriptions is inactive".
|
||||
* Update: Improve maybe_add_subscription_meta() and subscription_contains_synced_product() inside our WC_Subscriptions_Synchroniser class to use CRUD methods.
|
||||
* Update: Refactor the `wcs_is_subscription` helper function to support HPOS.
|
||||
* Update: Refactor our Related Orders data store classes (WCS_Related_Order_Store_Cached_CPT and WCS_Related_Order_Store_CPT) to use CRUD methods to support subscriptions and orders stored in HPOS.
|
||||
* Update: Display related orders table when viewing the new "Edit Order" page (HPOS enabled stores).
|
||||
* Update: Replace instances of `get_posts()` across codebase with new wcs_get_orders_with_meta_query() function.
|
||||
* Update: The subscription creation function `wcs_create_subscription` has been updated to use WooCommerce CRUD methods in preparation for supporting High Performance Order Storage (HPOS).
|
||||
* Update: Improve wcs_copy_order_address() to use modern APIs for setting address fields.
|
||||
* Dev: Removed the deprecated "wcs_subscriptions_for_{$relation_type}_order" dynamic hook used to filter the list of related subscriptions for the given relation type. The following hooks have been removed with no alternative:
|
||||
wcs_subscriptions_for_renewal_order
|
||||
wcs_subscriptions_for_switch_order
|
||||
wcs_subscriptions_for_resubscribe_order
|
||||
* Dev: Introduce a WC_Subscription::set_status() function to handle subscriptions set with a draft or auto-draft status. Replaces the need for the overriding WC_Subscription::get_status() which has been deleted.
|
||||
* Dev: Manual renewal orders created with HPOS and data syncing enabled are properly linked to the subscription by its `_subscription_renewal` meta and backfilled to posts table.
|
||||
* Dev: Update subscriptions-core to 5.1.0
|
||||
* Dev: Replace use of deprecated hook `wcs_renewal_order_meta_query` with `wc_subscriptions_renewal_order_data` in `WC_Subscriptions_Switcher`.
|
||||
* Dev: Usage of \WC_Subscriptions_Core_Plugin::get_plugin_version() is no longer recommended for version detection. \WC_Subscriptions_Core_Plugin::get_library_version() should be used instead.
|
||||
* Dev: Code that was tagged with a version and moved from WooCommerce Subscriptions now explicitly mentions this and shows the correct subscriptions-core and WC Subscriptions versions.
|
||||
* Dev: Refactor the saving of subscription dates in the subscription datastore to separate fetching changes and saving. Enables backfilling subscription dates when HPOS syncing is enabled.
|
||||
* Dev: Replace the use of the deprecated wcs_renewal_order_meta hook with wc_subscription_renewal_order_data in the WCS_Related_Order_Store_Cached_CPT class.
|
||||
* Dev: wcs_get_objects_property and wcs_set_objects_property have been marked as deprecated. Getters/Setters should be used on the objects instead.
|
||||
* Dev: Deprecated the "wcs_{type}_meta_query" dynamic hook used to alter the database query used to fetch the meta data to copy between subscriptions and renewal orders. There is no direct replacement. Third-parties should use the "wc_subscriptions_{type}_data" or "wc_subscriptions_object_data" hooks instead.
|
||||
* Dev: Deprecated the "wcs_{type}_meta" dynamic hook used to filter data copied to subscriptions and renewal orders. Third-parties should use wc_subscriptions_{type}_data instead.
|
||||
wcs_subscription_meta -> wc_subscriptions_subscription_data
|
||||
wcs_parent_meta -> wc_subscriptions_parent_data
|
||||
wcs_resubscribe_order_meta -> wc_subscriptions_resubscribe_order_data
|
||||
wcs_renewal_order_meta -> wc_subscriptions_renewal_order_data
|
||||
* Dev: woocommerce_new_subscription_data hook will only work with CPT datastore and so has been deprecated.
|
||||
* Dev: i18n usage of strftime has been deprecated for subscription titles. Date is now formatted using woocommerce standard date formatting.
|
||||
* Dev: Removes the legacy `woo-includes/` directory.
|
||||
* Dev: Updated internal version references to the version of subscriptions-core.
|
||||
* Dev: Bump minimum required version of WooCommerce to 6.0.
|
||||
|
||||
2022-10-11 - version 4.6.0
|
||||
* Add: Declare incompatibility with WooCommerce High-Performance Order Storage (HPOS).
|
||||
* Fix: Move One Time Shipping metabox fields to use the woocommerce_product_options_shipping_product_data hook introduced in WC 6.0.
|
||||
|
@@ -23,6 +23,12 @@ 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;
|
||||
}
|
||||
|
||||
// Add the reports layout to the WooCommerce -> Reports admin section
|
||||
add_filter( 'woocommerce_admin_reports', __CLASS__ . '::initialize_reports', 12, 1 );
|
||||
|
||||
@@ -33,6 +39,35 @@ class WCS_Admin_Reports {
|
||||
add_action( 'current_screen', __CLASS__ . '::conditional_reporting_includes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an admin notice indicating subscription reports are disabled on HPOS environments with no syncing.
|
||||
*/
|
||||
public static function display_hpos_incompatibility_notice() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
// Only display the admin notice on report admin screens.
|
||||
if ( ! $screen || 'woocommerce_page_wc-reports' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_notice = new WCS_Admin_Notice( 'error' );
|
||||
|
||||
$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>'
|
||||
)
|
||||
)
|
||||
);
|
||||
$admin_notice->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the 'Subscriptions' report type to the WooCommerce reports screen.
|
||||
*
|
||||
@@ -99,7 +134,7 @@ class WCS_Admin_Reports {
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
$screen = get_current_screen();
|
||||
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce-subscriptions' ) );
|
||||
$version = WC_Subscriptions_Plugin::instance()->get_plugin_version();
|
||||
$version = WC_Subscriptions_Core_Plugin::instance()->get_library_version();
|
||||
|
||||
// Reports Subscriptions Pages
|
||||
if ( in_array( $screen->id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) && isset( $_GET['tab'] ) && 'subscriptions' == $_GET['tab'] ) {
|
||||
@@ -172,7 +207,7 @@ class WCS_Admin_Reports {
|
||||
$properties = array(
|
||||
'orders_count' => array_sum( (array) wp_count_posts( 'shop_order' ) ),
|
||||
'subscriptions_count' => array_sum( (array) wp_count_posts( 'shop_subscription' ) ),
|
||||
'subscriptions_version' => WC_Subscriptions_Plugin::instance()->get_plugin_version(),
|
||||
'subscriptions_version' => WC_Subscriptions_Plugin::instance()->get_plugin_version(), // get_plugin_version() is used here to report the correct WCS version.
|
||||
);
|
||||
|
||||
if ( in_array( $name, array( 'subscription-events-by-date', 'upcoming-recurring-revenue', 'subscription-payment-retry' ), true ) ) {
|
||||
|
@@ -258,7 +258,7 @@ class WCS_Report_Dashboard {
|
||||
* @since 2.1
|
||||
*/
|
||||
public static function dashboard_scripts() {
|
||||
wp_enqueue_style( 'wcs-dashboard-report', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/css/dashboard.css' ), array(), WC_Subscriptions_Plugin::instance()->get_plugin_version() );
|
||||
wp_enqueue_style( 'wcs-dashboard-report', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/css/dashboard.css' ), array(), WC_Subscriptions_Plugin::instance()->get_library_version() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -41,13 +41,13 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
||||
echo '<div id="poststuff" class="woocommerce-reports-wide">';
|
||||
echo ' <div id="postbox-container-1" class="postbox-container" style="width: 280px;"><div class="postbox" style="padding: 10px;">';
|
||||
echo ' <h3>' . esc_html__( 'Customer Totals', 'woocommerce-subscriptions' ) . '</h3>';
|
||||
echo ' <p><strong>' . esc_html__( 'Total Subscribers', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->total_customers ) . wcs_help_tip( __( 'The number of unique customers with a subscription of any status other than pending or trashed.', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Active Subscriptions', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->active_subscriptions ) . wcs_help_tip( __( 'The total number of subscriptions with a status of active or pending cancellation.', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Total Subscriptions', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->total_subscriptions ) . wcs_help_tip( __( 'The total number of subscriptions with a status other than pending or trashed.', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Total Subscription Orders', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->initial_order_count + $this->totals->renewal_switch_count ) . wcs_help_tip( __( 'The total number of sign-up, switch and renewal orders placed with your store with a paid status (i.e. processing or complete).', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <p><strong>' . esc_html__( 'Total Subscribers', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->total_customers ) . wc_help_tip( __( 'The number of unique customers with a subscription of any status other than pending or trashed.', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Active Subscriptions', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->active_subscriptions ) . wc_help_tip( __( 'The total number of subscriptions with a status of active or pending cancellation.', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Total Subscriptions', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->total_subscriptions ) . wc_help_tip( __( 'The total number of subscriptions with a status other than pending or trashed.', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Total Subscription Orders', 'woocommerce-subscriptions' ) . '</strong>: ' . esc_html( $this->totals->initial_order_count + $this->totals->renewal_switch_count ) . wc_help_tip( __( 'The total number of sign-up, switch and renewal orders placed with your store with a paid status (i.e. processing or complete).', 'woocommerce-subscriptions' ) ) . '<br />';
|
||||
echo ' <strong>' . esc_html__( 'Average Lifetime Value', 'woocommerce-subscriptions' ) . '</strong>: ';
|
||||
echo wp_kses_post( wc_price( $this->totals->total_customers > 0 ? ( ( $this->totals->initial_order_total + $this->totals->renewal_switch_total ) / $this->totals->total_customers ) : 0 ) );
|
||||
echo wcs_help_tip( __( 'The average value of all customers\' sign-up, switch and renewal orders.', 'woocommerce-subscriptions' ) ) . '</p>';
|
||||
echo wc_help_tip( __( 'The average value of all customers\' sign-up, switch and renewal orders.', 'woocommerce-subscriptions' ) ) . '</p>';
|
||||
echo '</div></div>';
|
||||
$this->display();
|
||||
echo '</div>';
|
||||
@@ -96,13 +96,13 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
|
||||
$columns = array(
|
||||
'customer_name' => __( 'Customer', 'woocommerce-subscriptions' ),
|
||||
// translators: %s: help tip.
|
||||
'active_subscription_count' => sprintf( __( 'Active Subscriptions %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The number of subscriptions this customer has with a status of active or pending cancellation.', 'woocommerce-subscriptions' ) ) ),
|
||||
'active_subscription_count' => sprintf( __( 'Active Subscriptions %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The number of subscriptions this customer has with a status of active or pending cancellation.', 'woocommerce-subscriptions' ) ) ),
|
||||
// translators: %s: help tip.
|
||||
'total_subscription_count' => sprintf( __( 'Total Subscriptions %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The number of subscriptions this customer has with a status other than pending or trashed.', 'woocommerce-subscriptions' ) ) ),
|
||||
'total_subscription_count' => sprintf( __( 'Total Subscriptions %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The number of subscriptions this customer has with a status other than pending or trashed.', 'woocommerce-subscriptions' ) ) ),
|
||||
// translators: %s: help tip.
|
||||
'total_subscription_order_count' => sprintf( __( 'Total Subscription Orders %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The number of sign-up, switch and renewal orders this customer has placed with your store with a paid status (i.e. processing or complete).', 'woocommerce-subscriptions' ) ) ),
|
||||
'total_subscription_order_count' => sprintf( __( 'Total Subscription Orders %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The number of sign-up, switch and renewal orders this customer has placed with your store with a paid status (i.e. processing or complete).', 'woocommerce-subscriptions' ) ) ),
|
||||
// translators: %s: help tip.
|
||||
'customer_lifetime_value' => sprintf( __( 'Lifetime Value from Subscriptions %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The total value of this customer\'s sign-up, switch and renewal orders.', 'woocommerce-subscriptions' ) ) ),
|
||||
'customer_lifetime_value' => sprintf( __( 'Lifetime Value from Subscriptions %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The total value of this customer\'s sign-up, switch and renewal orders.', 'woocommerce-subscriptions' ) ) ),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
@@ -88,11 +88,11 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
|
||||
$columns = array(
|
||||
'product_name' => __( 'Subscription Product', 'woocommerce-subscriptions' ),
|
||||
// translators: %s: help tip.
|
||||
'subscription_count' => sprintf( __( 'Subscription Count %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The number of subscriptions that include this product as a line item and have a status other than pending or trashed.', 'woocommerce-subscriptions' ) ) ),
|
||||
'subscription_count' => sprintf( __( 'Subscription Count %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The number of subscriptions that include this product as a line item and have a status other than pending or trashed.', 'woocommerce-subscriptions' ) ) ),
|
||||
// translators: %s: help tip.
|
||||
'average_recurring_total' => sprintf( __( 'Average Recurring Line Total %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The average line total for this product on each subscription.', 'woocommerce-subscriptions' ) ) ),
|
||||
'average_recurring_total' => sprintf( __( 'Average Recurring Line Total %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The average line total for this product on each subscription.', 'woocommerce-subscriptions' ) ) ),
|
||||
// translators: %s: help tip.
|
||||
'average_lifetime_value' => sprintf( __( 'Average Lifetime Value %s', 'woocommerce-subscriptions' ), wcs_help_tip( __( 'The average line total on all orders for this product line item.', 'woocommerce-subscriptions' ) ) ),
|
||||
'average_lifetime_value' => sprintf( __( 'Average Lifetime Value %s', 'woocommerce-subscriptions' ), wc_help_tip( __( 'The average line total on all orders for this product line item.', 'woocommerce-subscriptions' ) ) ),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
|
@@ -16,7 +16,7 @@ class WC_REST_Subscription_System_Status_Manager {
|
||||
* Attach callbacks.
|
||||
*/
|
||||
public static function init() {
|
||||
add_filter( 'woocommerce_rest_prepare_system_status', array( __CLASS__, 'add_subscription_fields_to_reponse' ) );
|
||||
add_filter( 'woocommerce_rest_prepare_system_status', array( __CLASS__, 'add_subscription_fields_to_response' ) );
|
||||
add_filter( 'woocommerce_rest_system_status_schema', array( __CLASS__, 'add_additional_fields_to_schema' ) );
|
||||
}
|
||||
|
||||
@@ -24,11 +24,13 @@ class WC_REST_Subscription_System_Status_Manager {
|
||||
* Adds subscription fields to System Status response.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @deprecated 4.8.0
|
||||
*
|
||||
* @param WP_REST_Response $response The base system status response.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function add_subscription_fields_to_reponse( $response ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.8.0', __CLASS__ . '::add_subscription_fields_to_response' );
|
||||
$response->data['subscriptions'] = array(
|
||||
'wcs_debug' => defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false,
|
||||
'mode' => ( WCS_Staging::is_duplicate_site() ) ? __( 'staging', 'woocommerce-subscriptions' ) : __( 'live', 'woocommerce-subscriptions' ),
|
||||
@@ -43,6 +45,31 @@ class WC_REST_Subscription_System_Status_Manager {
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds subscription fields to System Status response.
|
||||
*
|
||||
* @since 4.8.0
|
||||
*
|
||||
* @param WP_REST_Response $response The base system status response.
|
||||
* @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() );
|
||||
|
||||
$response->data['subscriptions'] = array(
|
||||
'wcs_debug' => defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false,
|
||||
'mode' => ( WCS_Staging::is_duplicate_site() ) ? __( 'staging', 'woocommerce-subscriptions' ) : __( 'live', 'woocommerce-subscriptions' ),
|
||||
'live_url' => esc_url( WCS_Staging::get_site_url_from_source( 'subscriptions_install' ) ),
|
||||
'statuses' => array_map( 'strval', $count_by_status ), // Enforce values as strings.
|
||||
'report_cache_enabled' => ( 'yes' === get_option( 'woocommerce_subscriptions_cache_updates_enabled', 'yes' ) ),
|
||||
'cache_update_failures' => absint( get_option( 'woocommerce_subscriptions_cache_updates_failures', 0 ) ),
|
||||
'subscriptions_by_payment_gateway' => WCS_Admin_System_Status::get_subscriptions_by_gateway(),
|
||||
'payment_gateway_feature_support' => self::get_payment_gateway_feature_support(),
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the store's payment gateways and the features they support.
|
||||
*
|
||||
@@ -53,7 +80,7 @@ class WC_REST_Subscription_System_Status_Manager {
|
||||
$gateway_features = array();
|
||||
|
||||
foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway_id => $gateway ) {
|
||||
// Some gateways include array keys. For consistancy, only send the values.
|
||||
// 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 ) );
|
||||
|
||||
if ( 'paypal' === $gateway_id && WCS_PayPal::are_reference_transactions_enabled() ) {
|
||||
|
@@ -42,7 +42,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
||||
public function register_routes() {
|
||||
parent::register_routes();
|
||||
|
||||
register_rest_route( $this->namespace, "/{$this->rest_base}/statuses", array(
|
||||
register_rest_route( $this->namespace, "/{$this->rest_base}/statuses", array( // nosemgrep: audit.php.wp.security.rest-route.permission-callback.return-true -- /subscriptions/statuses is a public endpoint and doesn't need any permission checks.
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_statuses' ),
|
||||
|
@@ -61,7 +61,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/statuses', array(
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/statuses', array( // nosemgrep: audit.php.wp.security.rest-route.permission-callback.return-true -- /subscriptions/statuses is a public endpoint and doesn't need any permission checks.
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_statuses' ),
|
||||
|
@@ -60,7 +60,7 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/statuses', array(
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/statuses', array( // nosemgrep: audit.php.wp.security.rest-route.permission-callback.return-true -- /subscriptions/statuses is a public endpoint and doesn't need any permission checks.
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_statuses' ),
|
||||
@@ -301,16 +301,14 @@ class WC_REST_Subscriptions_V1_Controller extends WC_REST_Orders_V1_Controller {
|
||||
$orders = array();
|
||||
|
||||
foreach ( $subscription_orders as $order_id ) {
|
||||
$post = get_post( $order_id );
|
||||
|
||||
// Validate that the order can be loaded before trying to generate a response object for it.
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( ! $order || ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
|
||||
if ( ! $order || ! wc_rest_check_post_permissions( $this->post_type, 'read', $order_id ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response = $this->prepare_item_for_response( $post, $request );
|
||||
$response = $this->prepare_item_for_response( $order, $request );
|
||||
|
||||
foreach ( array( 'parent', 'renewal', 'switch' ) as $order_type ) {
|
||||
if ( wcs_order_contains_subscription( $order_id, $order_type ) ) {
|
||||
|
161
includes/class-wc-subscriptions-dependency-manager.php
Normal file
161
includes/class-wc-subscriptions-dependency-manager.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Subscriptions_Dependency_Manager class
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 5.0.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class WC_Subscriptions_Dependency_Manager {
|
||||
|
||||
/**
|
||||
* The minimum supported WooCommerce version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $minimum_supported_wc_version;
|
||||
|
||||
/**
|
||||
* @var string|null The active WooCommerce version, or null if WooCommerce is not active.
|
||||
*/
|
||||
private $wc_active_version = null;
|
||||
|
||||
/**
|
||||
* @var bool Whether the active WooCommerce version has been cached.
|
||||
*/
|
||||
private $wc_version_cached = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct( $minimum_supported_wc_version ) {
|
||||
$this->minimum_supported_wc_version = $minimum_supported_wc_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the required dependencies are met.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @return bool True if the required dependencies are met. Otherwise, false.
|
||||
*/
|
||||
public function has_valid_dependencies() {
|
||||
// We don't need to check is_woocommerce_active() here because is_woocommerce_version_supported() will return false if WooCommerce is not active.
|
||||
return $this->is_woocommerce_version_supported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the WooCommerce plugin is active.
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @return bool True if the plugin is active, false otherwise.
|
||||
*/
|
||||
public function is_woocommerce_active() {
|
||||
if ( class_exists( 'WooCommerce' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->get_woocommerce_active_version() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the WooCommerce version is supported by Subscriptions.
|
||||
*
|
||||
* The minimum supported WooCommerce version is defined in the WC_Subscriptions::$wc_minimum_supported_version property.
|
||||
*
|
||||
* @return bool true if the WooCommerce version is supported, false otherwise.
|
||||
*/
|
||||
public function is_woocommerce_version_supported() {
|
||||
return version_compare(
|
||||
// In php8.2+ version_compare requires a string so ensure we always pass a string.
|
||||
// version_compare treats an empty string as less than 0.
|
||||
$this->get_woocommerce_active_version() ?? '',
|
||||
$this->minimum_supported_wc_version,
|
||||
'>='
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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:
|
||||
* 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() {
|
||||
// Use a cached value to avoid calling get_plugins() and looping multiple times.
|
||||
if ( true === $this->wc_version_cached ) {
|
||||
return $this->wc_active_version;
|
||||
}
|
||||
|
||||
$this->wc_version_cached = true;
|
||||
|
||||
// Load plugin.php if it's not already loaded.
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
// Loop through all active plugins and check if WooCommerce is active.
|
||||
foreach ( get_plugins() as $plugin_slug => $plugin_data ) {
|
||||
$is_woocommerce = false;
|
||||
|
||||
/**
|
||||
* The WooCommerce plugin can be installed in two supported ways:
|
||||
* 1. Installed at 'woocommerce/woocommerce.php'
|
||||
* 2. Installed at any '{x}/woocommerce.php' where the plugin name is 'WooCommerce'
|
||||
*/
|
||||
if ( 'woocommerce/woocommerce.php' === $plugin_slug ) {
|
||||
$is_woocommerce = true;
|
||||
} elseif ( 'woocommerce.php' === basename( $plugin_slug ) && 'WooCommerce' === $plugin_data['Name'] ) {
|
||||
$is_woocommerce = true;
|
||||
}
|
||||
|
||||
if ( $is_woocommerce && is_plugin_active( $plugin_slug ) ) {
|
||||
$this->wc_active_version = $plugin_data['Version'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->wc_active_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an admin notice if the required dependencies are not met.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function display_dependency_admin_notice() {
|
||||
if ( ! current_user_can( 'activate_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_notice_content = '';
|
||||
|
||||
if ( ! $this->is_woocommerce_active() ) {
|
||||
$install_url = wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => 'woocommerce',
|
||||
),
|
||||
admin_url( 'update.php' )
|
||||
),
|
||||
'install-plugin_woocommerce'
|
||||
);
|
||||
|
||||
// translators: 1$-2$: opening and closing <strong> tags, 3$-4$: link tags, takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, leads to plugins.php in admin
|
||||
$admin_notice_content = sprintf( esc_html__( '%1$sWooCommerce Subscriptions is inactive.%2$s The %3$sWooCommerce plugin%4$s must be active for WooCommerce Subscriptions to work. Please %5$sinstall & activate WooCommerce »%6$s', 'woocommerce-subscriptions' ), '<strong>', '</strong>', '<a href="http://wordpress.org/extend/plugins/woocommerce/">', '</a>', '<a href="' . esc_url( $install_url ) . '">', '</a>' );
|
||||
} elseif ( ! $this->is_woocommerce_version_supported() ) {
|
||||
// translators: 1$-2$: opening and closing <strong> tags, 3$: minimum supported WooCommerce version, 4$-5$: opening and closing link tags, leads to plugin admin
|
||||
$admin_notice_content = sprintf( esc_html__( '%1$sWooCommerce Subscriptions is inactive.%2$s This version of Subscriptions requires WooCommerce %3$s or newer. Please %4$supdate WooCommerce to version %3$s or newer »%5$s', 'woocommerce-subscriptions' ), '<strong>', '</strong>', $this->minimum_supported_wc_version, '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', '</a>' );
|
||||
}
|
||||
|
||||
if ( $admin_notice_content ) {
|
||||
echo '<div class="error">';
|
||||
echo '<p>' . wp_kses_post( $admin_notice_content ) . '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,6 +8,9 @@
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* @method static WC_Subscriptions_Plugin instance()
|
||||
*/
|
||||
class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
||||
|
||||
/**
|
||||
@@ -52,7 +55,7 @@ class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
||||
$notice = new WCS_Admin_Notice( 'error' );
|
||||
|
||||
// translators: 1-2: opening/closing <b> tags, 3: Subscriptions version.
|
||||
$notice->set_simple_content( sprintf( __( '%1$sWarning!%2$s We can see the %1$sWooCommerce Subscriptions Early Renewal%2$s plugin is active. Version %3$s of %1$sWooCommerce Subscriptions%2$s comes with that plugin\'s functionality packaged into the core plugin. Please deactivate WooCommerce Subscriptions Early Renewal to avoid any conflicts.', 'woocommerce-subscriptions' ), '<b>', '</b>', $this->get_plugin_version() ) );
|
||||
$notice->set_simple_content( sprintf( __( '%1$sWarning!%2$s We can see the %1$sWooCommerce Subscriptions Early Renewal%2$s plugin is active. Version %3$s of %1$sWooCommerce Subscriptions%2$s comes with that plugin\'s functionality packaged into the core plugin. Please deactivate WooCommerce Subscriptions Early Renewal to avoid any conflicts.', 'woocommerce-subscriptions' ), '<b>', '</b>', $this->get_plugin_version() ) ); // get_plugin_version() is used here to report the correct WCS version.
|
||||
$notice->set_actions(
|
||||
array(
|
||||
array(
|
||||
@@ -117,9 +120,14 @@ class WC_Subscriptions_Plugin extends WC_Subscriptions_Core_Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin's version
|
||||
* Gets the version of WooCommerce Subscriptions.
|
||||
*
|
||||
* NOTE: This function should only be used to get the version of WooCommerce Subscriptions.
|
||||
* `WC_Subscriptions_Core_Plugin::instance()->get_plugin_version()` will return either the version of WooCommerce Subscriptions (if installed) or the version of WooCommerce Subscriptions Core.
|
||||
* `WC_Subscriptions_Core_Plugin::instance()->get_library_version()` should be used to get the version of WooCommerce Subscriptions Core.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @see get_library_version()
|
||||
* @return string The plugin version.
|
||||
*/
|
||||
public function get_plugin_version() {
|
||||
|
@@ -64,7 +64,7 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
||||
*/
|
||||
public static function save_coupon_fields( $id ) {
|
||||
// Check the nonce (again).
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) ) {
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ class WCS_Limited_Recurring_Coupon_Manager {
|
||||
$change_payment = isset( $_GET['change_payment_method'] ) ? wc_clean( $_GET['change_payment_method'] ) : 0;
|
||||
$has_limited_coupon = false;
|
||||
|
||||
if ( $change_payment && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'] ) ) {
|
||||
if ( $change_payment && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) ) ) {
|
||||
$subscription = wcs_get_subscription( $change_payment );
|
||||
$has_limited_coupon = self::order_has_limited_recurring_coupon( $subscription );
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ class WCS_Upgrade_Notice_Manager {
|
||||
*/
|
||||
public static function maybe_show_admin_notice() {
|
||||
|
||||
if ( isset( $_GET['_wcsnonce'] ) && wp_verify_nonce( $_GET['_wcsnonce'], 'dismiss_upgrade_notice' ) && ! empty( $_GET['dismiss_upgrade_notice'] ) && self::$version === $_GET['dismiss_upgrade_notice'] ) {
|
||||
if ( isset( $_GET['_wcsnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wcsnonce'] ) ) , 'dismiss_upgrade_notice' ) && ! empty( $_GET['dismiss_upgrade_notice'] ) && self::$version === $_GET['dismiss_upgrade_notice'] ) {
|
||||
delete_option( self::$option_name );
|
||||
return;
|
||||
}
|
||||
|
@@ -127,7 +127,10 @@ class WCS_Webhooks {
|
||||
$webhook = new WC_Webhook( $id );
|
||||
$current_user = get_current_user_id();
|
||||
|
||||
wp_set_current_user( $webhook->get_user_id() );
|
||||
// Build the payload with the same user context as the user who created
|
||||
// the webhook -- this avoids permission errors as background processing
|
||||
// runs with no user context.
|
||||
wp_set_current_user( $webhook->get_user_id() ); // phpcs:ignore Generic.PHP.ForbiddenFunctions.Discouraged -- user ID can only be provided by WC_Webhook::get_user_id() which is the webhook author's ID.
|
||||
|
||||
switch ( $webhook->get_api_version() ) {
|
||||
case 'legacy_v3':
|
||||
@@ -150,7 +153,8 @@ class WCS_Webhooks {
|
||||
break;
|
||||
}
|
||||
|
||||
wp_set_current_user( $current_user );
|
||||
// Restore the current user.
|
||||
wp_set_current_user( $current_user ); // phpcs:ignore Generic.PHP.ForbiddenFunctions.Discouraged -- this ID was provided by get_current_user_id() above.
|
||||
}
|
||||
|
||||
return $payload;
|
||||
|
@@ -173,9 +173,9 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
|
||||
|
||||
if ( $subscription ) {
|
||||
// Copy all meta, excluding core properties (totals etc), from the subscription to new renewal order
|
||||
add_filter( 'wcs_renewal_order_meta', array( $this, 'exclude_core_order_meta_properties' ) );
|
||||
add_filter( 'wc_subscriptions_renewal_order_data', array( $this, 'exclude_core_properties_from_copy' ) );
|
||||
wcs_copy_order_meta( $subscription, $order, 'renewal_order' );
|
||||
remove_filter( 'wcs_renewal_order_meta', array( $this, 'exclude_core_order_meta_properties' ) );
|
||||
remove_filter( 'wc_subscriptions_renewal_order_data', array( $this, 'exclude_core_properties_from_copy' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
|
||||
$subscription = wcs_get_subscription( $cart_item[ $this->cart_item_key ]['subscription_id'] );
|
||||
|
||||
// Mark this order as a renewal.
|
||||
$order->update_meta_data( '_subscription_renewal', $subscription->get_id() );
|
||||
WCS_Related_Order_Store::instance()->add_relation( $order, $subscription, 'renewal' );
|
||||
|
||||
// Mark this order as an early renewal.
|
||||
$order->update_meta_data( '_subscription_renewal_early', $subscription->get_id() );
|
||||
@@ -389,7 +389,7 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static function allow_early_renewal_order_cancellation() {
|
||||
if ( isset( $_GET['cancel_order'] ) && isset( $_GET['order_id'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'woocommerce-cancel_order' ) ) {
|
||||
if ( isset( $_GET['cancel_order'], $_GET['order_id'], $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'woocommerce-cancel_order' ) ) {
|
||||
$order_id = absint( $_GET['order_id'] );
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
@@ -399,6 +399,64 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes core properties from being copied to the renewal order when an early renewal is created.
|
||||
*
|
||||
* These core order properties are set when the order is created via the checkout and should not be
|
||||
* copied from the subscription in case they were changed via the checkout process.
|
||||
*
|
||||
* @since 4.8.0
|
||||
*
|
||||
* @param array $order_data The data to be copied to the early renewal order. Each value is keyed by the meta key. Example format [ '_meta_key' => 'meta_value' ].
|
||||
* @return array $order_data The filtered set of order data.
|
||||
*/
|
||||
public function exclude_core_properties_from_copy( $order_data ) {
|
||||
$excluded_properties = array(
|
||||
'_customer_user',
|
||||
'_order_currency',
|
||||
'_prices_include_tax',
|
||||
'_order_version',
|
||||
'_shipping_first_name',
|
||||
'_shipping_last_name',
|
||||
'_shipping_company',
|
||||
'_shipping_address_1',
|
||||
'_shipping_address_2',
|
||||
'_shipping_city',
|
||||
'_shipping_state',
|
||||
'_shipping_postcode',
|
||||
'_shipping_country',
|
||||
'_shipping_address_index',
|
||||
'_billing_first_name',
|
||||
'_billing_last_name',
|
||||
'_billing_company',
|
||||
'_billing_address_1',
|
||||
'_billing_address_2',
|
||||
'_billing_city',
|
||||
'_billing_state',
|
||||
'_billing_postcode',
|
||||
'_billing_country',
|
||||
'_billing_email',
|
||||
'_billing_phone',
|
||||
'_billing_address_index',
|
||||
'is_vat_exempt',
|
||||
'_customer_ip_address',
|
||||
'_customer_user_agent',
|
||||
'_cart_discount',
|
||||
'_cart_discount_tax',
|
||||
'_order_shipping',
|
||||
'_order_shipping_tax',
|
||||
'_order_tax',
|
||||
'_order_total',
|
||||
);
|
||||
|
||||
// Remove the core order properties from the data copied from the subscription.
|
||||
foreach ( $excluded_properties as $meta_key ) {
|
||||
unset( $order_data[ $meta_key ] );
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes core order meta properties from the meta copied from the subscription.
|
||||
*
|
||||
@@ -406,11 +464,13 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
|
||||
* when copying meta from the subscription to the early renewal order.
|
||||
*
|
||||
* @since 2.5.6
|
||||
* @deprecated 4.8.0
|
||||
*
|
||||
* @param array $order_meta The meta keys and values to copy from the subscription to the early renewal order.
|
||||
* @return array The subscription meta to copy to the early renewal order.
|
||||
*/
|
||||
public function exclude_core_order_meta_properties( $order_meta ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.8.0', __CLASS__ . '::exclude_core_properties_from_copy()' );
|
||||
|
||||
// Additional meta keys to exclude. These are in addition to the meta keys already excluded by wcs_copy_order_meta().
|
||||
$excluded_meta_keys = array(
|
||||
|
@@ -103,7 +103,7 @@ class WCS_Early_Renewal_Modal_Handler {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $_GET['wcs_nonce'], 'wcs-renew-early-modal-' . $_GET['subscription_id'] ) ) {
|
||||
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['wcs_nonce'] ) ), 'wcs-renew-early-modal-' . absint( $_GET['subscription_id'] ) ) ) {
|
||||
wc_add_notice( __( 'There was an error with your request. Please try again.', 'woocommerce-subscriptions' ), 'error' );
|
||||
self::redirect();
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ function wcs_get_early_renewal_url( $subscription ) {
|
||||
* @param string $url The early renewal URL.
|
||||
* @param int $subscription_id The ID of the subscription to renew to.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_subscriptions_get_early_renewal_url', $url, $subscription_id );
|
||||
return apply_filters( 'woocommerce_subscriptions_get_early_renewal_url', $url, $subscription_id ); // nosemgrep: audit.php.wp.security.xss.query-arg -- False positive. $url is escaped in the template and escaping URLs should be done at the point of output or usage.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -36,7 +36,7 @@ class WC_Subscriptions_Payment_Gateways extends WC_Subscriptions_Core_Payment_Ga
|
||||
return $available_gateways;
|
||||
}
|
||||
|
||||
if ( ! WC_Subscriptions_Cart::cart_contains_subscription() && ( ! isset( $_GET['order_id'] ) || ! wcs_order_contains_subscription( $_GET['order_id'] ) ) ) {
|
||||
if ( ! WC_Subscriptions_Cart::cart_contains_subscription() && ( ! isset( $_GET['order_id'] ) || ! wcs_order_contains_subscription( absint( $_GET['order_id'] ) ) ) ) {
|
||||
return $available_gateways;
|
||||
}
|
||||
|
||||
|
@@ -20,16 +20,26 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class WCS_Meta_Box_Payment_Retries {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
* Outputs the Payment retry metabox.
|
||||
*
|
||||
* @param WC_Order|WP_Post $order The order object or post object.
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
public static function output( $order ) {
|
||||
// For backwards compatibility the $order parameter could be a Post.
|
||||
if ( is_a( $order, 'WP_Post' ) ) {
|
||||
$order = wc_get_order( $order->ID );
|
||||
}
|
||||
|
||||
if ( ! wcs_is_order( $order ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
WC()->mailer();
|
||||
|
||||
$retries = WCS_Retry_Manager::store()->get_retries_for_order( $post->ID );
|
||||
$retries = WCS_Retry_Manager::store()->get_retries_for_order( $order->get_id() );
|
||||
|
||||
include_once( dirname( __FILE__ ) . '/html-retries-table.php' );
|
||||
|
||||
do_action( 'woocommerce_subscriptions_retries_meta_box', $post->ID, $retries );
|
||||
do_action( 'woocommerce_subscriptions_retries_meta_box', $order->get_id(), $retries );
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ class WCS_Retry_Admin {
|
||||
add_filter( 'woocommerce_subscription_settings', array( $this, 'add_settings' ) );
|
||||
|
||||
if ( WCS_Retry_Manager::is_retry_enabled() ) {
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 50 );
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 50, 2 );
|
||||
|
||||
add_filter( 'wcs_display_date_type', array( $this, 'maybe_hide_date_type' ), 10, 3 );
|
||||
|
||||
@@ -37,13 +37,26 @@ class WCS_Retry_Admin {
|
||||
|
||||
/**
|
||||
* Add a meta box to the Edit Order screen to display the retries relating to that order
|
||||
*
|
||||
* @param string $post_type Optional. Post type. Default empty.
|
||||
* @param WC_Order|WP_Post $order Optional. The Order object. Default null. If null, the global $post is used.
|
||||
*/
|
||||
public function add_meta_boxes() {
|
||||
global $current_screen, $post_ID;
|
||||
public function add_meta_boxes( $post_type = '', $order = null ) {
|
||||
/**
|
||||
* Get the order parameter into a consistent type.
|
||||
*
|
||||
* For backwards compatibility, if the order parameter isn't provided, use the global $post_id.
|
||||
* On CPT stores, the order param will be a WP Post object.
|
||||
*/
|
||||
if ( is_null( $order ) || is_a( $order, 'WP_Post' ) ) {
|
||||
global $post_ID;
|
||||
$order_id = $order ? $order->ID : $post_ID;
|
||||
$order = wc_get_order( $order_id );
|
||||
}
|
||||
|
||||
// Only display the meta box if an order relates to a subscription
|
||||
if ( 'shop_order' === get_post_type( $post_ID ) && wcs_order_contains_renewal( $post_ID ) && WCS_Retry_Manager::store()->get_retry_count_for_order( $post_ID ) > 0 ) {
|
||||
add_meta_box( 'renewal_payment_retries', __( 'Automatic Failed Payment Retries', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Payment_Retries::output', 'shop_order', 'normal', 'low' );
|
||||
// Only display the meta box if an order relates to a subscription and there are retries for that order.
|
||||
if ( wcs_is_order( $order ) && wcs_order_contains_renewal( $order ) && WCS_Retry_Manager::store()->get_retry_count_for_order( $order->get_id() ) > 0 ) {
|
||||
add_meta_box( 'renewal_payment_retries', __( 'Automatic Failed Payment Retries', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Payment_Retries::output', wcs_get_page_screen_id( 'shop_order' ), 'normal', 'low' );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,19 +17,19 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
<th><?php esc_html_e( 'Retry Date', 'woocommerce-subscriptions' ); ?></th>
|
||||
<th>
|
||||
<?php esc_html_e( 'Retry Status', 'woocommerce-subscriptions' ); ?>
|
||||
<?php echo wcs_help_tip( __( 'The status of the automatic payment retry: pending means the retry will be processed in the future, failed means the payment was not successful when retried and completed means the payment succeeded when retried.', 'woocommerce-subscriptions' ) ); ?>
|
||||
<?php echo wc_help_tip( __( 'The status of the automatic payment retry: pending means the retry will be processed in the future, failed means the payment was not successful when retried and completed means the payment succeeded when retried.', 'woocommerce-subscriptions' ) ); ?>
|
||||
</th>
|
||||
<th>
|
||||
<?php esc_html_e( 'Status of Order', 'woocommerce-subscriptions' ); ?>
|
||||
<?php echo wcs_help_tip( __( 'The status applied to the order for the time between when the renewal payment failed or last retry occurred and when this retry was processed.', 'woocommerce-subscriptions' ) ); ?>
|
||||
<?php echo wc_help_tip( __( 'The status applied to the order for the time between when the renewal payment failed or last retry occurred and when this retry was processed.', 'woocommerce-subscriptions' ) ); ?>
|
||||
</th>
|
||||
<th>
|
||||
<?php esc_html_e( 'Status of Subscription', 'woocommerce-subscriptions' ); ?>
|
||||
<?php echo wcs_help_tip( __( 'The status applied to the subscription for the time between when the renewal payment failed or last retry occurred and when this retry was processed.', 'woocommerce-subscriptions' ) ); ?>
|
||||
<?php echo wc_help_tip( __( 'The status applied to the subscription for the time between when the renewal payment failed or last retry occurred and when this retry was processed.', 'woocommerce-subscriptions' ) ); ?>
|
||||
</th>
|
||||
<th>
|
||||
<?php esc_html_e( 'Email', 'woocommerce-subscriptions' ); ?>
|
||||
<?php echo wcs_help_tip( __( 'The email sent to the customer when the renewal payment or payment retry failed to notify them that the payment would be retried.', 'woocommerce-subscriptions' ) ); ?>
|
||||
<?php echo wc_help_tip( __( 'The email sent to the customer when the renewal payment or payment retry failed to notify them that the payment would be retried.', 'woocommerce-subscriptions' ) ); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@@ -56,9 +56,6 @@ class WCS_Retry_Manager {
|
||||
|
||||
add_filter( 'woocommerce_subscription_dates', __CLASS__ . '::add_retry_date_type' );
|
||||
|
||||
add_action( 'delete_post', __CLASS__ . '::maybe_cancel_retry_for_order' );
|
||||
add_action( 'wp_trash_post', __CLASS__ . '::maybe_cancel_retry_for_order' );
|
||||
|
||||
add_action( 'woocommerce_subscription_status_updated', __CLASS__ . '::maybe_cancel_retry', 0, 3 );
|
||||
|
||||
add_action( 'woocommerce_subscriptions_retry_status_updated', __CLASS__ . '::maybe_delete_payment_retry_date', 0, 2 );
|
||||
@@ -74,6 +71,9 @@ class WCS_Retry_Manager {
|
||||
|
||||
add_action( 'woocommerce_subscriptions_before_upgrade', __CLASS__ . '::upgrade', 11, 2 );
|
||||
|
||||
// Attach hooks that depend on WooCommerce being loaded.
|
||||
add_action( 'woocommerce_loaded', array( __CLASS__, 'attach_wc_dependant_hooks' ) );
|
||||
|
||||
if ( ! self::$table_maker ) {
|
||||
self::$table_maker = new WCS_Retry_Table_Maker();
|
||||
add_action( 'init', array( self::$table_maker, 'register_tables' ), 0 );
|
||||
@@ -81,6 +81,26 @@ class WCS_Retry_Manager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches hooks that depend on WooCommerce being loaded.
|
||||
*
|
||||
* We need to use different hooks on stores that have HPOS enabled but to check if this feature
|
||||
* is enabled, we must wait for WooCommerce to be loaded first.
|
||||
*
|
||||
* @since 4.8.0
|
||||
*/
|
||||
public static function attach_wc_dependant_hooks() {
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
// Ensure scheduled retries are deleted when a renewal order is deleted or trashed.
|
||||
add_action( 'woocommerce_before_trash_order', __CLASS__ . '::maybe_cancel_retry_for_order' );
|
||||
add_action( 'woocommerce_before_delete_order', __CLASS__ . '::maybe_cancel_retry_for_order' );
|
||||
} else {
|
||||
// Ensure scheduled retries are deleted when a renewal order is deleted or trashed.
|
||||
add_action( 'delete_post', __CLASS__ . '::maybe_cancel_retry_for_order' );
|
||||
add_action( 'wp_trash_post', __CLASS__ . '::maybe_cancel_retry_for_order' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds any extra status that may be needed for a given order to check if it may
|
||||
* need payment
|
||||
@@ -154,20 +174,20 @@ class WCS_Retry_Manager {
|
||||
/**
|
||||
* When a (renewal) order is trashed or deleted, make sure its retries are also trashed/deleted.
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param int $order_id
|
||||
*/
|
||||
public static function maybe_cancel_retry_for_order( $post_id ) {
|
||||
public static function maybe_cancel_retry_for_order( $order_id ) {
|
||||
|
||||
if ( 'shop_order' == get_post_type( $post_id ) ) {
|
||||
if ( 'shop_order' === WC_Data_Store::load( 'order' )->get_order_type( $order_id ) ) {
|
||||
|
||||
$last_retry = self::store()->get_last_retry_for_order( $post_id );
|
||||
$last_retry = self::store()->get_last_retry_for_order( $order_id );
|
||||
|
||||
// Make sure the last retry is cancelled first so that it is unscheduled via self::maybe_delete_payment_retry_date()
|
||||
if ( null !== $last_retry && 'cancelled' !== $last_retry->get_status() ) {
|
||||
$last_retry->update_status( 'cancelled' );
|
||||
}
|
||||
|
||||
foreach ( self::store()->get_retry_ids_for_order( $post_id ) as $retry_id ) {
|
||||
foreach ( self::store()->get_retry_ids_for_order( $order_id ) as $retry_id ) {
|
||||
self::store()->delete_retry( $retry_id );
|
||||
}
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ class WC_Subscriptions_Switcher {
|
||||
add_filter( 'woocommerce_subscriptions_product_price_string_inclusions', array( __CLASS__, 'customise_product_string_inclusions' ), 12, 2 );
|
||||
|
||||
// Don't carry switch meta data to renewal orders
|
||||
add_filter( 'wcs_renewal_order_meta_query', array( __CLASS__, 'remove_renewal_order_meta_query' ), 10 );
|
||||
add_filter( 'wc_subscriptions_renewal_order_data', array( __CLASS__, 'remove_renewal_order_meta' ), 10 );
|
||||
|
||||
// Don't carry switch meta data to renewal orders
|
||||
add_filter( 'woocommerce_subscriptions_recurring_cart_key', array( __CLASS__, 'get_recurring_cart_key' ), 10, 2 );
|
||||
@@ -149,7 +149,7 @@ class WC_Subscriptions_Switcher {
|
||||
add_action( 'woocommerce_grant_product_download_permissions', array( __CLASS__, 'delay_granting_download_permissions' ), 9, 1 );
|
||||
add_action( 'woocommerce_subscriptions_switch_completed', array( __CLASS__, 'grant_download_permissions' ), 9, 1 );
|
||||
add_action( 'woocommerce_subscription_checkout_switch_order_processed', array( __CLASS__, 'log_switches' ) );
|
||||
add_filter( 'woocommerce_subscriptions_admin_related_orders_to_display', array( __CLASS__, 'display_switches_in_related_order_metabox' ), 10, 3 );
|
||||
add_filter( 'wcs_admin_subscription_related_orders_to_display', array( __CLASS__, 'display_switches_in_related_order_metabox' ), 10, 3 );
|
||||
|
||||
// Override the add to cart text when switch args are present.
|
||||
add_filter( 'woocommerce_product_single_add_to_cart_text', array( __CLASS__, 'display_switch_add_to_cart_text' ), 10, 1 );
|
||||
@@ -188,11 +188,11 @@ class WC_Subscriptions_Switcher {
|
||||
// If the current user doesn't own the subscription, remove the query arg from the URL
|
||||
if ( isset( $_GET['switch-subscription'] ) && isset( $_GET['item'] ) ) {
|
||||
|
||||
$subscription = wcs_get_subscription( $_GET['switch-subscription'] );
|
||||
$line_item = wcs_get_order_item( $_GET['item'], $subscription );
|
||||
$subscription = wcs_get_subscription( absint( $_GET['switch-subscription'] ) );
|
||||
$line_item = wcs_get_order_item( absint( $_GET['item'] ), $subscription );
|
||||
|
||||
// Visiting a switch link for someone elses subscription or if the switch link doesn't contain a valid nonce
|
||||
if ( ! is_object( $subscription ) || empty( $_GET['_wcsnonce'] ) || ! wp_verify_nonce( $_GET['_wcsnonce'], 'wcs_switch_request' ) || empty( $line_item ) || ! self::can_item_be_switched_by_user( $line_item, $subscription ) ) {
|
||||
if ( ! is_object( $subscription ) || empty( $_GET['_wcsnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wcsnonce'] ) ), 'wcs_switch_request' ) || empty( $line_item ) || ! self::can_item_be_switched_by_user( $line_item, $subscription ) ) {
|
||||
|
||||
wp_redirect( remove_query_arg( array( 'switch-subscription', 'auto-switch', 'item', '_wcsnonce' ) ) );
|
||||
exit();
|
||||
@@ -293,7 +293,7 @@ class WC_Subscriptions_Switcher {
|
||||
|
||||
if ( $last_order->needs_payment() ) {
|
||||
// translators: 1$: is the "You have already subscribed to this product" notice, 2$-4$: opening/closing link tags, 3$: an order number
|
||||
$subscribed_notice = sprintf( __( '%1$s Complete payment on %2$sOrder %3$s%4$s to be able to change your subscription.', 'woocommerce-subscriptions' ), $subscribed_notice, sprintf( '<a href="%s">', $last_order->get_checkout_payment_url() ), $last_order->get_order_number(), '</a>' );
|
||||
$subscribed_notice = sprintf( __( '%1$s Complete payment on %2$sOrder %3$s%4$s to be able to change your subscription.', 'woocommerce-subscriptions' ), $subscribed_notice, sprintf( '<a href="%s">', esc_url( $last_order->get_checkout_payment_url() ) ), $last_order->get_order_number(), '</a>' );
|
||||
}
|
||||
|
||||
wc_add_notice( $subscribed_notice, 'notice' );
|
||||
@@ -334,7 +334,7 @@ class WC_Subscriptions_Switcher {
|
||||
public static function add_switch_query_arg_grouped( $permalink ) {
|
||||
|
||||
if ( isset( $_GET['switch-subscription'] ) ) {
|
||||
$permalink = self::add_switch_query_args( $_GET['switch-subscription'], $_GET['item'], $permalink );
|
||||
$permalink = self::add_switch_query_args( absint( $_GET['switch-subscription'] ), absint( $_GET['item'] ), $permalink );
|
||||
}
|
||||
|
||||
return $permalink;
|
||||
@@ -359,7 +359,7 @@ class WC_Subscriptions_Switcher {
|
||||
switch ( $type ) {
|
||||
case 'variable-subscription':
|
||||
case 'subscription':
|
||||
return self::add_switch_query_args( $_GET['switch-subscription'], $_GET['item'], $permalink );
|
||||
return self::add_switch_query_args( absint( $_GET['switch-subscription'] ), absint( $_GET['item'] ), $permalink );
|
||||
|
||||
case 'grouped':
|
||||
// Check to see if the group contains a subscription.
|
||||
@@ -367,7 +367,7 @@ class WC_Subscriptions_Switcher {
|
||||
foreach ( $children as $child ) {
|
||||
$child_product = wc_get_product( $child );
|
||||
if ( 'subscription' === wcs_get_objects_property( $child_product, 'type' ) ) {
|
||||
return self::add_switch_query_args( $_GET['switch-subscription'], $_GET['item'], $permalink );
|
||||
return self::add_switch_query_args( absint( $_GET['switch-subscription'] ), absint( $_GET['item'] ), $permalink );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ class WC_Subscriptions_Switcher {
|
||||
|
||||
echo '<label>';
|
||||
echo sprintf( '<input%s type="checkbox" name="%s" value="1"/> %s', checked( $value, 'yes', false ), esc_attr( $name ), esc_html( $label ) );
|
||||
echo isset( $option['desc_tip'] ) ? wcs_help_tip( $option['desc_tip'], true ) : '';
|
||||
echo isset( $option['desc_tip'] ) ? wc_help_tip( $option['desc_tip'], true ) : '';
|
||||
echo '</label>';
|
||||
}
|
||||
?>
|
||||
@@ -620,9 +620,10 @@ class WC_Subscriptions_Switcher {
|
||||
'_wcsnonce' => wp_create_nonce( 'wcs_switch_request' ),
|
||||
)
|
||||
);
|
||||
|
||||
$permalink = add_query_arg( $query_args, $permalink );
|
||||
|
||||
return apply_filters( 'woocommerce_subscriptions_add_switch_query_args', $permalink, $subscription_id, $item_id );
|
||||
return apply_filters( 'woocommerce_subscriptions_add_switch_query_args', $permalink, $subscription_id, $item_id ); // nosemgrep: audit.php.wp.security.xss.query-arg -- False positive. $permalink is escaped in the template and escaping URLs should be done at the point of output or usage.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -914,8 +915,6 @@ class WC_Subscriptions_Switcher {
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function process_checkout( $order_id, $posted_data = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! WC_Subscriptions_Cart::cart_contains_subscription() ) {
|
||||
return;
|
||||
}
|
||||
@@ -924,16 +923,116 @@ class WC_Subscriptions_Switcher {
|
||||
$switch_order_data = array();
|
||||
|
||||
try {
|
||||
|
||||
foreach ( WC()->cart->recurring_carts as $recurring_cart_key => $recurring_cart ) {
|
||||
$subscription = false;
|
||||
|
||||
// Find the subscription for this recurring cart switch.
|
||||
foreach ( $recurring_cart->get_cart() as $cart_item_key => $cart_item ) {
|
||||
|
||||
// A switch recurring cart shouldn't contain any cart items that are not switched.
|
||||
if ( ! isset( $cart_item['subscription_switch']['subscription_id'] ) ) {
|
||||
continue 2;
|
||||
}
|
||||
|
||||
// All cart items in a switch recurring cart should have the same subscription ID.
|
||||
$subscription = wcs_get_subscription( $cart_item['subscription_switch']['subscription_id'] );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! $subscription ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subscription = wcs_get_subscription( $cart_item['subscription_switch']['subscription_id'] );
|
||||
/**
|
||||
* One-time calculations
|
||||
*
|
||||
* Coupons, fees and shipping are calculated a single time for each recurring cart.
|
||||
*/
|
||||
|
||||
// If there are coupons in the cart, mark them for pending addition
|
||||
$new_coupons = array();
|
||||
|
||||
foreach ( $recurring_cart->get_coupons() as $coupon_code => $coupon ) {
|
||||
$coupon_item = new WC_Subscription_Item_Coupon_Pending_Switch( $coupon_code );
|
||||
$coupon_item->set_props(
|
||||
array(
|
||||
'code' => $coupon_code,
|
||||
'discount' => $recurring_cart->get_coupon_discount_amount( $coupon_code ),
|
||||
'discount_tax' => $recurring_cart->get_coupon_discount_tax_amount( $coupon_code ),
|
||||
)
|
||||
);
|
||||
|
||||
$coupon_data = $coupon->get_data();
|
||||
|
||||
// Avoid storing used_by - it's not needed and can get large.
|
||||
unset( $coupon_data['used_by'] );
|
||||
|
||||
$coupon_item->add_meta_data( 'coupon_data', $coupon_data );
|
||||
$coupon_item->save();
|
||||
|
||||
do_action( 'woocommerce_checkout_create_order_coupon_item', $coupon_item, $coupon_code, $coupon, $subscription );
|
||||
|
||||
$subscription->add_item( $coupon_item );
|
||||
$new_coupons[] = $coupon_item->get_id();
|
||||
}
|
||||
|
||||
$subscription->save();
|
||||
$switch_order_data[ $subscription->get_id() ]['coupons'] = $new_coupons;
|
||||
|
||||
// If there are fees in the cart, mark them for pending addition
|
||||
$new_fee_items = array();
|
||||
foreach ( $recurring_cart->get_fees() as $fee_key => $fee ) {
|
||||
$fee_item = new WC_Subscription_Item_Fee_Pending_Switch();
|
||||
$fee_item->set_props(
|
||||
array(
|
||||
'name' => $fee->name,
|
||||
'tax_status' => $fee->taxable,
|
||||
'amount' => $fee->amount,
|
||||
'total' => $fee->total,
|
||||
'tax' => $fee->tax,
|
||||
'tax_class' => $fee->tax_class,
|
||||
'tax_data' => $fee->tax_data,
|
||||
)
|
||||
);
|
||||
|
||||
$fee_item->save();
|
||||
|
||||
do_action( 'woocommerce_checkout_create_order_fee_item', $fee_item, $fee_key, $fee, $subscription );
|
||||
|
||||
$subscription->add_item( $fee_item );
|
||||
$new_fee_items[] = $fee_item->get_id();
|
||||
}
|
||||
|
||||
$subscription->save();
|
||||
$switch_order_data[ $subscription->get_id() ]['fee_items'] = $new_fee_items;
|
||||
|
||||
if ( ! isset( $switch_order_data[ $subscription->get_id() ]['shipping_line_items'] ) ) {
|
||||
// Add the shipping
|
||||
// Keep a record of the current shipping line items so we can flip any new shipping items to a _pending_switch shipping item.
|
||||
$current_shipping_line_items = array_keys( $subscription->get_shipping_methods() );
|
||||
$new_shipping_line_items = array();
|
||||
|
||||
// Keep a record of the subscription shipping total. Adding shipping methods will cause a new shipping total to be set, we'll need to set it back after.
|
||||
$subscription_shipping_total = $subscription->get_total_shipping();
|
||||
|
||||
WC_Subscriptions_Checkout::add_shipping( $subscription, $recurring_cart );
|
||||
|
||||
// We must save the subscription, we need the Shipping method saved
|
||||
// otherwise the ID is bogus (new:1) and we need it.
|
||||
$subscription->save();
|
||||
|
||||
// Set all new shipping methods to shipping_pending_switch line items
|
||||
foreach ( $subscription->get_shipping_methods() as $shipping_line_item_id => $shipping_meta ) {
|
||||
if ( ! in_array( $shipping_line_item_id, $current_shipping_line_items ) ) {
|
||||
wcs_update_order_item_type( $shipping_line_item_id, 'shipping_pending_switch', $subscription->get_id() );
|
||||
$new_shipping_line_items[] = $shipping_line_item_id;
|
||||
}
|
||||
}
|
||||
|
||||
$subscription->set_shipping_total( $subscription_shipping_total );
|
||||
$switch_order_data[ $subscription->get_id() ]['shipping_line_items'] = $new_shipping_line_items;
|
||||
|
||||
// Loop through cart items to add them to the switched subscription.
|
||||
foreach ( $recurring_cart->get_cart() as $cart_item_key => $cart_item ) {
|
||||
|
||||
// If we haven't calculated a first payment date, fall back to the recurring cart's next payment date.
|
||||
if ( 0 == $cart_item['subscription_switch']['first_payment_timestamp'] ) {
|
||||
@@ -957,12 +1056,7 @@ class WC_Subscriptions_Switcher {
|
||||
|
||||
// If the item is on the same schedule, we can just add it to the new subscription and remove the old item.
|
||||
if ( $is_single_item_subscription || ( false === $is_different_billing_schedule && false === $is_different_payment_date && false === $is_different_length ) ) {
|
||||
|
||||
// Add the new item
|
||||
if ( wcs_is_woocommerce_pre( '3.0' ) ) {
|
||||
$item_id = WC_Subscriptions_Checkout::add_cart_item( $subscription, $cart_item, $cart_item_key );
|
||||
wcs_update_order_item_type( $item_id, 'line_item_pending_switch', $subscription->get_id() );
|
||||
} else {
|
||||
$item = new WC_Order_Item_Pending_Switch;
|
||||
$item->legacy_values = $cart_item; // @deprecated For legacy actions.
|
||||
$item->legacy_cart_item_key = $cart_item_key; // @deprecated For legacy actions.
|
||||
@@ -997,7 +1091,6 @@ class WC_Subscriptions_Switcher {
|
||||
// The subscription is not saved automatically, we need to call 'save' because we added an item
|
||||
$subscription->save();
|
||||
$item_id = $item->get_id();
|
||||
}
|
||||
|
||||
$switched_item_data['add_line_item'] = $item_id;
|
||||
|
||||
@@ -1045,99 +1138,16 @@ class WC_Subscriptions_Switcher {
|
||||
$switch_order_data[ $subscription->get_id() ]['dates']['update'] = $updated_dates;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are coupons in the cart, mark them for pending addition
|
||||
$new_coupons = array();
|
||||
foreach ( $recurring_cart->get_coupons() as $coupon_code => $coupon ) {
|
||||
$coupon_item = new WC_Subscription_Item_Coupon_Pending_Switch( $coupon_code );
|
||||
$coupon_item->set_props(
|
||||
array(
|
||||
'code' => $coupon_code,
|
||||
'discount' => $recurring_cart->get_coupon_discount_amount( $coupon_code ),
|
||||
'discount_tax' => $recurring_cart->get_coupon_discount_tax_amount( $coupon_code ),
|
||||
)
|
||||
);
|
||||
// Avoid storing used_by - it's not needed and can get large.
|
||||
$coupon_data = $coupon->get_data();
|
||||
unset( $coupon_data['used_by'] );
|
||||
$coupon_item->add_meta_data( 'coupon_data', $coupon_data );
|
||||
|
||||
$coupon_item->save();
|
||||
do_action( 'woocommerce_checkout_create_order_coupon_item', $coupon_item, $coupon_code, $coupon, $subscription );
|
||||
$subscription->add_item( $coupon_item );
|
||||
|
||||
$new_coupons[] = $coupon_item->get_id();
|
||||
}
|
||||
$subscription->save();
|
||||
$switch_order_data[ $subscription->get_id() ]['coupons'] = $new_coupons;
|
||||
|
||||
// If there are fees in the cart, mark them for pending addition
|
||||
$new_fee_items = array();
|
||||
foreach ( $recurring_cart->get_fees() as $fee_key => $fee ) {
|
||||
$fee_item = new WC_Subscription_Item_Fee_Pending_Switch();
|
||||
$fee_item->set_props(
|
||||
array(
|
||||
'name' => $fee->name,
|
||||
'tax_status' => $fee->taxable,
|
||||
'amount' => $fee->amount,
|
||||
'total' => $fee->total,
|
||||
'tax' => $fee->tax,
|
||||
'tax_class' => $fee->tax_class,
|
||||
'tax_data' => $fee->tax_data,
|
||||
)
|
||||
);
|
||||
|
||||
$fee_item->save();
|
||||
do_action( 'woocommerce_checkout_create_order_fee_item', $fee_item, $fee_key, $fee, $subscription );
|
||||
$subscription->add_item( $fee_item );
|
||||
|
||||
$new_fee_items[] = $fee_item->get_id();
|
||||
}
|
||||
$subscription->save();
|
||||
$switch_order_data[ $subscription->get_id() ]['fee_items'] = $new_fee_items;
|
||||
|
||||
// Add the shipping
|
||||
// Keep a record of the current shipping line items so we can flip any new shipping items to a _pending_switch shipping item.
|
||||
$current_shipping_line_items = array_keys( $subscription->get_shipping_methods() );
|
||||
$new_shipping_line_items = array();
|
||||
|
||||
// Keep a record of the subscription shipping total. Adding shipping methods will cause a new shipping total to be set, we'll need to set it back after.
|
||||
$subscription_shipping_total = $subscription->get_total_shipping();
|
||||
|
||||
WC_Subscriptions_Checkout::add_shipping( $subscription, $recurring_cart );
|
||||
|
||||
if ( ! wcs_is_woocommerce_pre( '3.0' ) ) {
|
||||
// We must save the subscription, we need the Shipping method saved
|
||||
// otherwise the ID is bogus (new:1) and we need it.
|
||||
$subscription->save();
|
||||
}
|
||||
|
||||
// Set all new shipping methods to shipping_pending_switch line items
|
||||
foreach ( $subscription->get_shipping_methods() as $shipping_line_item_id => $shipping_meta ) {
|
||||
|
||||
if ( ! in_array( $shipping_line_item_id, $current_shipping_line_items ) ) {
|
||||
wcs_update_order_item_type( $shipping_line_item_id, 'shipping_pending_switch', $subscription->get_id() );
|
||||
$new_shipping_line_items[] = $shipping_line_item_id;
|
||||
}
|
||||
}
|
||||
|
||||
if ( wcs_is_woocommerce_pre( '3.0' ) ) {
|
||||
$subscription->set_total( $subscription_shipping_total, 'shipping' );
|
||||
} else {
|
||||
$subscription->set_shipping_total( $subscription_shipping_total );
|
||||
}
|
||||
|
||||
$switch_order_data[ $subscription->get_id() ]['shipping_line_items'] = $new_shipping_line_items;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $switch_order_data as $subscription_id => $switch_data ) {
|
||||
|
||||
// Cancel all the switch orders linked to the switched subscription(s) which haven't been completed yet - excluding this one.
|
||||
$switch_orders = wcs_get_switch_orders_for_subscription( $subscription_id );
|
||||
|
||||
foreach ( $switch_orders as $switch_order_id => $switch_order ) {
|
||||
if ( wcs_get_objects_property( $order, 'id' ) !== $switch_order_id && in_array( $switch_order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed', 'on-hold' ), $switch_order ) ) ) {
|
||||
if ( $order->get_id() !== $switch_order_id && in_array( $switch_order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed', 'on-hold' ), $switch_order ) ) ) {
|
||||
// translators: %s: order number.
|
||||
$switch_order->update_status( 'cancelled', sprintf( __( 'Switch order cancelled due to a new switch order being created #%s.', 'woocommerce-subscriptions' ), $order->get_order_number() ) );
|
||||
}
|
||||
@@ -1150,7 +1160,9 @@ class WC_Subscriptions_Switcher {
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
// There was an error updating the subscription, delete pending switch order.
|
||||
wp_delete_post( $order_id, true );
|
||||
if ( $order instanceof WC_Order ) {
|
||||
$order->delete( true );
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -1161,8 +1173,10 @@ class WC_Subscriptions_Switcher {
|
||||
* @param WC_Order $order The new order
|
||||
* @param WC_Subscription $subscription The original subscription
|
||||
* @param WC_Cart $recurring_cart A recurring cart
|
||||
* @deprecated 4.8.0
|
||||
*/
|
||||
public static function update_shipping_methods( $subscription, $recurring_cart ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.8.0', 'The use of this function is no longer recommended and will be removed in a future version.' );
|
||||
|
||||
// First, archive all the shipping methods
|
||||
foreach ( $subscription->get_shipping_methods() as $shipping_method_id => $shipping_method ) {
|
||||
@@ -1185,8 +1199,18 @@ class WC_Subscriptions_Switcher {
|
||||
* @param WC_Subscription $subscription The original subscription
|
||||
*/
|
||||
public static function maybe_update_subscription_address( $order, $subscription ) {
|
||||
$subscription->set_address( array_diff_assoc( $order->get_address( 'billing' ), $subscription->get_address( 'billing' ) ), 'billing' );
|
||||
$subscription->set_address( array_diff_assoc( $order->get_address( 'shipping' ), $subscription->get_address( 'shipping' ) ), 'shipping' );
|
||||
$billing_address_changes = array_diff_assoc( $order->get_address( 'billing' ), $subscription->get_address( 'billing' ) );
|
||||
$shipping_address_changes = array_diff_assoc( $order->get_address( 'shipping' ), $subscription->get_address( 'shipping' ) );
|
||||
|
||||
if ( wcs_is_woocommerce_pre( '7.1' ) ) {
|
||||
$subscription->set_address( $billing_address_changes, 'billing' );
|
||||
$subscription->set_address( $shipping_address_changes, 'shipping' );
|
||||
} else {
|
||||
$subscription->set_billing_address( $billing_address_changes );
|
||||
$subscription->set_shipping_address( $shipping_address_changes );
|
||||
|
||||
$subscription->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1334,11 +1358,11 @@ class WC_Subscriptions_Switcher {
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
if ( empty( $_GET['_wcsnonce'] ) || ! wp_verify_nonce( $_GET['_wcsnonce'], 'wcs_switch_request' ) ) {
|
||||
if ( empty( $_GET['_wcsnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wcsnonce'] ) ), 'wcs_switch_request' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$subscription = wcs_get_subscription( $_GET['switch-subscription'] );
|
||||
$subscription = wcs_get_subscription( absint( $_GET['switch-subscription'] ) );
|
||||
$item_id = absint( $_GET['item'] );
|
||||
$item = wcs_get_order_item( $item_id, $subscription );
|
||||
|
||||
@@ -1415,7 +1439,7 @@ class WC_Subscriptions_Switcher {
|
||||
return $cart_item_data;
|
||||
}
|
||||
|
||||
$subscription = wcs_get_subscription( $_GET['switch-subscription'] );
|
||||
$subscription = wcs_get_subscription( absint( $_GET['switch-subscription'] ) );
|
||||
|
||||
// Requesting a switch for someone elses subscription
|
||||
if ( ! current_user_can( 'switch_shop_subscription', $subscription->get_id() ) ) {
|
||||
@@ -1676,9 +1700,28 @@ class WC_Subscriptions_Switcher {
|
||||
/**
|
||||
* Do not carry over switch related meta data to renewal orders.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @see wc_subscriptions_renewal_order_data
|
||||
*
|
||||
* @param array $order_meta An order's meta data.
|
||||
*
|
||||
* @return array Filtered order meta data to be copied.
|
||||
*/
|
||||
public static function remove_renewal_order_meta( $order_meta ) {
|
||||
unset( $order_meta['_subscription_switch'] );
|
||||
return $order_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not carry over switch related meta data to renewal orders.
|
||||
*
|
||||
* @deprecated 4.7.0
|
||||
*
|
||||
* @since 1.5.4
|
||||
*/
|
||||
public static function remove_renewal_order_meta_query( $order_meta_query ) {
|
||||
_deprecated_function( __METHOD__, '4.7.0', 'WC_Subscriptions_Switcher::remove_renewal_order_meta' );
|
||||
|
||||
$order_meta_query .= " AND `meta_key` NOT IN ('_subscription_switch')";
|
||||
|
||||
@@ -1693,7 +1736,7 @@ class WC_Subscriptions_Switcher {
|
||||
public static function addons_add_to_cart_url( $add_to_cart_url ) {
|
||||
|
||||
if ( isset( $_GET['switch-subscription'] ) && false === strpos( $add_to_cart_url, 'switch-subscription' ) ) {
|
||||
$add_to_cart_url = self::add_switch_query_args( $_GET['switch-subscription'], $_GET['item'], $add_to_cart_url );
|
||||
$add_to_cart_url = self::add_switch_query_args( absint( $_GET['switch-subscription'] ), absint( $_GET['item'] ), $add_to_cart_url );
|
||||
}
|
||||
|
||||
return $add_to_cart_url;
|
||||
@@ -2309,29 +2352,34 @@ class WC_Subscriptions_Switcher {
|
||||
*
|
||||
* @param WC_Abstract_Order[] $orders_to_display The list of related orders to display.
|
||||
* @param WC_Subscription[] $subscriptions The list of related subscriptions.
|
||||
* @param WP_Post $post The order or subscription post being viewed.
|
||||
* @param WC_Order $order The order or subscription post being viewed.
|
||||
*
|
||||
* @return $orders_to_display The orders/subscriptions to display in the meta box.
|
||||
*/
|
||||
public static function display_switches_in_related_order_metabox( $orders_to_display, $subscriptions, $post ) {
|
||||
public static function display_switches_in_related_order_metabox( $orders_to_display, $subscriptions, $order ) {
|
||||
if ( $order instanceof WP_Post ) {
|
||||
wcs_deprecated_argument( __METHOD__, '4.7.0', 'Passing a WP Post object is deprecated. This function now expects an Order or Subscription object.' );
|
||||
$order = wc_get_order( $order->ID );
|
||||
}
|
||||
|
||||
$switched_subscriptions = array();
|
||||
|
||||
// On the subscription page, just show related orders.
|
||||
if ( wcs_is_subscription( $post->ID ) ) {
|
||||
if ( wcs_is_subscription( $order ) ) {
|
||||
|
||||
foreach ( wcs_get_switch_orders_for_subscription( $post->ID ) as $order ) {
|
||||
$order->update_meta_data( '_relationship', __( 'Switch Order', 'woocommerce-subscriptions' ) );
|
||||
$orders_to_display[] = $order;
|
||||
foreach ( wcs_get_switch_orders_for_subscription( $order->get_id() ) as $switch_order ) {
|
||||
$switch_order->update_meta_data( '_relationship', __( 'Switch Order', 'woocommerce-subscriptions' ) );
|
||||
$orders_to_display[] = $switch_order;
|
||||
}
|
||||
|
||||
// Display the subscriptions which had item/s switched to this subscription by its parent order.
|
||||
if ( ! empty( $post->post_parent ) ) {
|
||||
$switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->post_parent );
|
||||
if ( ! empty( $order->post_parent ) ) {
|
||||
$switched_subscriptions = wcs_get_subscriptions_for_switch_order( $order->get_parent_id() );
|
||||
}
|
||||
|
||||
// On the Edit Order screen, show any subscriptions with items switched by this order.
|
||||
} else {
|
||||
$switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->ID );
|
||||
$switched_subscriptions = wcs_get_subscriptions_for_switch_order( $order );
|
||||
}
|
||||
|
||||
foreach ( $switched_subscriptions as $subscription ) {
|
||||
|
@@ -65,7 +65,7 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
|
||||
}
|
||||
}
|
||||
|
||||
return $pay_url;
|
||||
return $pay_url; // nosemgrep: audit.php.wp.security.xss.query-arg -- False positive. $pay_url is escaped in the template and escaping URLs should be done at the point of output or usage.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
|
||||
if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) && isset( $wp->query_vars['order-pay'] ) && isset( $_GET['subscription_switch'] ) ) {
|
||||
|
||||
// Pay for existing order
|
||||
$order_key = $_GET['key'];
|
||||
$order_key = sanitize_text_field( wp_unslash( $_GET['key'] ) );
|
||||
$order_id = ( isset( $wp->query_vars['order-pay'] ) ) ? $wp->query_vars['order-pay'] : absint( $_GET['order_id'] );
|
||||
$order = wc_get_order( $wp->query_vars['order-pay'] );
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
20
vendor/autoload.php
vendored
20
vendor/autoload.php
vendored
@@ -2,6 +2,24 @@
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
if (PHP_VERSION_ID < 50600) {
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, $err);
|
||||
} elseif (!headers_sent()) {
|
||||
echo $err;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
$err,
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit253f1c7df0eb4d6d594d9e32faa57a6a::getLoader();
|
||||
return ComposerAutoloaderInit33a9fa1eb707ddafd4d5a1bd7f21492d::getLoader();
|
||||
|
21
vendor/composer/ClassLoader.php
vendored
21
vendor/composer/ClassLoader.php
vendored
@@ -42,6 +42,9 @@ namespace Composer\Autoload;
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/** @var \Closure(string):void */
|
||||
private static $includeFile;
|
||||
|
||||
/** @var ?string */
|
||||
private $vendorDir;
|
||||
|
||||
@@ -106,6 +109,7 @@ class ClassLoader
|
||||
public function __construct($vendorDir = null)
|
||||
{
|
||||
$this->vendorDir = $vendorDir;
|
||||
self::initializeIncludeClosure();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +429,8 @@ class ClassLoader
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
$includeFile = self::$includeFile;
|
||||
$includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -555,6 +560,14 @@ class ClassLoader
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function initializeIncludeClosure()
|
||||
{
|
||||
if (self::$includeFile !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -564,9 +577,9 @@ class ClassLoader
|
||||
*
|
||||
* @param string $file
|
||||
* @return void
|
||||
* @private
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
self::$includeFile = \Closure::bind(static function($file) {
|
||||
include $file;
|
||||
}, null, null);
|
||||
}
|
||||
}
|
||||
|
31
vendor/composer/InstalledVersions.php
vendored
31
vendor/composer/InstalledVersions.php
vendored
@@ -21,12 +21,14 @@ use Composer\Semver\VersionParser;
|
||||
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
||||
*
|
||||
* To require its presence, you can require `composer-runtime-api ^2.0`
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class InstalledVersions
|
||||
{
|
||||
/**
|
||||
* @var mixed[]|null
|
||||
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
|
||||
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
|
||||
*/
|
||||
private static $installed;
|
||||
|
||||
@@ -37,7 +39,7 @@ class InstalledVersions
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
private static $installedByVendor = array();
|
||||
|
||||
@@ -96,7 +98,7 @@ class InstalledVersions
|
||||
{
|
||||
foreach (self::getInstalled() as $installed) {
|
||||
if (isset($installed['versions'][$packageName])) {
|
||||
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
|
||||
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +119,7 @@ class InstalledVersions
|
||||
*/
|
||||
public static function satisfies(VersionParser $parser, $packageName, $constraint)
|
||||
{
|
||||
$constraint = $parser->parseConstraints($constraint);
|
||||
$constraint = $parser->parseConstraints((string) $constraint);
|
||||
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
|
||||
|
||||
return $provided->matches($constraint);
|
||||
@@ -241,7 +243,7 @@ class InstalledVersions
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
|
||||
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
|
||||
*/
|
||||
public static function getRootPackage()
|
||||
{
|
||||
@@ -255,7 +257,7 @@ class InstalledVersions
|
||||
*
|
||||
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
|
||||
* @return array[]
|
||||
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
|
||||
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
|
||||
*/
|
||||
public static function getRawData()
|
||||
{
|
||||
@@ -278,7 +280,7 @@ class InstalledVersions
|
||||
* Returns the raw data of all installed.php which are currently loaded for custom implementations
|
||||
*
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
public static function getAllRawData()
|
||||
{
|
||||
@@ -301,7 +303,7 @@ class InstalledVersions
|
||||
* @param array[] $data A vendor/composer/installed.php data set
|
||||
* @return void
|
||||
*
|
||||
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
|
||||
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
|
||||
*/
|
||||
public static function reload($data)
|
||||
{
|
||||
@@ -311,7 +313,7 @@ class InstalledVersions
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
|
||||
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
|
||||
*/
|
||||
private static function getInstalled()
|
||||
{
|
||||
@@ -326,7 +328,9 @@ class InstalledVersions
|
||||
if (isset(self::$installedByVendor[$vendorDir])) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir];
|
||||
} elseif (is_file($vendorDir.'/composer/installed.php')) {
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require $vendorDir.'/composer/installed.php';
|
||||
$installed[] = self::$installedByVendor[$vendorDir] = $required;
|
||||
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
|
||||
self::$installed = $installed[count($installed) - 1];
|
||||
}
|
||||
@@ -338,12 +342,17 @@ class InstalledVersions
|
||||
// only require the installed.php file if this file is loaded from its dumped location,
|
||||
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
|
||||
if (substr(__DIR__, -8, 1) !== 'C') {
|
||||
self::$installed = require __DIR__ . '/installed.php';
|
||||
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
|
||||
$required = require __DIR__ . '/installed.php';
|
||||
self::$installed = $required;
|
||||
} else {
|
||||
self::$installed = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$installed !== array()) {
|
||||
$installed[] = self::$installed;
|
||||
}
|
||||
|
||||
return $installed;
|
||||
}
|
||||
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
|
2
vendor/composer/autoload_namespaces.php
vendored
2
vendor/composer/autoload_namespaces.php
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
|
2
vendor/composer/autoload_psr4.php
vendored
2
vendor/composer/autoload_psr4.php
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$vendorDir = dirname(__DIR__);
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
|
29
vendor/composer/autoload_real.php
vendored
29
vendor/composer/autoload_real.php
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit253f1c7df0eb4d6d594d9e32faa57a6a
|
||||
class ComposerAutoloaderInit33a9fa1eb707ddafd4d5a1bd7f21492d
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@@ -24,31 +24,12 @@ class ComposerAutoloaderInit253f1c7df0eb4d6d594d9e32faa57a6a
|
||||
|
||||
require __DIR__ . '/platform_check.php';
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit253f1c7df0eb4d6d594d9e32faa57a6a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit253f1c7df0eb4d6d594d9e32faa57a6a', 'loadClassLoader'));
|
||||
spl_autoload_register(array('ComposerAutoloaderInit33a9fa1eb707ddafd4d5a1bd7f21492d', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit33a9fa1eb707ddafd4d5a1bd7f21492d', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit253f1c7df0eb4d6d594d9e32faa57a6a::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
}
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit33a9fa1eb707ddafd4d5a1bd7f21492d::getInitializer($loader));
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit253f1c7df0eb4d6d594d9e32faa57a6a
|
||||
class ComposerStaticInit33a9fa1eb707ddafd4d5a1bd7f21492d
|
||||
{
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'C' =>
|
||||
@@ -129,9 +129,9 @@ class ComposerStaticInit253f1c7df0eb4d6d594d9e32faa57a6a
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit253f1c7df0eb4d6d594d9e32faa57a6a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit253f1c7df0eb4d6d594d9e32faa57a6a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit253f1c7df0eb4d6d594d9e32faa57a6a::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit33a9fa1eb707ddafd4d5a1bd7f21492d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit33a9fa1eb707ddafd4d5a1bd7f21492d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit33a9fa1eb707ddafd4d5a1bd7f21492d::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
@@ -156,17 +156,17 @@
|
||||
},
|
||||
{
|
||||
"name": "woocommerce/subscriptions-core",
|
||||
"version": "2.3.0",
|
||||
"version_normalized": "2.3.0.0",
|
||||
"version": "5.8.0",
|
||||
"version_normalized": "5.8.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Automattic/woocommerce-subscriptions-core.git",
|
||||
"reference": "8017438f8e0cfc16494344f783fb134f77284d58"
|
||||
"reference": "24db3cf51eb191edb21e79421387072194b59046"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Automattic/woocommerce-subscriptions-core/zipball/8017438f8e0cfc16494344f783fb134f77284d58",
|
||||
"reference": "8017438f8e0cfc16494344f783fb134f77284d58",
|
||||
"url": "https://api.github.com/repos/Automattic/woocommerce-subscriptions-core/zipball/24db3cf51eb191edb21e79421387072194b59046",
|
||||
"reference": "24db3cf51eb191edb21e79421387072194b59046",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -179,7 +179,7 @@
|
||||
"woocommerce/woocommerce-sniffs": "0.1.0",
|
||||
"yoast/phpunit-polyfills": "1.0.3"
|
||||
},
|
||||
"time": "2022-10-07T03:45:34+00:00",
|
||||
"time": "2023-07-05T04:17:20+00:00",
|
||||
"type": "wordpress-plugin",
|
||||
"extra": {
|
||||
"phpcodesniffer-search-depth": 2
|
||||
@@ -209,7 +209,7 @@
|
||||
"description": "Sell products and services with recurring payments in your WooCommerce Store.",
|
||||
"homepage": "https://github.com/Automattic/woocommerce-subscriptions-core",
|
||||
"support": {
|
||||
"source": "https://github.com/Automattic/woocommerce-subscriptions-core/tree/2.3.0",
|
||||
"source": "https://github.com/Automattic/woocommerce-subscriptions-core/tree/5.8.0",
|
||||
"issues": "https://github.com/Automattic/woocommerce-subscriptions-core/issues"
|
||||
},
|
||||
"install-path": "../woocommerce/subscriptions-core"
|
||||
|
14
vendor/composer/installed.php
vendored
14
vendor/composer/installed.php
vendored
@@ -1,22 +1,22 @@
|
||||
<?php return array(
|
||||
'root' => array(
|
||||
'name' => 'woocommerce/woocommerce-subscriptions',
|
||||
'pretty_version' => 'dev-trunk',
|
||||
'version' => 'dev-trunk',
|
||||
'reference' => '3654b75b4e4dc6fc0a87c6424910937660919214',
|
||||
'type' => 'wordpress-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '1b8773fe15dd9d70a59bfde2d5593191398b6096',
|
||||
'name' => 'woocommerce/woocommerce-subscriptions',
|
||||
'dev' => false,
|
||||
),
|
||||
'versions' => array(
|
||||
'composer/installers' => array(
|
||||
'pretty_version' => 'v1.12.0',
|
||||
'version' => '1.12.0.0',
|
||||
'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19',
|
||||
'type' => 'composer-plugin',
|
||||
'install_path' => __DIR__ . '/./installers',
|
||||
'aliases' => array(),
|
||||
'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'roundcube/plugin-installer' => array(
|
||||
@@ -32,21 +32,21 @@
|
||||
),
|
||||
),
|
||||
'woocommerce/subscriptions-core' => array(
|
||||
'pretty_version' => '2.3.0',
|
||||
'version' => '2.3.0.0',
|
||||
'pretty_version' => '5.8.0',
|
||||
'version' => '5.8.0.0',
|
||||
'reference' => '24db3cf51eb191edb21e79421387072194b59046',
|
||||
'type' => 'wordpress-plugin',
|
||||
'install_path' => __DIR__ . '/../woocommerce/subscriptions-core',
|
||||
'aliases' => array(),
|
||||
'reference' => '8017438f8e0cfc16494344f783fb134f77284d58',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'woocommerce/woocommerce-subscriptions' => array(
|
||||
'pretty_version' => 'dev-trunk',
|
||||
'version' => 'dev-trunk',
|
||||
'reference' => '3654b75b4e4dc6fc0a87c6424910937660919214',
|
||||
'type' => 'wordpress-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '1b8773fe15dd9d70a59bfde2d5593191398b6096',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
),
|
||||
|
@@ -17,33 +17,51 @@
|
||||
}
|
||||
|
||||
/* Subscriptions Admin Page */
|
||||
.woocommerce_page_wc-orders--shop_subscription .tablenav input,
|
||||
.woocommerce_page_wc-orders--shop_subscription .tablenav select,
|
||||
.post-type-shop_subscription .tablenav input,
|
||||
.post-type-shop_subscription .tablenav select {
|
||||
height: 32px;
|
||||
}
|
||||
.woocommerce_page_wc-orders--shop_subscription .tablenav .select2-container,
|
||||
.post-type-shop_subscription .tablenav .select2-container {
|
||||
width: 240px !important;
|
||||
font-size: 14px;
|
||||
vertical-align: middle;
|
||||
margin: 1px 6px 4px 1px;
|
||||
}
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.tablenav
|
||||
.select2-selection--single,
|
||||
.post-type-shop_subscription .tablenav .select2-selection--single {
|
||||
height: 32px;
|
||||
}
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.tablenav
|
||||
.select2-selection__rendered,
|
||||
.post-type-shop_subscription .tablenav .select2-selection__rendered {
|
||||
line-height: 29px;
|
||||
}
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.tablenav
|
||||
.select2-selection__arrow,
|
||||
.post-type-shop_subscription .tablenav .select2-selection__arrow {
|
||||
height: 30px;
|
||||
}
|
||||
.woocommerce_page_wc-orders--shop_subscription .wp-list-table,
|
||||
.post-type-shop_subscription .wp-list-table {
|
||||
margin-top: 1em;
|
||||
}
|
||||
.woocommerce_page_wc-orders--shop_subscription .widefat .column-status,
|
||||
.woocommerce_page_wc-orders--shop_subscription .widefat .column-order_title,
|
||||
.post-type-shop_subscription .widefat .column-status,
|
||||
.post-type-shop_subscription .widefat .column-order_title {
|
||||
width: 160px;
|
||||
text-align: left;
|
||||
}
|
||||
.wcs-payment-overdue {
|
||||
color: #d63539;
|
||||
}
|
||||
/* Product List table */
|
||||
table.wp-list-table span.product-type.variable-subscription {
|
||||
background-position: -48px 0;
|
||||
@@ -726,6 +744,14 @@ table.wc_gateways .renewals .tips {
|
||||
}
|
||||
|
||||
/* Hide irrelevant sections on Edit Subscription screen */
|
||||
body.woocommerce_page_wc-orders--shop_subscription
|
||||
.order_actions
|
||||
#actions
|
||||
optgroup[label='Resend order emails'],
|
||||
body.woocommerce_page_wc-orders--shop_subscription .add-items .description.tips,
|
||||
body.woocommerce_page_wc-orders--shop_subscription
|
||||
.add-items
|
||||
.button.refund-items,
|
||||
body.post-type-shop_subscription
|
||||
.order_actions
|
||||
#actions
|
||||
@@ -746,20 +772,33 @@ body.post-type-shop_subscription .add-items .button.refund-items {
|
||||
width: 19%;
|
||||
}
|
||||
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.wp-list-table
|
||||
.column-status,
|
||||
.post-type-shop_subscription .wp-list-table .column-status {
|
||||
display: none;
|
||||
text-align: left;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.wp-list-table
|
||||
.column-status
|
||||
mark,
|
||||
.post-type-shop_subscription .wp-list-table .column-status mark {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.wp-list-table
|
||||
.column-status::before,
|
||||
.post-type-shop_subscription .wp-list-table .column-status::before {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.woocommerce_page_wc-orders--shop_subscription
|
||||
.wp-list-table
|
||||
.column-orders,
|
||||
.post-type-shop_subscription .wp-list-table .column-orders {
|
||||
text-align: left !important;
|
||||
}
|
||||
|
@@ -1370,4 +1370,16 @@ jQuery( function ( $ ) {
|
||||
},
|
||||
};
|
||||
wcs_accounts_and_privacy_settings.init();
|
||||
|
||||
$( '#wpbody' ).on( 'click', '#doaction, #doaction2', function () {
|
||||
var action = $( this ).is( '#doaction' )
|
||||
? $( '#bulk-action-selector-top' ).val()
|
||||
: $( '#bulk-action-selector-bottom' ).val();
|
||||
|
||||
if ( 'wcs_remove_personal_data' === action ) {
|
||||
return window.confirm(
|
||||
WCSubscriptions.i18n_remove_personal_data_notice
|
||||
);
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
@@ -327,11 +327,11 @@ jQuery( function ( $ ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$( 'body.post-type-shop_subscription #post' ).on( 'submit', function () {
|
||||
$( 'body.post-type-shop_subscription #post, body.woocommerce_page_wc-orders--shop_subscription #order' ).on( 'submit', function () {
|
||||
if (
|
||||
'wcs_process_renewal' ==
|
||||
$(
|
||||
"body.post-type-shop_subscription select[name='wc_order_action']"
|
||||
'body.post-type-shop_subscription select[name="wc_order_action"], body.woocommerce_page_wc-orders--shop_subscription select[name="wc_order_action"]'
|
||||
).val()
|
||||
) {
|
||||
return confirm(
|
||||
@@ -340,7 +340,7 @@ jQuery( function ( $ ) {
|
||||
}
|
||||
} );
|
||||
|
||||
$( 'body.post-type-shop_subscription #post' ).on( 'submit', function () {
|
||||
$( 'body.post-type-shop_subscription #post, body.woocommerce_page_wc-orders--shop_subscription #order' ).on( 'submit', function () {
|
||||
if (
|
||||
typeof wcs_admin_meta_boxes.change_payment_method_warning !=
|
||||
'undefined' &&
|
||||
|
141
vendor/woocommerce/subscriptions-core/changelog.txt
vendored
141
vendor/woocommerce/subscriptions-core/changelog.txt
vendored
@@ -1,5 +1,146 @@
|
||||
*** WooCommerce Subscriptions Core Changelog ***
|
||||
|
||||
= 5.8.0 - 2023-07-05 =
|
||||
* Fix - When HPOS is enabled, permanently deleting a subscription related order wasn't updating the related orders cache properly.
|
||||
* Fix - Added logic to check if the recurring cart array is present before displaying the recurring totals section in the cart.
|
||||
|
||||
= 5.7.2 - 2023-06-05 =
|
||||
* Fix - Resolved an issue with customers being redirected to an incorrect Pay for Order URL after login.
|
||||
|
||||
= 5.7.1 - 2023-05-11 =
|
||||
* Dev - Resolve errors for third-party code using the URLs returned from WC_Subscriptions_Admin::add_subscription_url() and WCS_Cart_Renewal::get_checkout_payment_url() because they were erroneously escaped. #440
|
||||
* Dev - Enable third-party code to alter the delete payment token URL returned from flag_subscription_payment_token_deletions. #440
|
||||
|
||||
= 5.7.0 - 2023-05-04 =
|
||||
* Fix - Fatal error from third-party extensions using the `woocommerce_update_order` expecting the second parameter.
|
||||
* Dev - Pass the subscription object as the second parameter to `woocommerce_update_subscription` hook (and `woocommerce_update_order` for backwards compatibility).
|
||||
* Dev - Return a response from the WC_Subscription::set_status() function in line with the parent WC_Order::set_status() function.
|
||||
* Dev - Add the 'wcs_recurring_shipping_package_rates_match_standard_rates' filter to enable third-parties to override whether the subscription packages match during checkout validation.
|
||||
|
||||
= 5.6.0 - 2023-04-19 =
|
||||
* Fix - Correctly determine subscription free shipping eligibility when the initial payment cart isn't eligible. Fixes erroneous "Invalid recurring shipping method" errors on checkout. #409
|
||||
* Dev - Fixed precision loss notice that occurs when running PHP 8.1. #428
|
||||
* Dev - Fix phpcs and semgrep warnings to improve code quality. #429
|
||||
* Dev - Use `wp_safe_redirect()` when processing a payment method change request. #429
|
||||
|
||||
= 5.5.0 - 2023-03-10 =
|
||||
* Fix - When HPOS is enabled, changing your address while paying for a renewal order will update the address on the subscription. #413
|
||||
* Fix - Prevent admin error notices being shown for the "subscription trial end" event that was caused by no callbacks being attached to this scheduled action. #414
|
||||
* Fix - Prevent fatal error when copying the `_shipping_address` meta data where the value is not an array. #417
|
||||
|
||||
= 5.4.0 - 2023-02-21 =
|
||||
* Fix - Remove the recurring shipping method cache that caused bugs for third-party plugins like Conditional Shipping and Payments. #407
|
||||
|
||||
= 5.3.1 - 2023-02-01 =
|
||||
* Fix - Fatal error when loading the Edit Subscription page with custom admin billing or shipping fields. #403
|
||||
|
||||
= 5.3.0 - 2023-01-26 =
|
||||
* Add - Highlight subscriptions with overdue payment in list view with red icon & tooltip.
|
||||
* Fix - Shipping address correctly set when resubscribing or switching subscriptions that contain different billing and shipping addresses.
|
||||
* Fix - When processing customer requests to update all their subscription payment methods, ensure the updated subscription is used fetch the new payment meta, not and old instance.
|
||||
* Dev - Remove deprecated `strptime` function in favour of `DateTime::createFromFormat`.
|
||||
* Fix - Catch exceptions when changing payment method associated with a subscription to avoid fatal errors.
|
||||
|
||||
= 5.2.0 - 2023-01-23 =
|
||||
* Add - New wcs_set_order_address() helper function to set an array of address fields on an order or subscription.
|
||||
* Fix - Edit, add, and list Subscription admin pages now work when HPOS is enabled.
|
||||
* Fix - Fixed issues where multiple subscription purchases wouldn't appear on the My Account > Subscriptions screen, on HPOS environments.
|
||||
* Fix - Refactor `WCS_Meta_Box_Subscription_Data::save` to support HPOS stores, fixing a PHP warning notice when updating an order via the Edit Order screen.
|
||||
* Fix - Set the `download_permissions_granted` value when purchasing a downloadable subscription product when HPOS is enabled.
|
||||
* Fix - When a customer changes their address on their account or subscription, make sure the new address is saved when HPOS is enabled.
|
||||
* Fix - Removed the potential for an infinite loop when getting a subscription's related orders while the subscription is being loaded.
|
||||
* Fix - Refactor `WC_Subscriptions_Renewal_Order::get_failed_order_replaced_by()` to support HPOS stores.
|
||||
* Fix - Refactor the `WC_Subscriptions_Tracker` class to support HPOS stores.
|
||||
* Fix - "Subscriptions by Payment Gateway" in WooCommerce → Status now shows the correct values when HPOS is enabled.
|
||||
* Fix - Check whether the order actually exists before accessing order properties in wcs_order_contains_subscription()
|
||||
* Fix - Replace the get_posts() used in get_subscriptions_from_token() to support HPOS stores.
|
||||
* Fix - On HPOS stores, when a subscription's parent order is trashed or deleted, make sure the related subscription is also trashed or deleted.
|
||||
* Fix - On HPOS stores, when a subscription is trashed or deleted, make sure it is cancelled first.
|
||||
* Fix - Merge any custom meta_query args passed to wcs_get_orders_with_meta_query() to avoid overriding WC core args that map onto meta_query.
|
||||
* Fix - Filtering the Subscriptions List Table by customer, product ID and payment method, now works on stores with HPOS enabled.
|
||||
* Fix - Prevent erroneously resyncing a subscription every time it is loaded from the database on HPOS environments.
|
||||
* Fix - Fix "Trying to get property 'ID' of non-object" errors on the edit subscription screen when HPOS is enabled.
|
||||
* Fix - When HPOS is enabled, clicking the related orders link on the Subscriptions Table now filters the table with the related orders (previously all orders were shown).
|
||||
* Fix - On HPOS environments, ensure subscription related order caches are updated when relationship order meta (eg `_subscription_renewal` or `_subscription_switch`) is updated.
|
||||
* Fix - Show subscription status filters/views above the subscriptions list table on stores with HPOS enabled.
|
||||
* Fix - Reorder the edit subscription meta boxes on HPOS environments so the line items meta box appears after the subscription data.
|
||||
* Fix - On HPOS environments, prepopulate the subscription start date when creating a new subscription via the admin edit screen.
|
||||
* Fix - On HPOS environments, handle the admin subscriptions list table bulk actions and row actions in a HPOS compatible way.
|
||||
* Fix - On HPOS environments, admin notices might show incorrect subscription or order link as part of the admin notice.
|
||||
* Fix - On HPOS environments, parent order link on subscription edit page, in subscription details box, is incorrect.
|
||||
* Fix - On HPOS environments, update cache when subscription is trashed, deleted, or restored / untrashed.
|
||||
* Fix - Replace code using wp_count_posts( 'shop_subscription' ) with data store function to count subscriptions grouped by statuses on stores with HPOS enabled.
|
||||
* Dev - Replace code using get_post_type( $subscription_id ) with WC Data Store get_order_type().
|
||||
* Dev - Add subscriptions-core library version to the WooCommerce system status report.
|
||||
* Dev - Introduced a WCS_Object_Data_Cache_Manager and WCS_Object_Data_Cache_Manager_Many_To_One class as HPOS equivalents of the WCS_Post_Meta_Cache_Manager classes.
|
||||
* Dev - Introduced a new `untrash_order()` in the `WCS_Orders_Table_Subscription_Data_Store` class to fix untrashing subscriptions on stores that have HPOS enabled.
|
||||
* Dev - Moved the trash, untrash & delete related `add_actions()` in the `WC_Subscriptions_Manager` class to be added on the `woocommerce_loaded` action.
|
||||
* Dev - Update `wp_delete_post()` code that was used to delete a subscription to use CRUD methods to support HPOS.
|
||||
* Dev - Fix phpcs violations in the `WC_Subscriptions_Tracker` class to improve code quality.
|
||||
* Dev - Fix phpcs violations in the `WCS_Admin_System_Status` class to improve code quality.
|
||||
|
||||
= 5.1.0 - 2022-11-24 =
|
||||
* Fix - Set payment tokens when copying data between orders and subscriptions in a CRUD compatible way. Fixes PHP notices during renewal order process.
|
||||
* Fix - Infinite loop that can occur with `WCS_Orders_Table_Subscription_Data_Store::read_multiple()` on HPOS-enabled stores.
|
||||
* Fix - On HPOS stores, when querying for subscriptions with wcs_get_orders_with_meta_query() with status 'any', ensure that wc_get_orders() queries for subscription statuses.
|
||||
* Fix - On HPOS stores, when saving a subscription make sure subscription properties (ie `_requires_manual_renewal`) are saved to the database.
|
||||
* Fix - On HPOS stores, when a subscription is loaded from the database, make sure all core subscription properties are read directly from meta.
|
||||
* Fix - When viewing My Account > Subscriptions, fix an issue where no subscriptions were listed when HPOS is enabled.
|
||||
* Fix - On HPOS stores, ensure payment tokens are copied from the subscription to the renewal order.
|
||||
* Fix - Refactor `WCS_Meta_Box_Schedule::save` to support HPOS stores, fixing a PHP warning notice when updating an order via the Edit Order screen.
|
||||
* Fix - Return a fresh instance of the renewal order after creating it. Fixes caching issues on HPOS sites where the returned order has no line items.
|
||||
* Fix - Processing a manual renewal order with HPOS and data syncing enabled correctly saves the related order cache metadata on the subscription and prevents the post and order meta data getting out of sync.
|
||||
* Fix - Use supported CRUD apis to determine if subscriptions are present on store (`wcs_do_subscriptions_exist`)
|
||||
* Fix - With HPOS and data syncing enabled, updating the status of a pending manual renewal order to a paid status correctly activates the related subscription.
|
||||
* Update - Refactor the `wcs_is_subscription` helper function to support HPOS.
|
||||
* Update - Refactor our Related Orders data store classes (WCS_Related_Order_Store_Cached_CPT and WCS_Related_Order_Store_CPT) to use CRUD methods to support subscriptions and orders stored in HPOS.
|
||||
* Update - Display related orders table when viewing the new "Edit Order" page (HPOS enabled stores).
|
||||
* Fix - On HPOS stores, make sure the links in the related-orders table redirect to the new Edit Order URL.
|
||||
* Dev - Removed the deprecated "wcs_subscriptions_for_{$relation_type}_order" dynamic hook used to filter the list of related subscriptions for the given relation type. The following hooks have been removed with no alternative:
|
||||
wcs_subscriptions_for_renewal_order
|
||||
wcs_subscriptions_for_switch_order
|
||||
wcs_subscriptions_for_resubscribe_order
|
||||
* Dev - Introduce a WC_Subscription::set_status() function to handle subscriptions set with a draft or auto-draft status. Replaces the need for the overriding WC_Subscription::get_status() which has been deleted.
|
||||
* Dev - Manual renewal orders created with HPOS and data syncing enabled are properly linked to the subscription by its `_subscription_renewal` meta and backfilled to posts table.
|
||||
|
||||
= 5.0.0 - 2022-11-14 =
|
||||
* Dev - The library has been bumped to version to 5.0.0 to reduce confusion with the version of WooCommerce Subscriptions.
|
||||
* Dev - Usage of \WC_Subscriptions_Core_Plugin::get_plugin_version() is no longer recommended for version detection. \WC_Subscriptions_Core_Plugin::get_library_version() should be used instead.
|
||||
* Add - New wcs_get_orders_with_meta_query() helper function to query for orders and subscriptions.
|
||||
* Update - Replace instances of `get_posts()` across codebase with new wcs_get_orders_with_meta_query() function.
|
||||
* Dev - Code that was tagged with a version and moved from WooCommerce Subscriptions now explicitly mentions this and shows the correct subscriptions-core and WC Subscriptions versions.
|
||||
* Dev - Refactor the saving of subscription dates in the subscription datastore to separate fetching changes and saving. Enables backfilling subscription dates when HPOS syncing is enabled.
|
||||
|
||||
= 2.5.2 - 2022-11-15 =
|
||||
* Fix - When creating a subscription via the checkout, make sure a new instance of the subscription is attached to the `woocommerce_checkout_subscription_created` action hook.
|
||||
|
||||
= 2.5.1 - 2022-11-04 =
|
||||
* Dev - Replace the use of the deprecated wcs_renewal_order_meta hook with wc_subscription_renewal_order_data in the WCS_Related_Order_Store_Cached_CPT class.
|
||||
* Dev - Fix typo in deprecation notice for the 'wcs_{type}_meta_query' filter. Incorrect replacement hook.
|
||||
|
||||
= 2.5.0 - 2022-11-04 =
|
||||
* Add - New WCS_Orders_Table_Subscription_Data_Store class to support subscriptions stored in High-Performance Order Storage (HPOS).
|
||||
* Add - New WCS_Orders_Table_Data_Store_Controller class to load the proper subscriptions data store when the store has HPOS enabled.
|
||||
* Add - New data copier class to copy data to subscriptions and related orders in place of direct database queries in prepraration for HPOS support.
|
||||
* Fix - When saving sync meta data on a new subscription, use 'woocommerce_new_subscription' instead of 'save_post'. This is to prevent errors when purchasing a subscription on stores that have HPOS enabled.
|
||||
* Update - Improve maybe_add_subscription_meta() and subscription_contains_synced_product() inside our WC_Subscriptions_Synchroniser class to use CRUD methods.
|
||||
* Dev - wcs_get_objects_property and wcs_set_objects_property have been marked as deprecated. Getters/Setters should be used on the objects instead.
|
||||
* Dev - Deprecated the "wcs_{type}_meta_query" dynamic hook used to alter the database query used to fetch the meta data to copy between subscriptions and renewal orders. There is no direct replacement. Third-parties should use the "wc_subscriptions_{type}_data" or "wc_subscriptions_object_data" hooks instead.
|
||||
* Dev - Deprecated the "wcs_{type}_meta" dynamic hook used to filter data copied to subscriptions and renewal orders. Third-parties should use wc_subscriptions_{type}_data instead.
|
||||
wcs_subscription_meta -> wc_subscriptions_subscription_data
|
||||
wcs_parent_meta -> wc_subscriptions_parent_data
|
||||
wcs_resubscribe_order_meta -> wc_subscriptions_resubscribe_order_data
|
||||
wcs_renewal_order_meta -> wc_subscriptions_renewal_order_data
|
||||
|
||||
= 2.4.1 - 2022-11-02 =
|
||||
* Fix - Undefined method WC_Order::set_shipping_address() on stores running pre-7.1 of WooCommerce which prevented subscriptions from being purchased.
|
||||
|
||||
= 2.4.0 - 2022-10-28 =
|
||||
* Update - The subscription creation function `wcs_create_subscription` has been updated to use WooCommerce CRUD methods in preparation for supporting High Performance Order Storage (HPOS).
|
||||
* Update - Improve wcs_copy_order_address() to use modern APIs for setting address fields.
|
||||
* Dev - woocommerce_new_subscription_data hook will only work with CPT datastore and so has been deprecated.
|
||||
* Dev - i18n usage of strftime has been deprecated for subscription titles. Date is now formatted using woocommerce standard date formatting.
|
||||
|
||||
= 2.3.0 - 2022-10-07 =
|
||||
* Fix - Move One Time Shipping metabox fields to use the woocommerce_product_options_shipping_product_data hook introduced in WC 6.0.
|
||||
* Dev - Define build tool version requirements for consistent development and build environments.
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author WooCommerce
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin/Upgrades
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
@@ -32,7 +32,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Attaches callbacks to hooks.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @see WCS_Background_Updater::init() for additional hooks and callbacks.
|
||||
*/
|
||||
public function init() {
|
||||
@@ -46,7 +46,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
*
|
||||
* Sets the page to 1.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function schedule_repair() {
|
||||
$this->set_page( 1 );
|
||||
@@ -56,7 +56,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Gets a batch of items which need to be repaired.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @return array An array of items which need to be repaired.
|
||||
*/
|
||||
protected function get_items_to_update() {
|
||||
@@ -82,7 +82,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Runs the update and save any items which didn't get processed.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function run_update() {
|
||||
parent::run_update();
|
||||
@@ -94,7 +94,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Schedules the repair event for this item.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
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.
|
||||
@@ -105,7 +105,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Gets the current page number.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @return int
|
||||
*/
|
||||
protected function get_page() {
|
||||
@@ -115,7 +115,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Sets the current page number.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @param int $page.
|
||||
*/
|
||||
protected function set_page( $page ) {
|
||||
@@ -125,7 +125,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Gets items from the last request which weren't processed.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_unprocessed_items() {
|
||||
@@ -135,7 +135,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Saves any items which haven't been handled.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
protected function save_unprocessed_items() {
|
||||
if ( ! empty( $this->items_to_repair ) ) {
|
||||
@@ -147,7 +147,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
/**
|
||||
* Deletes any items stored in the unprocessed cache stored in an option.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
protected function clear_unprocessed_items_cache() {
|
||||
delete_option( "{$this->repair_hook}_unprocessed" );
|
||||
@@ -158,7 +158,7 @@ abstract class WCS_Background_Repairer extends WCS_Background_Upgrader {
|
||||
*
|
||||
* This function is called when there are no longer any items to update.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
protected function unschedule_background_updates() {
|
||||
parent::unschedule_background_updates();
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin/Upgrades
|
||||
* @since 2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
@@ -33,7 +33,7 @@ abstract class WCS_Background_Upgrader extends WCS_Background_Updater {
|
||||
* Schedule the @see $this->scheduled_hook action to start repairing subscriptions in
|
||||
* @see $this->time_limit seconds (60 seconds by default).
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function schedule_repair() {
|
||||
$this->schedule_background_update();
|
||||
@@ -43,7 +43,7 @@ abstract class WCS_Background_Upgrader extends WCS_Background_Updater {
|
||||
* Add a message to the wcs-upgrade-subscriptions-paypal-suspended log
|
||||
*
|
||||
* @param string $message The message to be logged
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
protected function log( $message ) {
|
||||
$this->logger->add( $this->log_handle, $message );
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* Implements methods to deal with the soft caching layer
|
||||
*
|
||||
* @class WCS_Cache_Manager
|
||||
* @version 2.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @package WooCommerce Subscriptions/Classes
|
||||
* @category Class
|
||||
* @author Gabor Javorszky
|
||||
|
@@ -13,8 +13,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* it is being moved to use the 'post_author' column of the posts table from WC v2.4 or v2.5. It
|
||||
* will eventually also be moved quite likely to custom tables.
|
||||
*
|
||||
* @version 2.3.0
|
||||
* @since 2.3.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
*/
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* @package WooCommerce Subscriptions
|
||||
* @category Class
|
||||
* @author WooCommerce
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
@@ -34,7 +34,7 @@ abstract class WCS_Deprecated_Functions_Handler {
|
||||
/**
|
||||
* Determines if a function is deprecated and handled by this class.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $function The function to check.
|
||||
* @return bool
|
||||
@@ -46,7 +46,7 @@ abstract class WCS_Deprecated_Functions_Handler {
|
||||
/**
|
||||
* Determines if there's a replacement function to call.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $function The deprecated function to check if there's a replacement for.
|
||||
* @return bool
|
||||
@@ -58,7 +58,7 @@ abstract class WCS_Deprecated_Functions_Handler {
|
||||
/**
|
||||
* Calls the replacement function if one exists.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $function The deprecated function.
|
||||
* @param array $arguments The deprecated function arguments.
|
||||
@@ -87,7 +87,7 @@ abstract class WCS_Deprecated_Functions_Handler {
|
||||
/**
|
||||
* Triggers the deprecated notice.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @param string $function The deprecated function.
|
||||
*/
|
||||
public function trigger_notice( $function ) {
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* @subpackage WCS_Hook_Deprecator
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
|
||||
abstract class WCS_Dynamic_Hook_Deprecator extends WCS_Hook_Deprecator {
|
||||
@@ -22,7 +22,7 @@ abstract class WCS_Dynamic_Hook_Deprecator extends WCS_Hook_Deprecator {
|
||||
* $wp_filter global for our hooks either, because sometime, hooks are dynamically hooked based
|
||||
* on other hooks. Sigh.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'all', array( &$this, 'check_for_deprecated_hooks' ) );
|
||||
@@ -31,7 +31,7 @@ abstract class WCS_Dynamic_Hook_Deprecator extends WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Check if the current hook contains the prefix of any dynamic hook that has been deprecated.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function check_for_deprecated_hooks() {
|
||||
|
||||
@@ -53,7 +53,7 @@ abstract class WCS_Dynamic_Hook_Deprecator extends WCS_Hook_Deprecator {
|
||||
* Check if a given hook contains the prefix and if it does, attach the @see $this->maybe_handle_deprecated_hook() method
|
||||
* as a callback to it.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected function check_for_deprecated_hook( $current_hook, $new_hook_prefix, $old_hook_prefix ) {
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
* @subpackage WCS_Hook_Deprecator
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
|
||||
abstract class WCS_Hook_Deprecator {
|
||||
@@ -23,7 +23,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function __construct() {
|
||||
foreach ( $this->deprecated_hooks as $new_hook => $old_hook ) {
|
||||
@@ -34,7 +34,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Check if an old hook still has callbacks attached to it, and if so, display a notice and trigger the old hook.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function maybe_handle_deprecated_hook() {
|
||||
|
||||
@@ -61,7 +61,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Check if an old hook still has callbacks attached to it, and if so, display a notice and trigger the old hook.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected function handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value ) {
|
||||
|
||||
@@ -78,7 +78,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Display a deprecated notice for old hooks.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected static function display_notice( $old_hook, $new_hook ) {
|
||||
_deprecated_function( sprintf( 'The "%s" hook uses out of date data structures so', esc_html( $old_hook ) ), '2.0 of WooCommerce Subscriptions', esc_html( $new_hook ) );
|
||||
@@ -87,7 +87,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Trigger the old hook with the original callback parameters
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
abstract protected function trigger_hook( $old_hook, $new_callback_args );
|
||||
|
||||
@@ -97,7 +97,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
* Because a subscription can exist without an order in Subscriptions 2.0, the order might actually
|
||||
* fallback to being the subscription rather than the order used to purchase the subscription.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected static function get_order( $subscription ) {
|
||||
return ( false == $subscription->get_parent_id() ) ? $subscription : $subscription->get_parent();
|
||||
@@ -109,7 +109,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
* Because a subscription can exist without an order in Subscriptions 2.0, the order might actually
|
||||
* fallback to being the subscription rather than the order used to purchase the subscription.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected static function get_order_id( $subscription ) {
|
||||
return ( false == $subscription->get_parent_id() ) ? $subscription->get_id() : $subscription->get_parent_id();
|
||||
@@ -118,7 +118,7 @@ abstract class WCS_Hook_Deprecator {
|
||||
/**
|
||||
* Get the first product ID for a subscription to pass to callbacks.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected static function get_product_id( $subscription ) {
|
||||
$order_items = $subscription->get_items();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* @author Prospress
|
||||
* @category Class
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -40,7 +40,7 @@ abstract class WCS_Migrator {
|
||||
* @param mixed $destination_store $destination store.
|
||||
* @param WC_Logger $logger Logger component.
|
||||
*
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
public function __construct( $source_store, $destination_store, $logger ) {
|
||||
$this->source_store = $source_store;
|
||||
@@ -54,7 +54,7 @@ abstract class WCS_Migrator {
|
||||
* @param int $entry_id
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
abstract public function should_migrate_entry( $entry_id );
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract class WCS_Migrator {
|
||||
* @param int $entry_id
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
abstract public function get_source_store_entry( $entry_id );
|
||||
|
||||
@@ -74,7 +74,7 @@ abstract class WCS_Migrator {
|
||||
* @param int $entry_id
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
abstract public function save_destination_store_entry( $entry_id );
|
||||
|
||||
@@ -84,7 +84,7 @@ abstract class WCS_Migrator {
|
||||
* @param int $entry_id
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
abstract public function delete_source_store_entry( $entry_id );
|
||||
|
||||
@@ -104,7 +104,7 @@ abstract class WCS_Migrator {
|
||||
* @param int $entry_id
|
||||
*
|
||||
* @return mixed
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
public function migrate_entry( $entry_id ) {
|
||||
$source_store_item = $this->get_source_store_entry( $entry_id );
|
||||
@@ -125,7 +125,7 @@ abstract class WCS_Migrator {
|
||||
*
|
||||
* @param string $message The message to be logged
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.0
|
||||
*/
|
||||
protected function log( $message ) {
|
||||
$this->logger->add( $this->log_handle, $message );
|
||||
|
@@ -13,8 +13,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* Parent orders are not managed via this data store as the order data stores inherited by Subscriptions already
|
||||
* provide APIs for managing the parent relationship.
|
||||
*
|
||||
* @version 2.3.0
|
||||
* @since 2.3.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
*/
|
||||
@@ -59,7 +59,7 @@ abstract class WCS_Related_Order_Store {
|
||||
* Allow third-parties to register their own custom order relationship types which should be handled by this store.
|
||||
*
|
||||
* @param array An array of order relationship types.
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
foreach ( (array) apply_filters( 'wcs_additional_related_order_relation_types', array() ) as $relation_type ) {
|
||||
self::$relation_types[] = $relation_type;
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* or subscription expires.
|
||||
*
|
||||
* @class WCS_Scheduler
|
||||
* @version 2.0.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.0
|
||||
* @package WooCommerce Subscriptions/Abstracts
|
||||
* @category Abstract Class
|
||||
* @author Prospress
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author Prospress
|
||||
* @category Abstract Class
|
||||
* @package WooCommerce Subscriptions/Abstracts
|
||||
* @since 2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -8,36 +8,35 @@
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
class WC_Subscriptions_Admin {
|
||||
|
||||
/**
|
||||
* The WooCommerce settings tab name
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static $tab_name = 'subscriptions';
|
||||
|
||||
/**
|
||||
* The prefix for subscription settings
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static $option_prefix = 'woocommerce_subscriptions';
|
||||
|
||||
/**
|
||||
* Store an instance of the list table
|
||||
*
|
||||
* @since 1.4.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.6
|
||||
*/
|
||||
private static $subscriptions_list_table;
|
||||
|
||||
/**
|
||||
* Store an instance of the list table
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
private static $found_related_orders = false;
|
||||
|
||||
@@ -45,14 +44,14 @@ class WC_Subscriptions_Admin {
|
||||
* Is meta boxes saved once?
|
||||
*
|
||||
* @var boolean
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
private static $saved_product_meta = false;
|
||||
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -112,10 +111,12 @@ class WC_Subscriptions_Admin {
|
||||
|
||||
add_action( 'woocommerce_admin_field_informational', __CLASS__ . '::add_informational_admin_field' );
|
||||
|
||||
// Filter Orders list table.
|
||||
add_filter( 'posts_where', array( __CLASS__, 'filter_orders' ) );
|
||||
add_filter( 'woocommerce_shop_order_list_table_prepare_items_query_args', [ __CLASS__, 'filter_orders_table_by_related_orders' ] );
|
||||
|
||||
// Filter get_posts used by Subscription Reports.
|
||||
add_filter( 'posts_where', array( __CLASS__, 'filter_orders_and_subscriptions_from_list' ) );
|
||||
|
||||
add_filter( 'posts_where', array( __CLASS__, 'filter_paid_subscription_orders_for_user' ) );
|
||||
|
||||
add_action( 'admin_notices', __CLASS__ . '::display_renewal_filter_notice' );
|
||||
@@ -158,7 +159,7 @@ class WC_Subscriptions_Admin {
|
||||
* Clear all transients data we have when the WooCommerce::Tools::Clear Transients action is
|
||||
* triggered.
|
||||
*
|
||||
* @since 2.1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.1
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
@@ -180,9 +181,11 @@ class WC_Subscriptions_Admin {
|
||||
);
|
||||
|
||||
// Get all related order and subscription ranges transients
|
||||
$results = $wpdb->get_col( "SELECT DISTINCT `option_name`
|
||||
$results = $wpdb->get_col(
|
||||
"SELECT DISTINCT `option_name`
|
||||
FROM `$wpdb->options`
|
||||
WHERE `option_name` LIKE '%wcs-related-orders-to-%' OR `option_name` LIKE '%wcs-sub-ranges-%'" );
|
||||
WHERE `option_name` LIKE '%wcs-related-orders-to-%' OR `option_name` LIKE '%wcs-sub-ranges-%'"
|
||||
);
|
||||
|
||||
foreach ( $results as $column ) {
|
||||
$name = explode( 'transient_', $column, 2 );
|
||||
@@ -201,7 +204,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array Array of Product types & their labels, excluding the Subscription product type.
|
||||
* @return array Array of Product types & their labels, including the Subscription product type.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function add_subscription_products_to_select( $product_types ) {
|
||||
|
||||
@@ -216,7 +219,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array $product_types
|
||||
* @return array
|
||||
* @since 2.5.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.1
|
||||
*/
|
||||
public static function add_downloadable_and_virtual_filters( $product_types ) {
|
||||
global $typenow;
|
||||
@@ -244,7 +247,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array $query_vars
|
||||
* @return array $query_vars
|
||||
* @since 2.5.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.1
|
||||
*/
|
||||
public static function modify_downloadable_and_virtual_product_queries( $query_vars ) {
|
||||
global $pagenow, $typenow;
|
||||
@@ -282,7 +285,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Output the subscription specific pricing fields on the "Edit Product" admin page.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function subscription_pricing_fields() {
|
||||
global $post;
|
||||
@@ -316,18 +319,19 @@ class WC_Subscriptions_Admin {
|
||||
<label for="_subscription_period_interval" class="wcs_hidden_label"><?php esc_html_e( 'Subscription interval', 'woocommerce-subscriptions' ); ?></label>
|
||||
<select id="_subscription_period_interval" name="_subscription_period_interval" class="wc_input_subscription_period_interval">
|
||||
<?php foreach ( wcs_get_subscription_period_interval_strings() as $value => $label ) { ?>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $chosen_interval, true ) ?>><?php echo esc_html( $label ); ?></option>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $chosen_interval, true ); ?>><?php echo esc_html( $label ); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<label for="_subscription_period" class="wcs_hidden_label"><?php esc_html_e( 'Subscription period', 'woocommerce-subscriptions' ); ?></label>
|
||||
<select id="_subscription_period" name="_subscription_period" class="wc_input_subscription_period last" >
|
||||
<?php foreach ( wcs_get_subscription_period_strings() as $value => $label ) { ?>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $chosen_period, true ) ?>><?php echo esc_html( $label ); ?></option>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $chosen_period, true ); ?>><?php echo esc_html( $label ); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</span>
|
||||
<?php echo wcs_help_tip( $price_tooltip ); ?>
|
||||
</p><?php
|
||||
</p>
|
||||
<?php
|
||||
|
||||
// Subscription Length
|
||||
woocommerce_wp_select(
|
||||
@@ -342,7 +346,8 @@ class WC_Subscriptions_Admin {
|
||||
);
|
||||
|
||||
// Sign-up Fee
|
||||
woocommerce_wp_text_input( array(
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_subscription_sign_up_fee',
|
||||
// Keep wc_input_subscription_intial_price for backward compatibility.
|
||||
'class' => 'wc_input_subscription_intial_price wc_input_subscription_initial_price wc_input_price short',
|
||||
@@ -357,22 +362,25 @@ class WC_Subscriptions_Admin {
|
||||
'step' => 'any',
|
||||
'min' => '0',
|
||||
),
|
||||
) );
|
||||
)
|
||||
);
|
||||
|
||||
// Trial Length
|
||||
?><p class="form-field _subscription_trial_length_field">
|
||||
?>
|
||||
<p class="form-field _subscription_trial_length_field">
|
||||
<label for="_subscription_trial_length"><?php esc_html_e( 'Free trial', 'woocommerce-subscriptions' ); ?></label>
|
||||
<span class="wrap">
|
||||
<input type="text" id="_subscription_trial_length" name="_subscription_trial_length" class="wc_input_subscription_trial_length" value="<?php echo esc_attr( $chosen_trial_length ); ?>" />
|
||||
<label for="_subscription_trial_period" class="wcs_hidden_label"><?php esc_html_e( 'Subscription Trial Period', 'woocommerce-subscriptions' ); ?></label>
|
||||
<select id="_subscription_trial_period" name="_subscription_trial_period" class="wc_input_subscription_trial_period last" >
|
||||
<?php foreach ( wcs_get_available_time_periods() as $value => $label ) { ?>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $chosen_trial_period, true ) ?>><?php echo esc_html( $label ); ?></option>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $chosen_trial_period, true ); ?>><?php echo esc_html( $label ); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</span>
|
||||
<?php echo wcs_help_tip( $trial_tooltip ); ?>
|
||||
</p><?php
|
||||
</p>
|
||||
<?php
|
||||
|
||||
do_action( 'woocommerce_subscriptions_product_options_pricing' );
|
||||
|
||||
@@ -385,7 +393,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Output subscription shipping options on the "Edit Product" admin screen
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function subscription_shipping_fields() {
|
||||
global $post;
|
||||
@@ -400,12 +408,14 @@ class WC_Subscriptions_Admin {
|
||||
echo '<div class="options_group subscription_one_time_shipping show_if_subscription show_if_variable-subscription hidden">';
|
||||
|
||||
// Only one Subscription per customer
|
||||
woocommerce_wp_checkbox( array(
|
||||
woocommerce_wp_checkbox(
|
||||
array(
|
||||
'id' => '_subscription_one_time_shipping',
|
||||
'label' => __( 'One time shipping', 'woocommerce-subscriptions' ),
|
||||
'description' => __( 'Shipping for subscription products is normally charged on the initial order and all renewal orders. Enable this to only charge shipping once on the initial order. Note: for this setting to be enabled the subscription must not have a free trial or a synced renewal date.', 'woocommerce-subscriptions' ),
|
||||
'desc_tip' => true,
|
||||
) );
|
||||
)
|
||||
);
|
||||
|
||||
do_action( 'woocommerce_subscriptions_product_options_shipping' );
|
||||
|
||||
@@ -417,8 +427,8 @@ class WC_Subscriptions_Admin {
|
||||
|
||||
/**
|
||||
* Output advanced subscription options on the "Edit Product" admin screen
|
||||
* @deprecated 2.1
|
||||
* @since 1.3.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
*/
|
||||
public static function subscription_advanced_fields() {
|
||||
_deprecated_function( __METHOD__, '2.1', 'WCS_Limiter::admin_edit_product_fields()' );
|
||||
@@ -427,14 +437,14 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Output the subscription specific pricing fields on the "Edit Product" admin page.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function variable_subscription_pricing_fields( $loop, $variation_data, $variation ) {
|
||||
global $thepostid;
|
||||
|
||||
// When called via Ajax
|
||||
if ( ! function_exists( 'woocommerce_wp_text_input' ) ) {
|
||||
require_once( WC()->plugin_path() . '/admin/post-types/writepanels/writepanels-init.php' );
|
||||
require_once WC()->plugin_path() . '/admin/post-types/writepanels/writepanels-init.php';
|
||||
}
|
||||
|
||||
if ( ! isset( $thepostid ) ) {
|
||||
@@ -448,7 +458,7 @@ class WC_Subscriptions_Admin {
|
||||
$billing_period = 'month';
|
||||
}
|
||||
|
||||
include( WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/admin/html-variation-price.php' ) );
|
||||
include WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/admin/html-variation-price.php' );
|
||||
|
||||
wp_nonce_field( 'wcs_subscription_variations', '_wcsnonce_save_variations', false );
|
||||
|
||||
@@ -458,12 +468,13 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Output extra options in the Bulk Edit select box for editing Subscription terms.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function variable_subscription_bulk_edit_actions() {
|
||||
global $post;
|
||||
|
||||
if ( WC_Subscriptions_Product::is_subscription( $post->ID ) ) : ?>
|
||||
if ( WC_Subscriptions_Product::is_subscription( $post->ID ) ) :
|
||||
?>
|
||||
<optgroup label="<?php esc_attr_e( 'Subscription pricing', 'woocommerce-subscriptions' ); ?>">
|
||||
<option value="variable_subscription_sign_up_fee"><?php esc_html_e( 'Subscription sign-up fee', 'woocommerce-subscriptions' ); ?></option>
|
||||
<option value="variable_subscription_period_interval"><?php esc_html_e( 'Subscription billing interval', 'woocommerce-subscriptions' ); ?></option>
|
||||
@@ -472,7 +483,8 @@ class WC_Subscriptions_Admin {
|
||||
<option value="variable_subscription_trial_length"><?php esc_html_e( 'Free trial length', 'woocommerce-subscriptions' ); ?></option>
|
||||
<option value="variable_subscription_trial_period"><?php esc_html_e( 'Free trial period', 'woocommerce-subscriptions' ); ?></option>
|
||||
</optgroup>
|
||||
<?php endif;
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,7 +492,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array Array of Product types & their labels, excluding the Subscription product type.
|
||||
* @return array Array of Product types & their labels, including the Subscription product type.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function save_subscription_meta( $post_id ) {
|
||||
|
||||
@@ -562,7 +574,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array Array of Product types & their labels, excluding the Subscription product type.
|
||||
* @return array Array of Product types & their labels, including the Subscription product type.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function save_variable_subscription_meta( $post_id ) {
|
||||
|
||||
@@ -585,7 +597,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param object $product An instance of a WC_Product_* object.
|
||||
* @return null
|
||||
* @since 1.3.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.9
|
||||
*/
|
||||
public static function bulk_edit_save_subscription_meta( $product ) {
|
||||
|
||||
@@ -695,7 +707,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param int $post_id ID of the parent WC_Product_Variable_Subscription
|
||||
* @return null
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function process_product_meta_variable_subscription( $post_id ) {
|
||||
|
||||
@@ -721,7 +733,7 @@ class WC_Subscriptions_Admin {
|
||||
* @param int $variation_id
|
||||
* @param int $i
|
||||
* return void
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function save_product_variation( $variation_id, $index ) {
|
||||
|
||||
@@ -821,18 +833,31 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array Array of Product types & their labels, excluding the Subscription product type.
|
||||
* @return array Array of Product types & their labels, including the Subscription product type.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function enqueue_styles_scripts() {
|
||||
global $post;
|
||||
|
||||
// Get admin screen id
|
||||
// Get admin screen ID.
|
||||
$screen = get_current_screen();
|
||||
|
||||
$is_woocommerce_screen = in_array( $screen->id, array( 'product', 'edit-shop_order', 'shop_order', 'edit-shop_subscription', 'shop_subscription', 'users', 'woocommerce_page_wc-settings' ) );
|
||||
$is_woocommerce_screen = in_array(
|
||||
$screen->id,
|
||||
[
|
||||
'product',
|
||||
'edit-shop_order',
|
||||
'shop_order',
|
||||
'edit-shop_subscription',
|
||||
'shop_subscription',
|
||||
'users',
|
||||
'woocommerce_page_wc-settings',
|
||||
'woocommerce_page_wc-orders',
|
||||
wcs_get_page_screen_id( 'shop_subscription' ),
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if ( $is_woocommerce_screen ) {
|
||||
|
||||
$dependencies = array( 'jquery' );
|
||||
|
||||
$woocommerce_admin_script_handle = 'wc-admin-meta-boxes';
|
||||
@@ -870,11 +895,6 @@ class WC_Subscriptions_Admin {
|
||||
} elseif ( 'shop_order' == $screen->id ) {
|
||||
$dependencies[] = $woocommerce_admin_script_handle;
|
||||
$dependencies[] = 'wc-admin-order-meta-boxes';
|
||||
|
||||
if ( wcs_is_woocommerce_pre( '2.6' ) ) {
|
||||
$dependencies[] = 'wc-admin-order-meta-boxes-modal';
|
||||
}
|
||||
|
||||
$script_params = array(
|
||||
'trashWarning' => $trashing_subscription_order_warning,
|
||||
'changeMetaWarning' => __( "WARNING: Bad things are about to happen!\n\nThe payment gateway used to purchase this subscription does not support modifying a subscription's details.\n\nChanges to the billing period, recurring discount, recurring tax or recurring total may not be reflected in the amount charged by the payment gateway.", 'woocommerce-subscriptions' ),
|
||||
@@ -891,6 +911,8 @@ class WC_Subscriptions_Admin {
|
||||
$script_params = array(
|
||||
'enablePayPalWarning' => __( 'PayPal Standard has a number of limitations and does not support all subscription features.', 'woocommerce-subscriptions' ) . "\n\n" . __( 'Because of this, it is not recommended as a payment method for Subscriptions unless it is the only available option for your country.', 'woocommerce-subscriptions' ),
|
||||
);
|
||||
} elseif ( in_array( $screen->id, [ wcs_get_page_screen_id( 'shop_subscription' ), 'edit-shop_subscription' ], true ) ) {
|
||||
$script_params['i18n_remove_personal_data_notice'] = __( 'This action cannot be reversed. Are you sure you wish to erase personal data from the selected subscriptions?', 'woocommerce-subscriptions' );
|
||||
}
|
||||
|
||||
$script_params['ajaxLoaderImage'] = WC()->plugin_url() . '/assets/images/ajax-loader.gif';
|
||||
@@ -912,7 +934,7 @@ class WC_Subscriptions_Admin {
|
||||
'pricePointerContent' => sprintf( _x( '%1$sSet a Price%2$s%3$sSubscription prices are a little different to other product prices. For a subscription, you can set a billing period, length, sign-up fee and free trial.%4$s', 'used in admin pointer script params in javascript as price pointer content', 'woocommerce-subscriptions' ), '<h3>', '</h3>', '<p>', '</p>' ),
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'woocommerce_subscriptions_admin_pointers', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/admin-pointers.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_plugin_version() );
|
||||
wp_enqueue_script( 'woocommerce_subscriptions_admin_pointers', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/admin-pointers.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_library_version(), true );
|
||||
|
||||
wp_localize_script( 'woocommerce_subscriptions_admin_pointers', 'WCSPointers', apply_filters( 'woocommerce_subscriptions_admin_pointer_script_parameters', $pointer_script_params ) );
|
||||
|
||||
@@ -921,12 +943,8 @@ class WC_Subscriptions_Admin {
|
||||
}
|
||||
|
||||
if ( $is_woocommerce_screen || 'edit-product' == $screen->id || ( isset( $_GET['page'], $_GET['tab'] ) && 'wc-reports' === $_GET['page'] && 'subscriptions' === $_GET['tab'] ) ) {
|
||||
wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_Subscriptions_Core_Plugin::instance()->get_plugin_version() );
|
||||
wp_enqueue_style( 'woocommerce_subscriptions_admin', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/css/admin.css' ), array( 'woocommerce_admin_styles' ), WC_Subscriptions_Core_Plugin::instance()->get_plugin_version() );
|
||||
}
|
||||
|
||||
if ( in_array( $screen->id, array( 'shop_order', 'edit-shop_subscription', 'shop_subscription' ) ) && wcs_is_woocommerce_pre( '3.3' ) ) {
|
||||
wp_enqueue_style( 'wc_subscriptions_statuses_admin', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/css/admin-order-statuses.css' ), array( 'woocommerce_admin_styles' ), WC_Subscriptions_Core_Plugin::instance()->get_plugin_version() );
|
||||
wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_Subscriptions_Core_Plugin::instance()->get_library_version() );
|
||||
wp_enqueue_style( 'woocommerce_subscriptions_admin', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/css/admin.css' ), array( 'woocommerce_admin_styles' ), WC_Subscriptions_Core_Plugin::instance()->get_library_version() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -953,7 +971,7 @@ class WC_Subscriptions_Admin {
|
||||
* @param string $column_name The string key for the current column in an admin table
|
||||
* @param int $user_id The ID of the user to which this row relates
|
||||
* @return string $value A check mark if the column is the active_subscriber column and the user has an active subscription.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function user_column_values( $value, $column_name, $user_id ) {
|
||||
|
||||
@@ -974,12 +992,13 @@ class WC_Subscriptions_Admin {
|
||||
* display all the subscriptions that have been purchased.
|
||||
*
|
||||
* @uses WC_Subscriptions_List_Table
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function subscriptions_management_page() {
|
||||
|
||||
$subscriptions_table = self::get_subscriptions_list_table();
|
||||
$subscriptions_table->prepare_items(); ?>
|
||||
$subscriptions_table->prepare_items();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-woocommerce" class="icon32-woocommerce-users icon32"><br/></div>
|
||||
<h2><?php esc_html_e( 'Manage Subscriptions', 'woocommerce-subscriptions' ); ?></h2>
|
||||
@@ -1002,7 +1021,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Outputs the screen options on the Subscription Management admin page.
|
||||
*
|
||||
* @since 1.3.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.1
|
||||
*/
|
||||
public static function add_manage_subscriptions_screen_options() {
|
||||
add_screen_option(
|
||||
@@ -1018,7 +1037,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Sets the correct value for screen options on the Subscription Management admin page.
|
||||
*
|
||||
* @since 1.3.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.1
|
||||
*/
|
||||
public static function set_manage_subscriptions_screen_option( $status, $option, $value ) {
|
||||
|
||||
@@ -1033,7 +1052,7 @@ class WC_Subscriptions_Admin {
|
||||
* Returns the columns for the Manage Subscriptions table, specifically used for adding the
|
||||
* show/hide column screen options.
|
||||
*
|
||||
* @since 1.3.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.1
|
||||
*/
|
||||
public static function get_subscription_table_columns( $columns ) {
|
||||
|
||||
@@ -1046,7 +1065,7 @@ class WC_Subscriptions_Admin {
|
||||
* Returns the columns for the Manage Subscriptions table, specifically used for adding the
|
||||
* show/hide column screen options.
|
||||
*
|
||||
* @since 1.3.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.1
|
||||
*/
|
||||
public static function get_subscriptions_list_table() {
|
||||
|
||||
@@ -1062,7 +1081,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @uses woocommerce_update_options()
|
||||
* @uses self::get_settings()
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function update_subscription_settings() {
|
||||
|
||||
@@ -1131,7 +1150,7 @@ class WC_Subscriptions_Admin {
|
||||
|
||||
// Add to $settings to be natively saved.
|
||||
$settings[] = array(
|
||||
'id' => WC_Subscriptions_Admin::$option_prefix . '_allow_switching_' . $option['id'],
|
||||
'id' => self::$option_prefix . '_allow_switching_' . $option['id'],
|
||||
'type' => 'checkbox', // This will sanitize value to yes/no.
|
||||
);
|
||||
}
|
||||
@@ -1144,7 +1163,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @uses woocommerce_admin_fields()
|
||||
* @uses self::get_settings()
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function subscription_settings_page() {
|
||||
woocommerce_admin_fields( self::get_settings() );
|
||||
@@ -1156,7 +1175,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
|
||||
* @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function add_subscription_settings_tab( $settings_tabs ) {
|
||||
|
||||
@@ -1169,7 +1188,7 @@ class WC_Subscriptions_Admin {
|
||||
* Sets default values for all the WooCommerce Subscription options. Called on plugin activation.
|
||||
*
|
||||
* @see WC_Subscriptions::activate_woocommerce_subscriptions
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function add_default_settings() {
|
||||
foreach ( self::get_settings() as $setting ) {
|
||||
@@ -1182,7 +1201,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Deteremines if the subscriptions settings have been setup.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @return bool Whether any subscription settings exist.
|
||||
*/
|
||||
public static function has_settings() {
|
||||
@@ -1199,12 +1218,18 @@ class WC_Subscriptions_Admin {
|
||||
* Get all the settings for the Subscriptions extension in the format required by the @see woocommerce_admin_fields() function.
|
||||
*
|
||||
* @return array Array of settings in the format required by the @see woocommerce_admin_fields() function.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_settings() {
|
||||
|
||||
return apply_filters( 'woocommerce_subscription_settings', array(
|
||||
|
||||
/**
|
||||
* Filter the settings for the Subscriptions extension.
|
||||
*
|
||||
* @param array $settings Array of settings in the format required by the woocommerce_admin_fields() function.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_subscription_settings',
|
||||
array(
|
||||
array(
|
||||
'name' => _x( 'Miscellaneous', 'options section heading', 'woocommerce-subscriptions' ),
|
||||
'type' => 'title',
|
||||
@@ -1225,14 +1250,15 @@ class WC_Subscriptions_Admin {
|
||||
'type' => 'sectionend',
|
||||
'id' => self::$option_prefix . '_miscellaneous',
|
||||
),
|
||||
) );
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays instructional information for a WooCommerce setting.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function add_informational_admin_field( $field_details ) {
|
||||
|
||||
@@ -1248,7 +1274,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Checks whether a user should be shown pointers or not, based on whether a user has previously dismissed pointers.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function show_user_pointers() {
|
||||
// Get dismissed pointers
|
||||
@@ -1267,7 +1293,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* The 'select_subscription' flag is picked up by JavaScript to set the value of the product type to "Subscription".
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function add_subscription_url( $show_pointers = true ) {
|
||||
$add_subscription_url = admin_url( 'post-new.php?post_type=product&select_subscription=true' );
|
||||
@@ -1276,14 +1302,14 @@ class WC_Subscriptions_Admin {
|
||||
$add_subscription_url = add_query_arg( 'subscription_pointers', 'true', $add_subscription_url );
|
||||
}
|
||||
|
||||
return $add_subscription_url;
|
||||
return $add_subscription_url; // nosemgrep: audit.php.wp.security.xss.query-arg -- False positive. The returned URL is escaped where it is used and escaping URLs should be done at the point of output or usage, not on return.
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches through the list of active plugins to find WooCommerce. Just in case
|
||||
* WooCommerce resides in a folder other than /woocommerce/
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_woocommerce_plugin_dir_file() {
|
||||
|
||||
@@ -1304,7 +1330,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param string $where
|
||||
* @return string
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function filter_orders( $where ) {
|
||||
global $typenow, $wpdb;
|
||||
@@ -1331,10 +1357,40 @@ class WC_Subscriptions_Admin {
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the Orders Table in HPOS to display_renewal_filter_noticehow only orders associated with a specific subscription.
|
||||
*
|
||||
* @since 5.2.0
|
||||
*
|
||||
* @param array $query_vars The query variables.
|
||||
*
|
||||
* @return array The query variables.
|
||||
*/
|
||||
public static function filter_orders_table_by_related_orders( $query_vars ) {
|
||||
/**
|
||||
* Exit early if the request is not to filter the order list table.
|
||||
*
|
||||
* Note this request isn't nonced as we're only filtering an admin list table and not modifying data.
|
||||
*/
|
||||
if ( ! ( is_admin() && isset( $_GET['_subscription_related_orders'] ) && $_GET['_subscription_related_orders'] > 0 ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
$subscription = wcs_get_subscription( absint( $_GET['_subscription_related_orders'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( ! wcs_is_subscription( $subscription ) ) {
|
||||
$query_vars['post__in'] = [ 0 ];
|
||||
} else {
|
||||
$query_vars['post__in'] = array_unique( $subscription->get_related_orders( 'ids' ) );
|
||||
}
|
||||
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the Admin orders and subscriptions table results based on a list of IDs returned by a report query.
|
||||
*
|
||||
* @since 2.6.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.2
|
||||
*
|
||||
* @param string $where The query WHERE clause.
|
||||
* @return string $where
|
||||
@@ -1361,12 +1417,14 @@ class WC_Subscriptions_Admin {
|
||||
// Display an admin notice if we cannot find the report data requested.
|
||||
if ( ! isset( $cache[ $cache_report_key ] ) ) {
|
||||
$admin_notice = new WCS_Admin_Notice( 'error' );
|
||||
$admin_notice->set_simple_content( sprintf(
|
||||
$admin_notice->set_simple_content(
|
||||
sprintf(
|
||||
/* translators: Placeholders are opening and closing link tags. */
|
||||
__( 'We weren\'t able to locate the set of report results you requested. Please regenerate the link from the %1$sSubscription Reports screen%2$s.', 'woocommerce-subscriptions' ),
|
||||
'<a href="' . esc_url( admin_url( 'admin.php?page=wc-reports&tab=subscriptions&report=subscription_events_by_date' ) ) . '">',
|
||||
'</a>'
|
||||
) );
|
||||
)
|
||||
);
|
||||
$admin_notice->display();
|
||||
|
||||
$where .= " AND {$wpdb->posts}.ID = 0";
|
||||
@@ -1394,7 +1452,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param string $where
|
||||
* @return string
|
||||
* @since 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
*/
|
||||
public static function filter_paid_subscription_orders_for_user( $where ) {
|
||||
global $typenow, $wpdb;
|
||||
@@ -1433,34 +1491,35 @@ class WC_Subscriptions_Admin {
|
||||
* @see self::filter_orders()
|
||||
*/
|
||||
public static function display_renewal_filter_notice() {
|
||||
// When HPOS is disabled, use the $found_related_orders static variable to determine if the Orders list is filtered or not.
|
||||
if ( ! wcs_is_custom_order_tables_usage_enabled() && ! self::$found_related_orders ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wp_version;
|
||||
/**
|
||||
* This request URL isn't nonced because it's only used to display a notice to the user.
|
||||
*/
|
||||
if ( isset( $_GET['_subscription_related_orders'] ) && $_GET['_subscription_related_orders'] > 0 ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$subscription_id = absint( $_GET['_subscription_related_orders'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$subscription = wcs_get_subscription( $subscription_id );
|
||||
|
||||
$query_arg = '_subscription_related_orders';
|
||||
// Display an error notice if we can't find the subscription.
|
||||
if ( ! $subscription ) {
|
||||
echo '<div id="moderated" class="error"><p>';
|
||||
// translators: placeholder is a subscription ID.
|
||||
printf( esc_html__( 'We can\'t find a subscription with ID #%d. Perhaps it was deleted?', 'woocommerce-subscriptions' ), esc_html( $subscription_id ) );
|
||||
echo '</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_GET[ $query_arg ] ) && $_GET[ $query_arg ] > 0 && true === self::$found_related_orders ) {
|
||||
|
||||
$initial_order = wc_get_order( absint( $_GET[ $query_arg ] ) );
|
||||
|
||||
if ( version_compare( $wp_version, '4.2', '<' ) ) {
|
||||
echo '<div class="updated"><p>';
|
||||
printf(
|
||||
'<a href="%1$s" class="close-subscriptions-search">×</a>',
|
||||
esc_url( remove_query_arg( $query_arg ) )
|
||||
);
|
||||
// translators: placeholders are opening link tag, ID of sub, and closing link tag
|
||||
printf( esc_html__( 'Showing orders for %1$sSubscription %2$s%3$s', 'woocommerce-subscriptions' ), '<a href="' . esc_url( get_edit_post_link( absint( $_GET[ $query_arg ] ) ) ) . '">', esc_html( $initial_order->get_order_number() ), '</a>' );
|
||||
echo '</p>';
|
||||
} else {
|
||||
echo '<div class="updated dismiss-subscriptions-search"><p>';
|
||||
// translators: placeholders are opening link tag, ID of sub, and closing link tag
|
||||
printf( esc_html__( 'Showing orders for %1$sSubscription %2$s%3$s', 'woocommerce-subscriptions' ), '<a href="' . esc_url( get_edit_post_link( absint( $_GET[ $query_arg ] ) ) ) . '">', esc_html( $initial_order->get_order_number() ), '</a>' );
|
||||
printf( esc_html__( 'Showing orders for %1$sSubscription %2$s%3$s', 'woocommerce-subscriptions' ), '<a href="' . esc_url( wcs_get_edit_post_link( $subscription ) ) . '">', esc_html( $subscription->get_order_number() ), '</a>' );
|
||||
echo '</p>';
|
||||
printf(
|
||||
'<a href="%1$s" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></a>',
|
||||
esc_url( remove_query_arg( $query_arg ) )
|
||||
esc_url( remove_query_arg( '_subscription_related_orders' ) )
|
||||
);
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
@@ -1470,7 +1529,7 @@ class WC_Subscriptions_Admin {
|
||||
* Returns either a string or array of strings describing the allowable trial period range
|
||||
* for a subscription.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_trial_period_validation_message( $form = 'combined' ) {
|
||||
|
||||
@@ -1563,7 +1622,7 @@ class WC_Subscriptions_Admin {
|
||||
* A WooCommerce version aware function for getting the Subscriptions admin settings
|
||||
* tab URL.
|
||||
*
|
||||
* @since 1.4.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.5
|
||||
* @return string
|
||||
*/
|
||||
public static function settings_tab_url() {
|
||||
@@ -1578,7 +1637,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param array $header
|
||||
*
|
||||
* @since 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
* @return array
|
||||
*/
|
||||
public static function payment_gateways_renewal_column( $header ) {
|
||||
@@ -1591,8 +1650,8 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Add a column to the Payment Gateway table to show whether the gateway supports automated renewals.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
* @return string
|
||||
*/
|
||||
public static function payment_gateways_rewewal_column( $header ) {
|
||||
@@ -1608,7 +1667,7 @@ class WC_Subscriptions_Admin {
|
||||
*
|
||||
* @param WC_Payment_Gateway $gateway
|
||||
*
|
||||
* @since 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
*/
|
||||
public static function payment_gateways_renewal_support( $gateway ) {
|
||||
$payment_gateways_handler = WC_Subscriptions_Core_Plugin::instance()->get_gateways_handler_class();
|
||||
@@ -1626,7 +1685,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Automatic Renewal Payments Support Status HTML Filter.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*
|
||||
* @param string $status_html
|
||||
* @param \WC_Payment_Gateway $gateway
|
||||
@@ -1641,8 +1700,8 @@ class WC_Subscriptions_Admin {
|
||||
* Automatically flag support for Paypal since it is included with subscriptions.
|
||||
* Display in the Payment Gateway column.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
*/
|
||||
public static function payment_gateways_rewewal_support( $gateway ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.5.3', 'WC_Subscriptions_Admin::payment_gateways_renewal_support( $gateway )' );
|
||||
@@ -1653,7 +1712,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Do not display formatted order total on the Edit Order administration screen
|
||||
*
|
||||
* @since 1.5.17
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.17
|
||||
*/
|
||||
public static function maybe_remove_formatted_order_total_filter( $formatted_total, $order ) {
|
||||
|
||||
@@ -1673,7 +1732,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Only attach the gettext callback when on admin shop subscription screen
|
||||
*
|
||||
* @since 2.2.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
|
||||
*/
|
||||
public static function maybe_attach_gettext_callback() {
|
||||
|
||||
@@ -1689,7 +1748,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Only unattach the gettext callback when it was attached
|
||||
*
|
||||
* @since 2.2.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
|
||||
*/
|
||||
public static function maybe_unattach_gettext_callback() {
|
||||
|
||||
@@ -1707,7 +1766,7 @@ class WC_Subscriptions_Admin {
|
||||
* When subscription items not editable (such as due to the payment gateway not supporting modifications),
|
||||
* change the text to explain why
|
||||
*
|
||||
* @since 2.2.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.7
|
||||
*/
|
||||
public static function change_order_item_editable_text( $translated_text, $text, $domain ) {
|
||||
|
||||
@@ -1728,7 +1787,7 @@ class WC_Subscriptions_Admin {
|
||||
* Add recurring payment gateway information after the Settings->Payments->Payment Methods table.
|
||||
* This includes information about manual renewals and a warning if no payment gateway which supports automatic recurring payments is enabled/setup correctly.
|
||||
*
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function add_recurring_payment_gateway_information( $settings ) {
|
||||
$available_gateways_description = '';
|
||||
@@ -1745,14 +1804,14 @@ class WC_Subscriptions_Admin {
|
||||
array(
|
||||
'name' => __( 'Recurring Payments', 'woocommerce-subscriptions' ),
|
||||
'desc' => $available_gateways_description,
|
||||
'id' => WC_Subscriptions_Admin::$option_prefix . '_payment_gateways_available',
|
||||
'id' => self::$option_prefix . '_payment_gateways_available',
|
||||
'type' => 'informational',
|
||||
),
|
||||
|
||||
array(
|
||||
// translators: placeholders are opening and closing link tags
|
||||
'desc' => sprintf( __( 'Payment gateways which don\'t support automatic recurring payments can be used to process %1$smanual subscription renewal payments%2$s.', 'woocommerce-subscriptions' ), '<a href="http://docs.woocommerce.com/document/subscriptions/renewal-process/">', '</a>' ),
|
||||
'id' => WC_Subscriptions_Admin::$option_prefix . '_payment_gateways_additional',
|
||||
'id' => self::$option_prefix . '_payment_gateways_additional',
|
||||
'type' => 'informational',
|
||||
),
|
||||
),
|
||||
@@ -1788,7 +1847,7 @@ class WC_Subscriptions_Admin {
|
||||
* Check if subscription product meta data should be saved for the current request.
|
||||
*
|
||||
* @param array Array of product types.
|
||||
* @since 2.2.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.9
|
||||
*/
|
||||
private static function is_subscription_product_save_request( $post_id, $product_types ) {
|
||||
|
||||
@@ -1810,7 +1869,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Insert a setting or an array of settings after another specific setting by its ID.
|
||||
*
|
||||
* @since 2.2.20
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.20
|
||||
* @param array $settings The original list of settings. Passed by reference.
|
||||
* @param string $insert_after_setting_id The setting id to insert the new setting after.
|
||||
* @param array $new_setting The new setting to insert. Can be a single setting or an array of settings.
|
||||
@@ -1853,7 +1912,7 @@ class WC_Subscriptions_Admin {
|
||||
|
||||
/**
|
||||
* Add a reminder on the enable guest checkout setting that subscriptions still require an account
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @param array $settings The list of settings
|
||||
*/
|
||||
public static function add_guest_checkout_setting_note( $settings ) {
|
||||
@@ -1881,7 +1940,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Gets the product type warning message displayed for products associated with subscriptions
|
||||
*
|
||||
* @since 3.0.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.7
|
||||
* @return string The change product type warning message.
|
||||
*/
|
||||
private static function get_change_product_type_warning() {
|
||||
@@ -1895,7 +1954,7 @@ class WC_Subscriptions_Admin {
|
||||
* can cause issues. For example when customers who try to manually renew where the subscription
|
||||
* products are placed in the cart.
|
||||
*
|
||||
* @since 3.0.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.7
|
||||
* @param int $product_id The product ID being saved.
|
||||
*/
|
||||
public static function validate_product_type_change( $product_id ) {
|
||||
@@ -1930,14 +1989,17 @@ class WC_Subscriptions_Admin {
|
||||
* This setting allows stores to enable users to create an account when purchasing a subscription, but
|
||||
* not allow an account to be created when they are making one off/standard purchases.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*
|
||||
* @param array $settings The Accounts & Privacy settings.
|
||||
* @return array $settings.
|
||||
*/
|
||||
public static function add_registration_for_subscription_purchases_setting( $settings ) {
|
||||
|
||||
self::insert_setting_after( $settings, 'woocommerce_enable_signup_and_login_from_checkout', array(
|
||||
self::insert_setting_after(
|
||||
$settings,
|
||||
'woocommerce_enable_signup_and_login_from_checkout',
|
||||
array(
|
||||
'id' => 'woocommerce_enable_signup_from_checkout_for_subscriptions',
|
||||
'name' => __( 'Allow subscription customers to create an account during checkout', 'woocommerce-subscriptions' ),
|
||||
'desc' => __( 'Allow subscription customers to create an account during checkout', 'woocommerce-subscriptions' ),
|
||||
@@ -1945,7 +2007,8 @@ class WC_Subscriptions_Admin {
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
'autoload' => false,
|
||||
) );
|
||||
)
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
@@ -1980,7 +2043,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Set a translation safe screen ID for Subcsription
|
||||
*
|
||||
* @since 1.3.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.3
|
||||
*/
|
||||
public static function set_admin_screen_id() {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1989,7 +2052,7 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Once we have set a correct admin page screen ID, we can use it for adding the Manage Subscriptions table's columns.
|
||||
*
|
||||
* @since 1.3.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.3
|
||||
*/
|
||||
public static function add_subscriptions_table_column_filter() {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2008,7 +2071,7 @@ class WC_Subscriptions_Admin {
|
||||
|
||||
/**
|
||||
* Registers the "Renewal Orders" meta box for the "Edit Order" page.
|
||||
* @deprecated 2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_meta_boxes() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Admin_Meta_Boxes::add_meta_boxes()' );
|
||||
@@ -2024,37 +2087,37 @@ class WC_Subscriptions_Admin {
|
||||
/**
|
||||
* Filters the Admin orders table results based on a list of IDs returned by a report query.
|
||||
*
|
||||
* @deprecated 2.6.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.2
|
||||
*
|
||||
* @param string $where The query WHERE clause.
|
||||
* @return string $where
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function filter_orders_from_list( $where ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.6.2', 'WC_Subscriptions_Admin::filter_orders_and_subscriptions_from_list( $where )' );
|
||||
|
||||
return WC_Subscriptions_Admin::filter_orders_and_subscriptions_from_list( $where );
|
||||
return self::filter_orders_and_subscriptions_from_list( $where );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the Admin subscriptions table results based on a list of IDs returned by a report query.
|
||||
*
|
||||
* @deprecated 2.6.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.2
|
||||
*
|
||||
* @param string $where The query WHERE clause.
|
||||
* @return string
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function filter_subscriptions_from_list( $where ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.6.2', 'WC_Subscriptions_Admin::filter_orders_and_subscriptions_from_list( $where )' );
|
||||
|
||||
return WC_Subscriptions_Admin::filter_orders_and_subscriptions_from_list( $where );
|
||||
return self::filter_orders_and_subscriptions_from_list( $where );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents variations from being deleted if switching from a variable product type to a subscription variable product type (and vice versa).
|
||||
*
|
||||
* @since 3.0.14
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.14
|
||||
*
|
||||
* @param bool $delete_variations A boolean value of true will delete the variations.
|
||||
* @param WC_Product $product Product data.
|
||||
|
@@ -4,10 +4,9 @@
|
||||
*
|
||||
* Sets up the write panels used by the subscription custom order/post type
|
||||
*
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -24,7 +23,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 25 );
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 25, 2 );
|
||||
|
||||
add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 35 );
|
||||
|
||||
@@ -33,7 +32,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles_scripts' ), 20 );
|
||||
|
||||
// We need to hook to the 'shop_order' rather than 'shop_subscription' because we declared that the 'shop_susbcription' order type supports 'order-meta-boxes'
|
||||
// We need to hook to the 'shop_order' rather than 'shop_subscription' because we declared that the 'shop_subscription' order type supports 'order-meta-boxes'.
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WCS_Meta_Box_Schedule::save', 10, 2 );
|
||||
add_action( 'woocommerce_process_shop_order_meta', 'WCS_Meta_Box_Subscription_Data::save', 10, 2 );
|
||||
|
||||
@@ -49,7 +48,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
|
||||
add_action( 'woocommerce_order_action_wcs_retry_renewal_payment', array( __CLASS__, 'process_retry_renewal_payment_action_request' ), 10, 1 );
|
||||
|
||||
// Disable stock managment while adding line items to a subscription via AJAX.
|
||||
// Disable stock management while adding line items to a subscription via AJAX.
|
||||
add_action( 'option_woocommerce_manage_stock', array( __CLASS__, 'override_stock_management' ) );
|
||||
|
||||
// Parent order line item price lock option.
|
||||
@@ -72,21 +71,41 @@ class WCS_Admin_Meta_Boxes {
|
||||
|
||||
/**
|
||||
* Add WC Meta boxes
|
||||
*
|
||||
* @see add_meta_boxes
|
||||
*
|
||||
* @param string $post_type The post type of the current post being edited.
|
||||
* @param WP_Post|WC_Order|null $post_or_order_object The post or order currently being edited.
|
||||
*/
|
||||
public function add_meta_boxes() {
|
||||
public function add_meta_boxes( $post_type = '', $post_or_order_object = null ) {
|
||||
$subscriptions_screen_id = wcs_get_page_screen_id( 'shop_subscription' );
|
||||
|
||||
add_meta_box( 'woocommerce-subscription-data', _x( 'Subscription Data', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Subscription_Data::output', $subscriptions_screen_id, 'normal', 'high' );
|
||||
|
||||
add_meta_box( 'woocommerce-subscription-schedule', _x( 'Schedule', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Schedule::output', $subscriptions_screen_id, 'side', 'default' );
|
||||
|
||||
remove_meta_box( 'woocommerce-order-data', $subscriptions_screen_id, 'normal' );
|
||||
|
||||
add_meta_box( 'subscription_renewal_orders', __( 'Related Orders', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Related_Orders::output', $subscriptions_screen_id, 'normal', 'low' );
|
||||
|
||||
// Ensure backwards compatibility if $post_or_order_object not provided and is 'shop_order' post type.
|
||||
if ( ! $post_or_order_object && 'shop_order' === $post_type ) {
|
||||
global $post_ID;
|
||||
$post_or_order_object = wc_get_order( $post_ID );
|
||||
}
|
||||
|
||||
add_meta_box( 'woocommerce-subscription-data', _x( 'Subscription Data', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Subscription_Data::output', 'shop_subscription', 'normal', 'high' );
|
||||
// Get "Edit Order" screen ID, which differs if HPOS is enabled.
|
||||
$order_screen_id = wcs_get_page_screen_id( 'shop_order' );
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
add_meta_box( 'woocommerce-subscription-schedule', _x( 'Schedule', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Schedule::output', 'shop_subscription', 'side', 'default' );
|
||||
// Only display the meta box if viewing an order that contains a subscription.
|
||||
if ( $post_or_order_object && $current_screen && $current_screen->id === $order_screen_id && wcs_order_contains_subscription( $post_or_order_object, 'any' ) ) {
|
||||
add_meta_box( 'subscription_renewal_orders', __( 'Related Orders', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Related_Orders::output', $order_screen_id, 'normal', 'low' );
|
||||
}
|
||||
|
||||
remove_meta_box( 'woocommerce-order-data', 'shop_subscription', 'normal' );
|
||||
|
||||
add_meta_box( 'subscription_renewal_orders', __( 'Related Orders', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Related_Orders::output', 'shop_subscription', 'normal', 'low' );
|
||||
|
||||
// Only display the meta box if an order relates to a subscription
|
||||
if ( 'shop_order' === WC_Data_Store::load( 'order' )->get_order_type( $post_ID ) && wcs_order_contains_subscription( $post_ID, 'any' ) ) {
|
||||
add_meta_box( 'subscription_renewal_orders', __( 'Related Orders', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Related_Orders::output', 'shop_order', 'normal', 'low' );
|
||||
// On HPOS environments we need to remove and readd the line items meta box so it appears after the subscription data.
|
||||
if ( wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
self::reorder_subscription_line_items_meta_box();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,11 +117,15 @@ class WCS_Admin_Meta_Boxes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't save save some order related meta boxes
|
||||
* Don't save some order related meta boxes.
|
||||
*
|
||||
* @see woocommerce_process_shop_order_meta
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
public function remove_meta_box_save( $post_id, $post ) {
|
||||
|
||||
if ( 'shop_subscription' == $post->post_type ) {
|
||||
public function remove_meta_box_save( $order_id, $order ) {
|
||||
if ( wcs_is_subscription( $order_id ) ) {
|
||||
remove_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40 );
|
||||
}
|
||||
}
|
||||
@@ -111,21 +134,35 @@ class WCS_Admin_Meta_Boxes {
|
||||
* Print admin styles/scripts
|
||||
*/
|
||||
public function enqueue_styles_scripts() {
|
||||
global $post;
|
||||
global $theorder;
|
||||
|
||||
// Get admin screen id
|
||||
// If $theorder is empty, fallback to using the global post object.
|
||||
if ( empty( $theorder ) && ! empty( $GLOBALS['post']->ID ) ) {
|
||||
$theorder = wcs_get_subscription( $GLOBALS['post']->ID );
|
||||
}
|
||||
|
||||
// Get admin screen ID.
|
||||
$screen = get_current_screen();
|
||||
$screen_id = isset( $screen->id ) ? $screen->id : '';
|
||||
|
||||
if ( 'shop_subscription' == $screen_id ) {
|
||||
// Get the script version.
|
||||
$ver = WC_Subscriptions_Core_Plugin::instance()->get_library_version();
|
||||
|
||||
wp_register_script( 'jstz', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/jstz.min.js' ) );
|
||||
if ( wcs_get_page_screen_id( 'shop_subscription' ) === $screen_id && wcs_is_subscription( $theorder ) ) {
|
||||
// Declare a subscription variable for clearer use. The $theorder global on edit subscription screens is a subscription.
|
||||
$subscription = $theorder;
|
||||
|
||||
wp_register_script( 'momentjs', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/moment.min.js' ) );
|
||||
wp_register_script( 'jstz', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/jstz.min.js' ), [], $ver, false );
|
||||
wp_register_script( 'momentjs', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/moment.min.js' ), [], $ver, false );
|
||||
|
||||
wp_enqueue_script( 'wcs-admin-meta-boxes-subscription', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/meta-boxes-subscription.js' ), array( 'wc-admin-meta-boxes', 'jstz', 'momentjs' ), WC_VERSION );
|
||||
wp_enqueue_script( 'wcs-admin-meta-boxes-subscription', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/meta-boxes-subscription.js' ), array( 'wc-admin-meta-boxes', 'jstz', 'momentjs' ), $ver, false );
|
||||
|
||||
wp_localize_script( 'wcs-admin-meta-boxes-subscription', 'wcs_admin_meta_boxes', apply_filters( 'woocommerce_subscriptions_admin_meta_boxes_script_parameters', array(
|
||||
wp_localize_script(
|
||||
'wcs-admin-meta-boxes-subscription',
|
||||
'wcs_admin_meta_boxes',
|
||||
apply_filters(
|
||||
'woocommerce_subscriptions_admin_meta_boxes_script_parameters',
|
||||
array(
|
||||
'i18n_start_date_notice' => __( 'Please enter a start date in the past.', 'woocommerce-subscriptions' ),
|
||||
'i18n_past_date_notice' => WCS_Staging::is_duplicate_site() ? __( 'Please enter a date at least 2 minutes into the future.', 'woocommerce-subscriptions' ) : __( 'Please enter a date at least one hour into the future.', 'woocommerce-subscriptions' ),
|
||||
'i18n_next_payment_start_notice' => __( 'Please enter a date after the trial end.', 'woocommerce-subscriptions' ),
|
||||
@@ -134,14 +171,16 @@ class WCS_Admin_Meta_Boxes {
|
||||
'i18n_trial_end_next_notice' => __( 'Please enter a date before the next payment.', 'woocommerce-subscriptions' ),
|
||||
'i18n_end_date_notice' => __( 'Please enter a date after the next payment.', 'woocommerce-subscriptions' ),
|
||||
'process_renewal_action_warning' => __( "Are you sure you want to process a renewal?\n\nThis will charge the customer and email them the renewal order (if emails are enabled).", 'woocommerce-subscriptions' ),
|
||||
'payment_method' => wcs_get_subscription( $post )->get_payment_method(),
|
||||
'payment_method' => $subscription->get_payment_method(),
|
||||
'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
|
||||
'get_customer_orders_nonce' => wp_create_nonce( 'get-customer-orders' ),
|
||||
'is_duplicate_site' => WCS_Staging::is_duplicate_site(),
|
||||
) ) );
|
||||
} else if ( 'shop_order' == $screen_id ) {
|
||||
)
|
||||
)
|
||||
);
|
||||
} elseif ( 'shop_order' === $screen_id ) {
|
||||
|
||||
wp_enqueue_script( 'wcs-admin-meta-boxes-order', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/wcs-meta-boxes-order.js' ) );
|
||||
wp_enqueue_script( 'wcs-admin-meta-boxes-order', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/wcs-meta-boxes-order.js' ), [], $ver, false );
|
||||
|
||||
wp_localize_script(
|
||||
'wcs-admin-meta-boxes-order',
|
||||
@@ -150,15 +189,13 @@ class WCS_Admin_Meta_Boxes {
|
||||
'retry_renewal_payment_action_warning' => __( "Are you sure you want to retry payment for this renewal order?\n\nThis will attempt to charge the customer and send renewal order emails (if emails are enabled).", 'woocommerce-subscriptions' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Enqueue the metabox script for coupons.
|
||||
if ( ! wcs_is_woocommerce_pre( '3.2' ) && in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
|
||||
} elseif ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ), true ) ) {
|
||||
wp_enqueue_script(
|
||||
'wcs-admin-coupon-meta-boxes',
|
||||
WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory_url( 'assets/js/admin/meta-boxes-coupon.js' ),
|
||||
array( 'jquery', 'wc-admin-meta-boxes' ),
|
||||
WC_Subscriptions_Core_Plugin::instance()->get_plugin_version()
|
||||
$ver,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -168,7 +205,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
*
|
||||
* @param array $actions An array of available actions
|
||||
* @return array An array of updated actions
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_subscription_actions( $actions ) {
|
||||
global $theorder;
|
||||
@@ -200,7 +237,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* Handles the action request to process a renewal order.
|
||||
*
|
||||
* @param array $subscription
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function process_renewal_action_request( $subscription ) {
|
||||
$subscription->add_order_note( __( 'Process renewal order action requested by admin.', 'woocommerce-subscriptions' ), false, true );
|
||||
@@ -211,7 +248,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* Handles the action request to create a pending renewal order.
|
||||
*
|
||||
* @param array $subscription
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function create_pending_renewal_action_request( $subscription ) {
|
||||
$subscription->add_order_note( __( 'Create pending renewal order requested by admin action.', 'woocommerce-subscriptions' ), false, true );
|
||||
@@ -233,7 +270,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* Handles the action request to create a pending parent order.
|
||||
*
|
||||
* @param array $subscription
|
||||
* @since 2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
public static function create_pending_parent_action_request( $subscription ) {
|
||||
|
||||
@@ -263,7 +300,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* Removes order related emails from the available actions.
|
||||
*
|
||||
* @param array $available_emails
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function remove_order_email_actions( $email_actions ) {
|
||||
global $theorder;
|
||||
@@ -279,7 +316,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* Process the action request to retry renewal payment for failed renewal orders.
|
||||
*
|
||||
* @param WC_Order $order
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function process_retry_renewal_payment_action_request( $order ) {
|
||||
|
||||
@@ -304,13 +341,13 @@ class WCS_Admin_Meta_Boxes {
|
||||
*
|
||||
* @param WC_Order $order
|
||||
* @return bool
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
private static function can_renewal_order_be_retried( $order ) {
|
||||
|
||||
$can_be_retried = false;
|
||||
|
||||
if ( wcs_order_contains_renewal( $order ) && $order->needs_payment() && '' != wcs_get_objects_property( $order, 'payment_method' ) ) {
|
||||
if ( wcs_order_contains_renewal( $order ) && $order->needs_payment() && '' != wcs_get_objects_property( $order, 'payment_method' ) ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
||||
$supports_date_changes = false;
|
||||
$order_payment_gateway = wc_get_payment_gateway_by_order( $order );
|
||||
$order_payment_gateway_supports = ( isset( $order_payment_gateway->id ) ) ? has_action( 'woocommerce_scheduled_subscription_payment_' . $order_payment_gateway->id ) : false;
|
||||
@@ -328,9 +365,9 @@ class WCS_Admin_Meta_Boxes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables stock managment while adding items to a subscription via the edit subscription screen.
|
||||
* Disables stock management while adding items to a subscription via the edit subscription screen.
|
||||
*
|
||||
* @since 3.0.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.6
|
||||
*
|
||||
* @param string $manage_stock The default manage stock setting.
|
||||
* @return string Whether the stock should be managed.
|
||||
@@ -338,7 +375,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
public static function override_stock_management( $manage_stock ) {
|
||||
|
||||
// Override stock management while adding line items to a subscription via AJAX.
|
||||
if ( isset( $_POST['order_id'], $_REQUEST['security'] ) && wp_verify_nonce( $_REQUEST['security'], 'order-item' ) && doing_action( 'wp_ajax_woocommerce_add_order_item' ) && wcs_is_subscription( absint( wp_unslash( $_POST['order_id'] ) ) ) ) {
|
||||
if ( isset( $_POST['order_id'], $_REQUEST['security'] ) && wp_verify_nonce( wc_clean( wp_unslash( $_REQUEST['security'] ) ), 'order-item' ) && doing_action( 'wp_ajax_woocommerce_add_order_item' ) && wcs_is_subscription( absint( wp_unslash( $_POST['order_id'] ) ) ) ) {
|
||||
$manage_stock = 'no';
|
||||
}
|
||||
|
||||
@@ -355,7 +392,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* - The order's currency matches the base store currency.
|
||||
* - The order contains a line item with a subtotal greater than the product's current live price.
|
||||
*
|
||||
* @since 3.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.10
|
||||
*
|
||||
* @param WC_Order $order The order being edited.
|
||||
*/
|
||||
@@ -389,7 +426,8 @@ class WCS_Admin_Meta_Boxes {
|
||||
'<div id="wcs_order_price_lock"><label for="wcs-order-price-lock">%s</label>%s<input id="wcs-order-price-lock" type="checkbox" name="wcs_order_price_lock" value="yes" %s></div>',
|
||||
esc_html__( 'Lock manual price increases', 'woocommerce-subscriptions' ),
|
||||
// So the help tip is initialized when the line items are reloaded, we need to add the 'tips' class to the element.
|
||||
wcs_help_tip( $help_tip, false, 'woocommerce-help-tip tips' ),
|
||||
// PHPCS warning ignored since escaping is handled by wc_help_tip().
|
||||
wcs_help_tip( $help_tip, false, 'woocommerce-help-tip tips' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
checked( $order->get_meta( '_manual_price_increases_locked' ), 'true', false )
|
||||
);
|
||||
}
|
||||
@@ -398,13 +436,13 @@ class WCS_Admin_Meta_Boxes {
|
||||
/**
|
||||
* Saves the manual price increase lock via Edit order save and ajax request.
|
||||
*
|
||||
* @since 3.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.10
|
||||
*
|
||||
* @param string $order_id Optional. The order ID. For non-ajax requests, this parameter is required.
|
||||
*/
|
||||
public static function save_increased_price_lock( $order_id = '' ) {
|
||||
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) ) {
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( wc_clean( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,7 +452,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_POST['wcs_order_price_lock'] ) && 'yes' === wc_clean( $_POST['wcs_order_price_lock'] ) ) {
|
||||
if ( isset( $_POST['wcs_order_price_lock'] ) && 'yes' === wc_clean( wp_unslash( $_POST['wcs_order_price_lock'] ) ) ) {
|
||||
$order->update_meta_data( '_manual_price_increases_locked', 'true' );
|
||||
$order->save();
|
||||
} elseif ( $order->meta_exists( '_manual_price_increases_locked' ) ) {
|
||||
@@ -426,7 +464,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
/**
|
||||
* Stores the subtracted base location tax totals for subscription and renewal line items.
|
||||
*
|
||||
* @since 3.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.10
|
||||
*
|
||||
* @param int $item_id The ID of the order item added.
|
||||
* @param WC_Order_Item_Product $line_item The line item added.
|
||||
@@ -490,7 +528,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
* - WC_AJAX::remove_order_item().
|
||||
* - wc_save_order_items().
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*
|
||||
* @param WC_Order_Item $item The line item being saved/updated via the edit subscription screen.
|
||||
* @return bool Whether to reduce stock for the line item.
|
||||
@@ -507,7 +545,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
/**
|
||||
* Updates the `_subtracted_base_location_tax` meta when admin users update a line item's quantity.
|
||||
*
|
||||
* @since 3.0.14
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.14
|
||||
*
|
||||
* @param int $order_id The edited order or subscription ID.
|
||||
* @param array $item_data An array of data about all line item changes.
|
||||
@@ -556,7 +594,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
/**
|
||||
* Updates the `_subtracted_base_location_taxes` meta when admin users update a line item's price.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*
|
||||
* @param int $order_id The edited order or subscription ID.
|
||||
* @param array $item_data An array of data about all line item changes.
|
||||
@@ -621,7 +659,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
*
|
||||
* Populates the parent order list on the edit subscription screen with orders belonging to the customer.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function get_customer_orders() {
|
||||
check_ajax_referer( 'get-customer-orders', 'security' );
|
||||
@@ -631,7 +669,7 @@ class WCS_Admin_Meta_Boxes {
|
||||
}
|
||||
|
||||
$customer_orders = array();
|
||||
$user_id = absint( $_POST['user_id'] );
|
||||
$user_id = absint( $_POST['user_id'] ?? null );
|
||||
$orders = wc_get_orders(
|
||||
array(
|
||||
'customer' => $user_id,
|
||||
@@ -640,11 +678,48 @@ class WCS_Admin_Meta_Boxes {
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
foreach ( $orders as $order ) {
|
||||
$customer_orders[ $order->get_id() ] = $order->get_order_number();
|
||||
}
|
||||
|
||||
wp_send_json( $customer_orders );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders the edit subscription screen meta boxes.
|
||||
*
|
||||
* Removes and readds the order items meta box so it appears after the subscription data.
|
||||
*
|
||||
* On HPOS environments, WC core registers the order-data and order-items meta boxes on a high priority before we've had a chance to add ours.
|
||||
* This means, on the edit subscription screen, when we remove the order-data meta box and add our own, it will appear after the line items.
|
||||
*
|
||||
* In order to keep the correct ordering of the meta boxes on the edit subscription screen, we need to remove the line items meta box and
|
||||
* readd it after we've added the subscription-data meta box.
|
||||
*/
|
||||
private static function reorder_subscription_line_items_meta_box() {
|
||||
global $wp_meta_boxes;
|
||||
$subscriptions_screen_id = wcs_get_page_screen_id( 'shop_subscription' );
|
||||
|
||||
// If the line items meta box isn't registered, bail.
|
||||
if ( empty( $wp_meta_boxes[ $subscriptions_screen_id ]['normal']['high']['woocommerce-order-items'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a copy of the line items meta box.
|
||||
$items_meta_box = $wp_meta_boxes[ $subscriptions_screen_id ]['normal']['high']['woocommerce-order-items'];
|
||||
|
||||
// Forcibly remove the line items meta box to reset its ordering in the list.
|
||||
unset( $wp_meta_boxes[ $subscriptions_screen_id ]['normal']['high']['woocommerce-order-items'] );
|
||||
|
||||
// Readd it.
|
||||
add_meta_box(
|
||||
$items_meta_box['id'],
|
||||
$items_meta_box['title'],
|
||||
$items_meta_box['callback'],
|
||||
$subscriptions_screen_id,
|
||||
'normal',
|
||||
'high',
|
||||
$items_meta_box['args']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* API for creating and displaying an admin notice.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
*/
|
||||
@@ -69,7 +69,7 @@ class WCS_Admin_Notice {
|
||||
* @param string $type The notice type. Can be notice, notice-info, updated, error or a custom notice type.
|
||||
* @param array $attributes The container div's attributes. Optional.
|
||||
* @param string $dismiss_url The URL used to dismiss the notice. Optional.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function __construct( $type, array $attributes = array(), $dismiss_url = '' ) {
|
||||
$this->type = $type;
|
||||
@@ -82,7 +82,7 @@ class WCS_Admin_Notice {
|
||||
*
|
||||
* Will print the notice if called during the 'admin_notices' action. Otherwise will attach a callback and display the notice when the 'admin_notices' is triggered.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function display() {
|
||||
if ( 'admin_notices' !== current_filter() ) {
|
||||
@@ -104,7 +104,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Whether the admin notice is dismissible.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_dismissible() {
|
||||
@@ -114,7 +114,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Whether the admin notice has a heading or not.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_heading() {
|
||||
@@ -124,7 +124,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Whether the admin notice has actions or not.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function has_actions() {
|
||||
@@ -136,7 +136,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Print the notice's heading.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function print_heading() {
|
||||
echo esc_html( $this->heading );
|
||||
@@ -147,7 +147,7 @@ class WCS_Admin_Notice {
|
||||
*
|
||||
* Will wrap simple notices in paragraph elements (<p></p>) for correct styling and print HTML notices unchanged.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function print_content() {
|
||||
switch ( $this->content_type ) {
|
||||
@@ -168,7 +168,7 @@ class WCS_Admin_Notice {
|
||||
*
|
||||
* Turns the attributes array into 'id="id" class="class class class"' strings.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function print_attributes() {
|
||||
$attributes = $this->attributes;
|
||||
@@ -188,7 +188,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Print the notice's dismiss URL.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function print_dismiss_url() {
|
||||
echo esc_attr( $this->dismiss_url );
|
||||
@@ -199,7 +199,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Get the notice's actions.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_actions() {
|
||||
@@ -231,7 +231,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Set the notice's content to a string containing HTML elements.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @param string $template_name Template name.
|
||||
* @param string $template_path Template path.
|
||||
* @param array $args Arguments. (default: array).
|
||||
@@ -248,7 +248,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Set actions the user can make in response to this notice.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @param array $actions The actions the user can make. Example format:
|
||||
* array(
|
||||
* array(
|
||||
@@ -265,7 +265,7 @@ class WCS_Admin_Notice {
|
||||
/**
|
||||
* Set notice's heading. If set this will appear at the top of the notice wrapped in a h2 element.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @param string $heading The notice heading.
|
||||
*/
|
||||
public function set_heading( $heading ) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 3.0.13
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.13
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
@@ -7,8 +7,7 @@
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Admin
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
class WCS_Admin_System_Status {
|
||||
|
||||
@@ -20,7 +19,7 @@ class WCS_Admin_System_Status {
|
||||
/**
|
||||
* Attach callbacks
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public static function init() {
|
||||
add_filter( 'woocommerce_system_status_report', array( __CLASS__, 'render_system_status_items' ) );
|
||||
@@ -29,21 +28,25 @@ class WCS_Admin_System_Status {
|
||||
/**
|
||||
* Renders the Subscription information in the WC status page
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public static function render_system_status_items() {
|
||||
|
||||
$store_data = $subscriptions_data = $subscriptions_by_payment_gateway_data = $payment_gateway_data = array();
|
||||
$store_data = [];
|
||||
$subscriptions_data = [];
|
||||
$subscriptions_by_payment_gateway_data = [];
|
||||
$payment_gateway_data = [];
|
||||
|
||||
self::set_debug_mode( $subscriptions_data );
|
||||
self::set_staging_mode( $subscriptions_data );
|
||||
self::set_live_site_url( $subscriptions_data );
|
||||
self::set_library_version( $subscriptions_data );
|
||||
self::set_theme_overrides( $subscriptions_data );
|
||||
self::set_subscription_statuses( $subscriptions_data );
|
||||
self::set_woocommerce_account_data( $subscriptions_data );
|
||||
|
||||
// Subscriptions by Payment Gateway
|
||||
self::set_subscriptions_by_payment_gateway( $subscriptions_by_payment_gateway );
|
||||
self::set_subscriptions_by_payment_gateway( $subscriptions_by_payment_gateway_data );
|
||||
|
||||
// Payment gateway features
|
||||
self::set_subscriptions_payment_gateway_support( $payment_gateway_data );
|
||||
@@ -65,7 +68,7 @@ class WCS_Admin_System_Status {
|
||||
array(
|
||||
'title' => __( 'Subscriptions by Payment Gateway', 'woocommerce-subscriptions' ),
|
||||
'tooltip' => __( 'This section shows information about Subscription payment methods.', 'woocommerce-subscriptions' ),
|
||||
'data' => $subscriptions_by_payment_gateway,
|
||||
'data' => $subscriptions_by_payment_gateway_data,
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Payment Gateway Support', 'woocommerce-subscriptions' ),
|
||||
@@ -79,7 +82,7 @@ class WCS_Admin_System_Status {
|
||||
$section_tooltip = $section['tooltip'];
|
||||
$debug_data = $section['data'];
|
||||
|
||||
include( WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/admin/status.php' ) );
|
||||
include WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/admin/status.php' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +127,19 @@ class WCS_Admin_System_Status {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $debug_data
|
||||
*/
|
||||
private static function set_library_version( &$debug_data ) {
|
||||
$debug_data['wcs_subs_core_version'] = array(
|
||||
'name' => _x( 'Subscriptions-core Library Version', 'Subscriptions-core Version, Label on WooCommerce -> System Status page', 'woocommerce-subscriptions' ),
|
||||
'label' => 'Subscriptions-core Library Version',
|
||||
'note' => WC_Subscriptions_Core_Plugin::instance()->get_library_version(),
|
||||
'mark' => '',
|
||||
'mark_icon' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List any Subscriptions template overrides.
|
||||
*/
|
||||
@@ -151,7 +167,6 @@ class WCS_Admin_System_Status {
|
||||
/**
|
||||
* Determine which of our files have been overridden by the theme.
|
||||
*
|
||||
* @author Jeremy Pry
|
||||
* @return array Theme override data.
|
||||
*/
|
||||
private static function get_theme_overrides() {
|
||||
@@ -163,7 +178,7 @@ class WCS_Admin_System_Status {
|
||||
$templates = WC_Admin_Status::scan_template_files( $wcs_template_dir );
|
||||
|
||||
foreach ( $templates as $file ) {
|
||||
$theme_file = $is_outdated = false;
|
||||
$theme_file = false;
|
||||
$locations = array(
|
||||
get_stylesheet_directory() . "/{$file}",
|
||||
get_stylesheet_directory() . "/{$wc_template_path}{$file}",
|
||||
@@ -247,7 +262,7 @@ class WCS_Admin_System_Status {
|
||||
|
||||
foreach ( $woocommerce_account_subscriptions as $subscription ) {
|
||||
if ( isset( $subscription['product_id'] ) && self::WCS_PRODUCT_ID === $subscription['product_id'] ) {
|
||||
$has_active_product_key = in_array( $site_id, $subscription['connections'] );
|
||||
$has_active_product_key = in_array( $site_id, $subscription['connections'], false ); // phpcs:ignore WordPress.PHP.StrictInArray.FoundNonStrictFalse -- In case the value from $subscription['connections'] is a string.
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -268,9 +283,11 @@ class WCS_Admin_System_Status {
|
||||
|
||||
foreach ( self::get_subscriptions_by_gateway() as $payment_method => $status_counts ) {
|
||||
if ( isset( $gateways[ $payment_method ] ) ) {
|
||||
$payment_method_name = $payment_method_label = $gateways[ $payment_method ]->method_title;
|
||||
$payment_method_name = $gateways[ $payment_method ]->method_title;
|
||||
$payment_method_label = $gateways[ $payment_method ]->method_title;
|
||||
} else {
|
||||
$payment_method_label = $payment_method = 'other';
|
||||
$payment_method_label = 'other';
|
||||
$payment_method = 'other';
|
||||
$payment_method_name = _x( 'Other', 'label for the system status page', 'woocommerce-subscriptions' );
|
||||
}
|
||||
|
||||
@@ -344,34 +361,64 @@ class WCS_Admin_System_Status {
|
||||
/**
|
||||
* Gets the store's subscription broken down by payment gateway and status.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
* @return array The subscription gateway and status data array( 'gateway_id' => array( 'status' => count ) );
|
||||
*/
|
||||
public static function get_subscriptions_by_gateway() {
|
||||
global $wpdb;
|
||||
$subscription_gatway_data = array();
|
||||
$subscription_gateway_data = [];
|
||||
$is_hpos_in_use = wcs_is_custom_order_tables_usage_enabled();
|
||||
$order_status_column_name = $is_hpos_in_use ? 'status' : 'post_status';
|
||||
|
||||
$results = $wpdb->get_results( "
|
||||
SELECT COUNT(subscriptions.ID) as count, post_meta.meta_value as payment_method, subscriptions.post_status
|
||||
FROM $wpdb->posts as subscriptions RIGHT JOIN $wpdb->postmeta as post_meta ON post_meta.post_id = subscriptions.ID
|
||||
WHERE subscriptions.post_type = 'shop_subscription' && post_meta.meta_key = '_payment_method'
|
||||
GROUP BY post_meta.meta_value, subscriptions.post_status", ARRAY_A );
|
||||
|
||||
foreach ( $results as $result ) {
|
||||
$subscription_gatway_data[ $result['payment_method'] ][ $result['post_status'] ] = $result['count'];
|
||||
// Conduct a different query for HPOS and non-HPOS stores.
|
||||
if ( $is_hpos_in_use ) {
|
||||
// With HPOS enabled, `payment_method` is a column in the `wc_orders` table.
|
||||
$results = $wpdb->get_results(
|
||||
"SELECT
|
||||
COUNT(subscriptions.id) as count,
|
||||
subscriptions.payment_method,
|
||||
subscriptions.status
|
||||
FROM {$wpdb->prefix}wc_orders as subscriptions
|
||||
WHERE subscriptions.type = 'shop_subscription'
|
||||
GROUP BY subscriptions.payment_method, subscriptions.status",
|
||||
ARRAY_A
|
||||
);
|
||||
} else {
|
||||
// With HPOS disabled, `_payment_method` is a column in the `postmeta` table.
|
||||
$results = $wpdb->get_results(
|
||||
"SELECT
|
||||
COUNT(subscriptions.ID) as count,
|
||||
post_meta.meta_value as payment_method,
|
||||
subscriptions.post_status
|
||||
FROM {$wpdb->prefix}posts as subscriptions
|
||||
RIGHT JOIN {$wpdb->prefix}postmeta as post_meta ON post_meta.post_id = subscriptions.ID
|
||||
WHERE
|
||||
subscriptions.post_type = 'shop_subscription'
|
||||
&& post_meta.meta_key = '_payment_method'
|
||||
GROUP BY post_meta.meta_value, subscriptions.post_status",
|
||||
ARRAY_A
|
||||
);
|
||||
}
|
||||
|
||||
return $subscription_gatway_data;
|
||||
foreach ( $results as $result ) {
|
||||
// Ignore any results that don't have a payment method.
|
||||
if ( empty( $result['payment_method'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$subscription_gateway_data[ $result['payment_method'] ][ $result[ $order_status_column_name ] ] = $result['count'];
|
||||
}
|
||||
|
||||
return $subscription_gateway_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the store's subscriptions by status.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscription_statuses() {
|
||||
$subscriptions_by_status = (array) wp_count_posts( 'shop_subscription' );
|
||||
$subscriptions_by_status = WC_Data_Store::load( 'subscription' )->get_subscriptions_count_by_status();
|
||||
$subscriptions_by_status_output = array();
|
||||
|
||||
foreach ( $subscriptions_by_status as $status => $count ) {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* WooCommerce Subscriptions WC Admin Manager.
|
||||
*
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 3.0.2
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.2
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Loader;
|
||||
@@ -64,7 +64,7 @@ class WCS_WC_Admin_Manager {
|
||||
/**
|
||||
* Register the navigation items in the WooCommerce navigation.
|
||||
*
|
||||
* @since 3.0.12
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.12
|
||||
*/
|
||||
public static function register_navigation_items() {
|
||||
if (
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -7,8 +7,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -8,8 +8,8 @@
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin
|
||||
* @version 2.3
|
||||
* @since 2.3
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -4,10 +4,9 @@
|
||||
*
|
||||
* Display the related orders table on the Edit Order and Edit Subscription screens.
|
||||
*
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin/Meta Boxes
|
||||
* @version 2.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -21,52 +20,73 @@ class WCS_Meta_Box_Related_Orders {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
* @param WP_Post|WC_Order $post_or_order_object The post object or order object currently being edited.
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
public static function output( $post_or_order_object ) {
|
||||
$order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object;
|
||||
$post = ( $post_or_order_object instanceof WP_Post ) ? $post_or_order_object : get_post( $order->get_id() );
|
||||
|
||||
if ( wcs_is_subscription( $post->ID ) ) {
|
||||
$subscription = wcs_get_subscription( $post->ID );
|
||||
$order = ( false == $subscription->get_parent_id() ) ? $subscription : $subscription->get_parent();
|
||||
} else {
|
||||
$order = wc_get_order( $post->ID );
|
||||
add_action( 'wcs_related_orders_meta_box_rows', __CLASS__ . '::output_rows', 10 );
|
||||
|
||||
include_once dirname( __FILE__ ) . '/views/html-related-orders-table.php';
|
||||
|
||||
if ( has_action( 'woocommerce_subscriptions_related_orders_meta_box' ) ) {
|
||||
wcs_deprecated_hook( 'woocommerce_subscriptions_related_orders_meta_box', 'subscriptions-core 5.1.0', 'wcs_related_orders_meta_box' );
|
||||
|
||||
/**
|
||||
* Fires after the Related Orders meta box has been displayed.
|
||||
*
|
||||
* This action is deprecated in favour of 'wcs_related_orders_meta_box'.
|
||||
*
|
||||
* @deprecated subscriptions-core 5.1.0
|
||||
*
|
||||
* @param WC_Order|WC_Subscription $order The order or subscription that is being displayed.
|
||||
* @param WP_Post $post The post object that is being displayed.
|
||||
*/
|
||||
do_action( 'woocommerce_subscriptions_related_orders_meta_box', $order, $post );
|
||||
}
|
||||
|
||||
add_action( 'woocommerce_subscriptions_related_orders_meta_box_rows', __CLASS__ . '::output_rows', 10 );
|
||||
|
||||
include_once( dirname( __FILE__ ) . '/views/html-related-orders-table.php' );
|
||||
|
||||
do_action( 'woocommerce_subscriptions_related_orders_meta_box', $order, $post );
|
||||
/**
|
||||
* Fires after the Related Orders meta box has been displayed.
|
||||
*
|
||||
* @since subscriptions-core 5.1.0
|
||||
*
|
||||
* @param WC_Order|WC_Subscription $order The order or subscription that is being displayed.
|
||||
*/
|
||||
do_action( 'wcs_related_orders_meta_box', $order );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the renewal orders in the Related Orders meta box.
|
||||
*
|
||||
* @param object $post A WordPress post
|
||||
* @since 2.0
|
||||
* @param WC_Order|WC_Subscription $order The order or subscription object being used to display the related orders.
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function output_rows( $post ) {
|
||||
public static function output_rows( $order ) {
|
||||
$orders_to_display = array();
|
||||
$subscriptions = array();
|
||||
$initial_subscriptions = array();
|
||||
$orders_by_type = array();
|
||||
$unknown_orders = array(); // Orders which couldn't be loaded.
|
||||
$is_subscription = wcs_is_subscription( $order );
|
||||
$this_order = $order;
|
||||
|
||||
// If this is a subscriptions screen,
|
||||
if ( wcs_is_subscription( $post->ID ) ) {
|
||||
$this_subscription = wcs_get_subscription( $post->ID );
|
||||
$subscriptions[] = $this_subscription;
|
||||
if ( $is_subscription ) {
|
||||
$subscription = wcs_get_subscription( $order );
|
||||
$subscriptions[] = $subscription;
|
||||
|
||||
// Resubscribed subscriptions and orders.
|
||||
$initial_subscriptions = wcs_get_subscriptions_for_resubscribe_order( $this_subscription );
|
||||
$orders_by_type['resubscribe'] = WCS_Related_Order_Store::instance()->get_related_order_ids( $this_subscription, 'resubscribe' );
|
||||
$initial_subscriptions = wcs_get_subscriptions_for_resubscribe_order( $subscription );
|
||||
$orders_by_type['resubscribe'] = WCS_Related_Order_Store::instance()->get_related_order_ids( $subscription, 'resubscribe' );
|
||||
} else {
|
||||
$subscriptions = wcs_get_subscriptions_for_order( $post->ID, array( 'order_type' => array( 'parent', 'renewal' ) ) );
|
||||
$initial_subscriptions = wcs_get_subscriptions_for_order( $post->ID, array( 'order_type' => array( 'resubscribe' ) ) );
|
||||
$subscriptions = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'parent', 'renewal' ) ) );
|
||||
$initial_subscriptions = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'resubscribe' ) ) );
|
||||
}
|
||||
|
||||
foreach ( $subscriptions as $subscription ) {
|
||||
// If we're on a single subscription or renewal order's page, display the parent orders
|
||||
if ( 1 == count( $subscriptions ) && $subscription->get_parent_id() ) {
|
||||
if ( 1 === count( $subscriptions ) && $subscription->get_parent_id() ) {
|
||||
$orders_by_type['parent'][] = $subscription->get_parent_id();
|
||||
}
|
||||
|
||||
@@ -115,24 +135,50 @@ class WCS_Meta_Box_Related_Orders {
|
||||
}
|
||||
}
|
||||
|
||||
$orders_to_display = apply_filters( 'woocommerce_subscriptions_admin_related_orders_to_display', $orders_to_display, $subscriptions, $post );
|
||||
if ( has_filter( 'woocommerce_subscriptions_admin_related_orders_to_display' ) ) {
|
||||
wcs_deprecated_hook( 'woocommerce_subscriptions_admin_related_orders_to_display', 'subscriptions-core 5.1.0', 'wcs_admin_subscription_related_orders_to_display' );
|
||||
|
||||
/**
|
||||
* Filters the orders to display in the Related Orders meta box.
|
||||
*
|
||||
* This filter is deprecated in favour of 'wcs_admin_subscription_related_orders_to_display'.
|
||||
*
|
||||
* @deprecated subscriptions-core 5.1.0
|
||||
*
|
||||
* @param array $orders_to_display An array of orders to display in the Related Orders meta box.
|
||||
* @param array $subscriptions An array of subscriptions related to the order.
|
||||
* @param WP_Post $post The order post object.
|
||||
*/
|
||||
$orders_to_display = apply_filters( 'woocommerce_subscriptions_admin_related_orders_to_display', $orders_to_display, $subscriptions, get_post( $this_order->get_id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the orders to display in the Related Orders meta box.
|
||||
*
|
||||
* @since subscriptions-core 5.1.0
|
||||
*
|
||||
* @param array $orders_to_display An array of orders to display in the Related Orders meta box.
|
||||
* @param array $subscriptions An array of subscriptions related to the order.
|
||||
* @param WC_Order $order The order object.
|
||||
*/
|
||||
$orders_to_display = apply_filters( 'wcs_admin_subscription_related_orders_to_display', $orders_to_display, $subscriptions, $this_order );
|
||||
|
||||
wcs_sort_objects( $orders_to_display, 'date_created', 'descending' );
|
||||
|
||||
foreach ( $orders_to_display as $order ) {
|
||||
// Skip the order being viewed.
|
||||
if ( $order->get_id() === (int) $post->ID ) {
|
||||
// Skip the current order or subscription being viewed.
|
||||
if ( $order->get_id() === $this_order->get_id() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
include( dirname( __FILE__ ) . '/views/html-related-orders-row.php' );
|
||||
include dirname( __FILE__ ) . '/views/html-related-orders-row.php';
|
||||
}
|
||||
|
||||
foreach ( $unknown_orders as $order_and_relationship ) {
|
||||
$order_id = $order_and_relationship['order_id'];
|
||||
$relationship = $order_and_relationship['relation'];
|
||||
|
||||
include( dirname( __FILE__ ) . '/views/html-unknown-related-orders-row.php' );
|
||||
include dirname( __FILE__ ) . '/views/html-unknown-related-orders-row.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,10 +2,9 @@
|
||||
/**
|
||||
* Subscription Billing Schedule
|
||||
*
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin/Meta Boxes
|
||||
* @version 2.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -18,41 +17,66 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class WCS_Meta_Box_Schedule {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
* Outputs the subscription schedule metabox.
|
||||
*
|
||||
* @param WC_Subscription|WP_Post $subscription The subscription object to display the schedule metabox for. This will be a WP Post object on CPT stores.
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
public static function output( $subscription ) {
|
||||
global $post, $the_subscription;
|
||||
|
||||
if ( empty( $the_subscription ) ) {
|
||||
if ( $subscription && is_a( $subscription, 'WC_Subscription' ) ) {
|
||||
$the_subscription = $subscription;
|
||||
} elseif ( empty( $the_subscription ) ) {
|
||||
$the_subscription = wcs_get_subscription( $post->ID );
|
||||
}
|
||||
|
||||
include( dirname( __FILE__ ) . '/views/html-subscription-schedule.php' );
|
||||
/**
|
||||
* Subscriptions without a start date are freshly created subscriptions.
|
||||
* In order to display the schedule meta box we need to pre-populate the start date with the created date.
|
||||
*/
|
||||
if ( 0 === $the_subscription->get_time( 'start' ) ) {
|
||||
$the_subscription->set_start_date( $the_subscription->get_date( 'date_created' ) );
|
||||
}
|
||||
|
||||
include dirname( __FILE__ ) . '/views/html-subscription-schedule.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
* Saves the subscription schedule meta box data.
|
||||
*
|
||||
* @see woocommerce_process_shop_order_meta
|
||||
*
|
||||
* @param int $subscription_id The subscription ID to save the schedule for.
|
||||
* @param WC_Subscription/WP_Post $subscription The subscription object to save the schedule for.
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
public static function save( $subscription_id, $subscription ) {
|
||||
|
||||
if ( 'shop_subscription' == $post->post_type && ! empty( $_POST['woocommerce_meta_nonce'] ) && wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) ) {
|
||||
if ( ! wcs_is_subscription( $subscription_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( wc_clean( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $subscription instanceof WP_Post ) {
|
||||
$subscription = wcs_get_subscription( $subscription->ID );
|
||||
}
|
||||
|
||||
if ( isset( $_POST['_billing_interval'] ) ) {
|
||||
update_post_meta( $post_id, '_billing_interval', $_POST['_billing_interval'] );
|
||||
$subscription->set_billing_interval( wc_clean( wp_unslash( $_POST['_billing_interval'] ) ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['_billing_period'] ) ) {
|
||||
update_post_meta( $post_id, '_billing_period', $_POST['_billing_period'] );
|
||||
$subscription->set_billing_period( wc_clean( wp_unslash( $_POST['_billing_period'] ) ) );
|
||||
}
|
||||
|
||||
$subscription = wcs_get_subscription( $post_id );
|
||||
|
||||
$dates = array();
|
||||
|
||||
foreach ( wcs_get_subscription_date_types() as $date_type => $date_label ) {
|
||||
$date_key = wcs_normalise_date_type_key( $date_type );
|
||||
|
||||
if ( 'last_order_date_created' == $date_key ) {
|
||||
if ( 'last_order_date_created' === $date_key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -60,9 +84,9 @@ class WCS_Meta_Box_Schedule {
|
||||
|
||||
// A subscription needs a created date, even if it wasn't set or is empty
|
||||
if ( 'date_created' === $date_key && empty( $_POST[ $utc_timestamp_key ] ) ) {
|
||||
$datetime = current_time( 'timestamp', true );
|
||||
$datetime = time();
|
||||
} elseif ( isset( $_POST[ $utc_timestamp_key ] ) ) {
|
||||
$datetime = $_POST[ $utc_timestamp_key ];
|
||||
$datetime = wc_clean( wp_unslash( $_POST[ $utc_timestamp_key ] ) );
|
||||
} else { // No date to set
|
||||
continue;
|
||||
}
|
||||
@@ -73,7 +97,10 @@ class WCS_Meta_Box_Schedule {
|
||||
try {
|
||||
$subscription->update_dates( $dates, 'gmt' );
|
||||
|
||||
wp_cache_delete( $post_id, 'posts' );
|
||||
// Clear the posts cache for non-HPOS stores.
|
||||
if ( ! wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
wp_cache_delete( $subscription_id, 'posts' );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
wcs_add_admin_notice( $e->getMessage(), 'error' );
|
||||
}
|
||||
@@ -81,4 +108,3 @@ class WCS_Meta_Box_Schedule {
|
||||
$subscription->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,10 +4,9 @@
|
||||
*
|
||||
* Functions for displaying the order data meta box.
|
||||
*
|
||||
* @author Prospress
|
||||
* @category Admin
|
||||
* @package WooCommerce Subscriptions/Admin/Meta Boxes
|
||||
* @version 3.0.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -20,46 +19,56 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
* Outputs the Subscription data metabox.
|
||||
*
|
||||
* @param WC_Subscription|WP_Post $subscription The subscription object to display the data metabox for. On CPT stores, this will be a WP Post object.
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
public static function output( $subscription ) {
|
||||
global $the_subscription;
|
||||
|
||||
if ( ! is_object( $the_subscription ) || $the_subscription->get_id() !== $post->ID ) {
|
||||
$the_subscription = wc_get_order( $post->ID );
|
||||
if ( $subscription instanceof WP_Post ) {
|
||||
$subscription = wcs_get_subscription( $subscription->ID );
|
||||
}
|
||||
|
||||
$subscription = $the_subscription;
|
||||
if ( ! is_object( $the_subscription ) || $the_subscription->get_id() !== $subscription->get_id() ) {
|
||||
$the_subscription = $subscription;
|
||||
}
|
||||
|
||||
self::init_address_fields();
|
||||
|
||||
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
|
||||
|
||||
$subscription_title = $subscription->get_data_store()->get_title( $subscription );
|
||||
?>
|
||||
<style type="text/css">
|
||||
#post-body-content, #titlediv, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv { display:none }
|
||||
</style>
|
||||
<div class="panel-wrap woocommerce">
|
||||
<input name="post_title" type="hidden" value="<?php echo empty( $post->post_title ) ? esc_attr( get_post_type_object( $post->post_type )->labels->singular_name ) : esc_attr( $post->post_title ); ?>" />
|
||||
<input name="post_title" type="hidden" value="<?php echo empty( $order_title ) ? esc_attr( get_post_type_object( $subscription->get_type() )->labels->singular_name ) : esc_attr( $subscription_title ); ?>" />
|
||||
<input name="post_status" type="hidden" value="<?php echo esc_attr( 'wc-' . $subscription->get_status() ); ?>" />
|
||||
<div id="order_data" class="panel">
|
||||
|
||||
<h2><?php
|
||||
<h2>
|
||||
<?php
|
||||
// translators: placeholder is the ID of the subscription
|
||||
printf( esc_html_x( 'Subscription #%s details', 'edit subscription header', 'woocommerce-subscriptions' ), esc_html( $subscription->get_order_number() ) ); ?></h2>
|
||||
printf( esc_html_x( 'Subscription #%s details', 'edit subscription header', 'woocommerce-subscriptions' ), esc_html( $subscription->get_order_number() ) );
|
||||
?>
|
||||
</h2>
|
||||
|
||||
<div class="order_data_column_container">
|
||||
<div class="order_data_column">
|
||||
<h3><?php esc_html_e( 'General', 'woocommerce-subscriptions' ); ?></h3>
|
||||
|
||||
<p class="form-field form-field-wide wc-customer-user">
|
||||
<label for="customer_user"><?php esc_html_e( 'Customer:', 'woocommerce-subscriptions' ) ?> <?php
|
||||
<label for="customer_user"><?php esc_html_e( 'Customer:', 'woocommerce-subscriptions' ); ?> <?php
|
||||
if ( $subscription->get_user_id() ) {
|
||||
$args = array(
|
||||
'post_status' => 'all',
|
||||
'post_type' => 'shop_subscription',
|
||||
'_customer_user' => absint( $subscription->get_user_id() ),
|
||||
);
|
||||
printf( '<a href="%s">%s</a>',
|
||||
printf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ),
|
||||
esc_html__( 'View other subscriptions →', 'woocommerce-subscriptions' )
|
||||
);
|
||||
@@ -69,7 +78,8 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
esc_html__( 'Profile →', 'woocommerce-subscriptions' )
|
||||
);
|
||||
}
|
||||
?></label>
|
||||
?>
|
||||
</label>
|
||||
<?php
|
||||
$user_string = '';
|
||||
$user_id = '';
|
||||
@@ -78,14 +88,16 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$user_string = esc_html( $user->display_name ) . ' (#' . absint( $user->ID ) . ' – ' . esc_html( $user->user_email ) . ')';
|
||||
}
|
||||
WCS_Select2::render( array(
|
||||
WCS_Select2::render(
|
||||
array(
|
||||
'class' => 'wc-customer-search',
|
||||
'name' => 'customer_user',
|
||||
'id' => 'customer_user',
|
||||
'placeholder' => esc_attr__( 'Search for a customer…', 'woocommerce-subscriptions' ),
|
||||
'selected' => $user_string,
|
||||
'value' => $user_id,
|
||||
) );
|
||||
)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
@@ -105,31 +117,37 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
</p>
|
||||
<?php
|
||||
$parent_order = $subscription->get_parent();
|
||||
if ( $parent_order ) { ?>
|
||||
if ( $parent_order ) {
|
||||
?>
|
||||
<p class="form-field form-field-wide">
|
||||
<?php echo esc_html__( 'Parent order: ', 'woocommerce-subscriptions' ) ?>
|
||||
<a href="<?php echo esc_url( get_edit_post_link( $subscription->get_parent_id() ) ); ?>">
|
||||
<?php echo esc_html__( 'Parent order: ', 'woocommerce-subscriptions' ); ?>
|
||||
<a href="<?php echo esc_url( wcs_get_edit_post_link( $subscription->get_parent_id() ) ); ?>">
|
||||
<?php
|
||||
// translators: placeholder is an order number.
|
||||
echo sprintf( esc_html__( '#%1$s', 'woocommerce-subscriptions' ), esc_html( $parent_order->get_order_number() ) );
|
||||
?>
|
||||
</a>
|
||||
</p>
|
||||
<?php } else {
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<p class="form-field form-field-wide">
|
||||
<label for="parent-order-id"><?php esc_html_e( 'Parent order:', 'woocommerce-subscriptions' ); ?> </label>
|
||||
<?php
|
||||
WCS_Select2::render( array(
|
||||
WCS_Select2::render(
|
||||
array(
|
||||
'class' => 'wc-enhanced-select',
|
||||
'name' => 'parent-order-id',
|
||||
'id' => 'parent-order-id',
|
||||
'placeholder' => esc_attr__( 'Select an order…', 'woocommerce-subscriptions' ),
|
||||
) );
|
||||
)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php }
|
||||
do_action( 'woocommerce_admin_order_data_after_order_details', $subscription ); ?>
|
||||
<?php
|
||||
}
|
||||
do_action( 'woocommerce_admin_order_data_after_order_details', $subscription );
|
||||
?>
|
||||
|
||||
</div>
|
||||
<div class="order_data_column">
|
||||
@@ -167,12 +185,12 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( make_clickable( esc_html( $field_value ) ) ) . '</p>';
|
||||
}
|
||||
|
||||
echo '<p' . ( ( '' != $subscription->get_payment_method() ) ? ' class="' . esc_attr( $subscription->get_payment_method() ) . '"' : '' ) . '><strong>' . esc_html__( 'Payment Method', 'woocommerce-subscriptions' ) . ':</strong>' . wp_kses_post( nl2br( $subscription->get_payment_method_to_display() ) );
|
||||
echo '<p' . ( ( '' != $subscription->get_payment_method() ) ? ' class="' . esc_attr( $subscription->get_payment_method() ) . '"' : '' ) . '><strong>' . esc_html__( 'Payment Method', 'woocommerce-subscriptions' ) . ':</strong>' . wp_kses_post( nl2br( $subscription->get_payment_method_to_display() ) ); // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
||||
|
||||
// Display help tip
|
||||
if ( '' != $subscription->get_payment_method() && ! $subscription->is_manual() ) {
|
||||
if ( '' != $subscription->get_payment_method() && ! $subscription->is_manual() ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
||||
// translators: %s: gateway ID.
|
||||
echo wcs_help_tip( sprintf( _x( 'Gateway ID: [%s]', 'The gateway ID displayed on the Edit Subscriptions screen when editing payment method.', 'woocommerce-subscriptions' ), $subscription->get_payment_method() ) );
|
||||
echo wcs_help_tip( sprintf( _x( 'Gateway ID: [%s]', 'The gateway ID displayed on the Edit Subscriptions screen when editing payment method.', 'woocommerce-subscriptions' ), $subscription->get_payment_method() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
@@ -189,11 +207,18 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
if ( ! isset( $field['id'] ) ) {
|
||||
$field['id'] = '_billing_' . $key;
|
||||
}
|
||||
|
||||
switch ( $field['type'] ) {
|
||||
case 'select':
|
||||
woocommerce_wp_select( $field );
|
||||
wcs_woocommerce_wp_select( $field, $subscription );
|
||||
break;
|
||||
default:
|
||||
if ( is_callable( array( $subscription, 'get_billing_' . $key ) ) ) {
|
||||
$field['value'] = $subscription->{"get_billing_$key"}();
|
||||
} else {
|
||||
$field['value'] = $subscription->get_meta( $field['id'] );
|
||||
}
|
||||
|
||||
woocommerce_wp_text_input( $field );
|
||||
break;
|
||||
}
|
||||
@@ -260,8 +285,8 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
}
|
||||
}
|
||||
|
||||
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) {
|
||||
echo '<p><strong>' . esc_html__( 'Customer Provided Note', 'woocommerce-subscriptions' ) . ':</strong> ' . wp_kses_post( nl2br( $post->post_excerpt ) ) . '</p>';
|
||||
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $subscription->get_customer_note() ) {
|
||||
echo '<p><strong>' . esc_html__( 'Customer Provided Note', 'woocommerce-subscriptions' ) . ':</strong> ' . wp_kses_post( nl2br( $subscription->get_customer_note() ) ) . '</p>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
@@ -280,19 +305,25 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
|
||||
switch ( $field['type'] ) {
|
||||
case 'select':
|
||||
woocommerce_wp_select( $field );
|
||||
wcs_woocommerce_wp_select( $field, $subscription );
|
||||
break;
|
||||
default:
|
||||
if ( is_callable( array( $subscription, 'get_shipping_' . $key ) ) ) {
|
||||
$field['value'] = $subscription->{"get_shipping_$key"}();
|
||||
} else {
|
||||
$field['value'] = $subscription->get_meta( $field['id'] );
|
||||
}
|
||||
|
||||
woocommerce_wp_text_input( $field );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) {
|
||||
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' === get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) {
|
||||
?>
|
||||
<p class="form-field form-field-wide"><label for="excerpt"><?php esc_html_e( 'Customer Provided Note', 'woocommerce-subscriptions' ) ?>:</label>
|
||||
<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer\'s notes about the order', 'woocommerce-subscriptions' ); ?>"><?php echo wp_kses_post( $post->post_excerpt ); ?></textarea>
|
||||
<p class="form-field form-field-wide"><label for="excerpt"><?php esc_html_e( 'Customer Provided Note', 'woocommerce-subscriptions' ); ?>:</label>
|
||||
<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer\'s notes about the order', 'woocommerce-subscriptions' ); ?>"><?php echo wp_kses_post( $subscription->get_customer_note() ); ?></textarea>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
@@ -310,20 +341,26 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
* Saves the subscription data meta box.
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param WP_Post $post
|
||||
* @see woocommerce_process_shop_order_meta
|
||||
*
|
||||
* @param int $subscription_id Subscription ID.
|
||||
* @param WC_Subscription $subscription Optional. Subscription object. Default null - will be loaded from the ID.
|
||||
*/
|
||||
public static function save( $post_id, $post = null ) {
|
||||
if ( 'shop_subscription' != $post->post_type || empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) ) {
|
||||
public static function save( $subscription_id, $subscription = null ) {
|
||||
if ( ! wcs_is_subscription( $subscription_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( wc_clean( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::init_address_fields();
|
||||
|
||||
// Get subscription object.
|
||||
$subscription = wcs_get_subscription( $post_id );
|
||||
$subscription = is_a( $subscription, 'WC_Subscription' ) ? $subscription : wcs_get_subscription( $subscription_id );
|
||||
$props = array();
|
||||
|
||||
// Ensure there is an order key.
|
||||
@@ -331,7 +368,7 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
$props['order_key'] = wcs_generate_order_key();
|
||||
}
|
||||
|
||||
// Update meta
|
||||
// Update customer.
|
||||
$customer_id = isset( $_POST['customer_user'] ) ? absint( $_POST['customer_user'] ) : 0;
|
||||
if ( $customer_id !== $subscription->get_customer_id() ) {
|
||||
$props['customer_id'] = $customer_id;
|
||||
@@ -374,15 +411,16 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
$subscription->set_props( $props );
|
||||
$subscription->save();
|
||||
|
||||
// Save the linked parent order id
|
||||
// Save the linked parent order ID.
|
||||
if ( ! empty( $_POST['parent-order-id'] ) ) {
|
||||
// if the parent order to be set is a renewal order
|
||||
if ( wcs_order_contains_renewal( $_POST['parent-order-id'] ) ) {
|
||||
// remove renewal meta
|
||||
$parent = wc_get_order( $_POST['parent-order-id'] );
|
||||
$parent_order_id = wc_clean( wp_unslash( $_POST['parent-order-id'] ) );
|
||||
// If the parent order to be set is a renewal order.
|
||||
if ( wcs_order_contains_renewal( $parent_order_id ) ) {
|
||||
// remove renewal order meta flag.
|
||||
$parent = wc_get_order( $parent_order_id );
|
||||
wcs_delete_objects_property( $parent, 'subscription_renewal' );
|
||||
}
|
||||
$subscription->set_parent_id( wc_clean( $_POST['parent-order-id'] ) );
|
||||
$subscription->set_parent_id( $parent_order_id );
|
||||
// translators: %s: parent order number (linked to its details screen).
|
||||
$subscription->add_order_note( sprintf( _x( 'Subscription linked to parent order %s via admin.', 'subscription note after linking to a parent order', 'woocommerce-subscriptions' ), sprintf( '<a href="%1$s">#%2$s</a> ', esc_url( wcs_get_edit_post_link( $subscription->get_parent_id() ) ), $subscription->get_parent()->get_order_number() ) ), false, true );
|
||||
$subscription->save();
|
||||
@@ -390,11 +428,12 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
|
||||
try {
|
||||
WCS_Change_Payment_Method_Admin::save_meta( $subscription );
|
||||
$order_status = wc_clean( wp_unslash( $_POST['order_status'] ?? '' ) );
|
||||
|
||||
if ( 'cancelled' == $_POST['order_status'] ) {
|
||||
if ( 'cancelled' === $order_status ) {
|
||||
$subscription->cancel_order();
|
||||
} else {
|
||||
$subscription->update_status( $_POST['order_status'], '', true );
|
||||
$subscription->update_status( $order_status, '', true );
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
// translators: placeholder is error message from the payment gateway or subscriptions when updating the status
|
||||
@@ -408,12 +447,12 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data {
|
||||
/**
|
||||
* Fire an action after a subscription is created via the admin screen.
|
||||
*
|
||||
* @since 2.4.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.1
|
||||
* @param WC_Subscription $subscription The subscription object.
|
||||
*/
|
||||
do_action( 'woocommerce_admin_created_subscription', $subscription );
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_process_shop_subscription_meta', $post_id, $post );
|
||||
do_action( 'woocommerce_process_shop_subscription_meta', $subscription_id, $subscription );
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Display a row in the related orders table for a subscription or order
|
||||
*
|
||||
* @var array $order A WC_Order or WC_Subscription order object to display
|
||||
* @var WC_Order|WC_Subscription $order A WC_Order or WC_Subscription order object to display.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?php echo esc_url( get_edit_post_link( $order->get_id() ) ); ?>">
|
||||
<a href="<?php echo esc_url( $order->get_edit_order_url() ); ?>">
|
||||
<?php
|
||||
// translators: placeholder is an order number.
|
||||
echo sprintf( esc_html_x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), esc_html( $order->get_order_number() ) );
|
||||
@@ -29,11 +29,16 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
$t_time = $order->get_date_created()->date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
|
||||
$date_to_display = ucfirst( wcs_get_human_time_diff( $date_created->getTimestamp() ) );
|
||||
} else {
|
||||
$t_time = $date_to_display = __( 'Unpublished', 'woocommerce-subscriptions' );
|
||||
$t_time = __( 'Unpublished', 'woocommerce-subscriptions' );
|
||||
$date_to_display = $t_time;
|
||||
}
|
||||
|
||||
if ( ! wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
// Backwards compatibility for third-parties using the generic WP post time filter.
|
||||
// Only apply this filter if HPOS is not enabled, as the filter is not compatible with HPOS.
|
||||
$date_to_display = apply_filters( 'post_date_column_time', $date_to_display, get_post( $order->get_id() ) );
|
||||
}
|
||||
|
||||
?>
|
||||
<abbr title="<?php echo esc_attr( $t_time ); ?>">
|
||||
<?php echo esc_html( apply_filters( 'wc_subscriptions_related_order_date_column', $date_to_display, $order ) ); ?>
|
||||
|
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Display the related orders for a subscription or order
|
||||
* Display the related orders for a subscription or order.
|
||||
*
|
||||
* @var object $post The primitive post object that is being displayed (as an order or subscription)
|
||||
* @var WC_Order|WC_Subscription $order The order that is being displayed.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -22,7 +23,31 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php do_action( 'woocommerce_subscriptions_related_orders_meta_box_rows', $post ); ?>
|
||||
<?php
|
||||
if ( has_action( 'woocommerce_subscriptions_related_orders_meta_box_rows' ) ) {
|
||||
wcs_deprecated_hook( 'woocommerce_subscriptions_related_orders_meta_box_rows', 'subscriptions-core 5.1.0', 'wcs_related_orders_meta_box_rows' );
|
||||
|
||||
/**
|
||||
* Renders renewal order rows in the Related Orders table.
|
||||
*
|
||||
* This action is deprecated in favour of 'wcs_related_orders_meta_box_rows'.
|
||||
*
|
||||
* @deprecated subscriptions-core 5.1.0
|
||||
*
|
||||
* @param WC_Post $post The order post object.
|
||||
*/
|
||||
do_action( 'woocommerce_subscriptions_related_orders_meta_box_rows', $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders renewal order rows in the Related Orders table.
|
||||
*
|
||||
* @since subscriptions-core 5.1.0
|
||||
*
|
||||
* @param WC_Order|WC_Subscription $order The order or subscriptions that is being displayed.
|
||||
*/
|
||||
do_action( 'wcs_related_orders_meta_box_rows', $order );
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@@ -14,27 +14,30 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
<div id="billing-schedule">
|
||||
<?php if ( $the_subscription->can_date_be_updated( 'next_payment' ) ) : ?>
|
||||
<div class="billing-schedule-edit wcs-date-input"><?php
|
||||
<div class="billing-schedule-edit wcs-date-input">
|
||||
<?php
|
||||
// Subscription Period Interval
|
||||
echo woocommerce_wp_select(
|
||||
wcs_woocommerce_wp_select(
|
||||
array(
|
||||
'id' => '_billing_interval',
|
||||
'class' => 'billing_interval',
|
||||
'label' => __( 'Payment:', 'woocommerce-subscriptions' ),
|
||||
'value' => $the_subscription->get_billing_interval(),
|
||||
'options' => wcs_get_subscription_period_interval_strings(),
|
||||
)
|
||||
),
|
||||
$the_subscription
|
||||
);
|
||||
|
||||
// Billing Period
|
||||
echo woocommerce_wp_select(
|
||||
wcs_woocommerce_wp_select(
|
||||
array(
|
||||
'id' => '_billing_period',
|
||||
'class' => 'billing_period',
|
||||
'label' => __( 'Billing Period', 'woocommerce-subscriptions' ),
|
||||
'value' => $the_subscription->get_billing_period(),
|
||||
'options' => wcs_get_subscription_period_strings(),
|
||||
)
|
||||
),
|
||||
$the_subscription
|
||||
);
|
||||
?>
|
||||
<input type="hidden" name="wcs-lengths" id="wcs-lengths" data-subscription_lengths="<?php echo esc_attr( wcs_json_encode( wcs_get_subscription_ranges() ) ); ?>">
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* @author Prospress
|
||||
* @category Core
|
||||
* @package WooCommerce Subscriptions/Functions
|
||||
* @version 2.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* Store a message to display via @see wcs_display_admin_notices().
|
||||
*
|
||||
* @param string The message to display
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
function wcs_add_admin_notice( $message, $notice_type = 'success' ) {
|
||||
|
||||
@@ -36,7 +36,7 @@ function wcs_add_admin_notice( $message, $notice_type = 'success' ) {
|
||||
*
|
||||
* This method is also hooked to 'admin_notices' to display notices there.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
function wcs_display_admin_notices( $clear = true ) {
|
||||
|
||||
@@ -64,7 +64,7 @@ add_action( 'admin_notices', 'wcs_display_admin_notices' );
|
||||
/**
|
||||
* Delete any admin notices we stored for display later.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
function wcs_clear_admin_notices() {
|
||||
delete_transient( '_wcs_admin_notices' );
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* @class WC_Product_Subscription
|
||||
* @package WooCommerce Subscriptions
|
||||
* @category Class
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Product_Subscription
|
||||
* @category Class
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @class WC_Product_Variable_Subscription
|
||||
* @package WooCommerce Subscriptions
|
||||
* @category Class
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@@ -183,7 +183,7 @@ class WC_Product_Variable_Subscription extends WC_Product_Variable {
|
||||
*
|
||||
* @param array $min_and_max_data The min and max variation data returned by @see wcs_get_min_max_variation_data(). Optional.
|
||||
* @param array $variation_ids The child variation IDs. Optional. By default this value be generated by @see WC_Product_Variable->get_visible_children().
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function set_min_and_max_variation_data( $min_and_max_data = array(), $variation_ids = array() ) {
|
||||
|
||||
@@ -210,7 +210,7 @@ class WC_Product_Variable_Subscription extends WC_Product_Variable {
|
||||
*
|
||||
* @param array $variation_ids An array of variation IDs.
|
||||
* @return array The variable product's min and max variation data.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public function get_min_and_max_variation_data( $variation_ids ) {
|
||||
$variation_ids_hash = $this->get_variation_ids_hash( $variation_ids );
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author Prospress
|
||||
* @category Class
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
|
||||
class WC_Subscription_Item_Coupon_Pending_Switch extends WC_Order_Item_Coupon {
|
||||
@@ -16,7 +16,7 @@ class WC_Subscription_Item_Coupon_Pending_Switch extends WC_Order_Item_Coupon {
|
||||
* Get item type.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function get_type() {
|
||||
return 'coupon_pending_switch';
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author Prospress
|
||||
* @category Class
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
|
||||
class WC_Subscription_Item_Fee_Pending_Switch extends WC_Order_Item_Fee {
|
||||
@@ -16,7 +16,7 @@ class WC_Subscription_Item_Fee_Pending_Switch extends WC_Order_Item_Fee {
|
||||
* Get item type.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function get_type() {
|
||||
return 'fee_pending_switch';
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author Prospress
|
||||
* @category Class
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
|
||||
class WC_Subscription_Line_Item_Removed extends WC_Order_Item_Product {
|
||||
@@ -16,7 +16,7 @@ class WC_Subscription_Line_Item_Removed extends WC_Order_Item_Product {
|
||||
* Get item type.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function get_type() {
|
||||
return 'line_item_removed';
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @author Prospress
|
||||
* @category Class
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
|
||||
class WC_Subscription_Line_Item_Switched extends WC_Order_Item_Product {
|
||||
@@ -16,7 +16,7 @@ class WC_Subscription_Line_Item_Switched extends WC_Order_Item_Product {
|
||||
* Get item type.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function get_type() {
|
||||
return 'line_item_switched';
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* from WC_Order that don't exist in WC_Abstract_Order (which would seem the more appropriate choice)
|
||||
*
|
||||
* @class WC_Subscription
|
||||
* @version 2.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @package WooCommerce Subscriptions/Classes
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
@@ -93,11 +93,14 @@ class WC_Subscription extends WC_Order {
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize the subscription object.
|
||||
* Initializes a specific subscription if the ID is passed, otherwise a new and empty instance of a subscription.
|
||||
*
|
||||
* @param int|WC_Subscription $subscription
|
||||
* This class should NOT be instantiated, instead the functions wcs_create_subscription() and wcs_get_subscription()
|
||||
* should be used.
|
||||
*
|
||||
* @param int|WC_Subscription $subscription Subscription to read.
|
||||
*/
|
||||
public function __construct( $subscription ) {
|
||||
public function __construct( $subscription = 0 ) {
|
||||
|
||||
// Add subscription date types as extra subscription data.
|
||||
foreach ( wcs_get_subscription_date_types() as $date_type => $date_name ) {
|
||||
@@ -253,7 +256,7 @@ class WC_Subscription extends WC_Order {
|
||||
* @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
|
||||
* @param int $user_id The ID of the user who owns the subscriptions. Although this parameter is optional, if you have the User ID you should pass it to improve performance.
|
||||
* @return bool True if the subscription has an unpaid renewal order, false if the subscription has no unpaid renewal orders.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function needs_payment() {
|
||||
|
||||
@@ -295,7 +298,7 @@ class WC_Subscription extends WC_Order {
|
||||
* 'subscription_cancellation'
|
||||
* 'subscription_date_changes'
|
||||
* 'subscription_amount_changes'
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function payment_method_supports( $payment_gateway_feature ) {
|
||||
|
||||
@@ -631,28 +634,32 @@ class WC_Subscription extends WC_Order {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the WC Order get_status function for draft and auto-draft statuses for a subscription
|
||||
* so that it will return a pending status instead of draft / auto-draft.
|
||||
* Sets the subscription status.
|
||||
*
|
||||
* @since 2.0
|
||||
* @return string Status
|
||||
* Overrides the WC Order set_status() function to handle 'draft' and 'auto-draft' statuses for a subscription.
|
||||
*
|
||||
* 'draft' and 'auto-draft' statuses are WP statuses applied to the post when a subscription is created via admin. When
|
||||
* a subscription is being read from the database, and the status is set to the post's 'draft' or 'auto-draft' status, the
|
||||
* subscription status is treated as the default status - 'pending'.
|
||||
*
|
||||
* @since 5.1.0
|
||||
*
|
||||
* @param string $new_status The new status.
|
||||
* @param string $note Optional. The note to add to the subscription.
|
||||
* @param bool $manual Optional. Is the status change triggered manually? Default is false.
|
||||
*/
|
||||
public function get_status( $context = 'view' ) {
|
||||
|
||||
if ( in_array( get_post_status( $this->get_id() ), array( 'draft', 'auto-draft' ) ) ) {
|
||||
$this->post_status = 'wc-pending';
|
||||
$status = apply_filters( 'woocommerce_order_get_status', 'pending', $this );
|
||||
} else {
|
||||
$status = parent::get_status();
|
||||
public function set_status( $new_status, $note = '', $manual_update = false ) {
|
||||
if ( ! $this->object_read && in_array( $new_status, [ 'draft', 'auto-draft' ], true ) ) {
|
||||
$new_status = apply_filters( 'woocommerce_default_subscription_status', 'pending' );
|
||||
}
|
||||
|
||||
return $status;
|
||||
return parent::set_status( $new_status, $note, $manual_update );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid order status keys
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @return array details of change
|
||||
*/
|
||||
public function get_valid_statuses() {
|
||||
@@ -664,7 +671,7 @@ class WC_Subscription extends WC_Order {
|
||||
* it stores it with the prefix. This makes it hard to use the same filters / status names in both WC's methods AND WP's
|
||||
* get_posts functions. This function bridges that gap and returns the prefixed versions of completed statuses.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @return array By default: wc-processing and wc-completed
|
||||
*/
|
||||
public function get_paid_order_statuses() {
|
||||
@@ -695,7 +702,7 @@ class WC_Subscription extends WC_Order {
|
||||
* @param string $payment_type Type of count (completed|refunded|net). Optional. Default completed.
|
||||
* @param string|array $order_types Type of order relation(s) to count. Optional. Default array(parent,renewal).
|
||||
* @return integer Count.
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function get_payment_count( $payment_type = 'completed', $order_types = '' ) {
|
||||
|
||||
@@ -785,7 +792,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* Failed orders are the number of orders that have wc-failed as the status
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_failed_payment_count() {
|
||||
|
||||
@@ -807,7 +814,7 @@ class WC_Subscription extends WC_Order {
|
||||
* otherwise it will be the sum of the sign up fee and price per period.
|
||||
*
|
||||
* @return float The total initial amount charged when the subscription product in the order was first purchased, if any.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_total_initial_payment() {
|
||||
$initial_total = ( $parent_order = $this->get_parent() ) ? $parent_order->get_total() : 0;
|
||||
@@ -818,7 +825,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Get billing period.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function get_billing_period( $context = 'view' ) {
|
||||
return $this->get_prop( 'billing_period', $context );
|
||||
@@ -828,7 +835,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Get billing interval.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function get_billing_interval( $context = 'view' ) {
|
||||
return $this->get_prop( 'billing_interval', $context );
|
||||
@@ -838,7 +845,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Get trial period.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function get_trial_period( $context = 'view' ) {
|
||||
return $this->get_prop( 'trial_period', $context );
|
||||
@@ -848,7 +855,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Get suspension count.
|
||||
*
|
||||
* @return int
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function get_suspension_count( $context = 'view' ) {
|
||||
return $this->get_prop( 'suspension_count', $context );
|
||||
@@ -859,7 +866,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function get_requires_manual_renewal( $context = 'view' ) {
|
||||
return $this->get_prop( 'requires_manual_renewal', $context );
|
||||
@@ -868,7 +875,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Get the switch data.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_switch_data( $context = 'view' ) {
|
||||
@@ -889,7 +896,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Set billing period.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_billing_period( $value ) {
|
||||
@@ -899,7 +906,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Set billing interval.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param int $value
|
||||
*/
|
||||
public function set_billing_interval( $value ) {
|
||||
@@ -910,7 +917,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Set trial period.
|
||||
*
|
||||
* @param string $value
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function set_trial_period( $value ) {
|
||||
$this->set_prop( 'trial_period', $value );
|
||||
@@ -919,18 +926,33 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Set suspension count.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param int $value
|
||||
*/
|
||||
public function set_suspension_count( $value ) {
|
||||
$this->set_prop( 'suspension_count', absint( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set schedule start date.
|
||||
*
|
||||
* This function should not be used. It only exists to support setting the start date on subscription creation without
|
||||
* having to call update_dates() which results in a save.
|
||||
*
|
||||
* The more aptly named set_schedule_start() cannot exist because then WC core thinks the _schedule_start meta is an
|
||||
* internal meta key and throws errors.
|
||||
*
|
||||
* @param string $schedule_start
|
||||
*/
|
||||
public function set_start_date( $schedule_start ) {
|
||||
$this->set_prop( 'schedule_start', $schedule_start );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parent order ID. We don't use WC_Abstract_Order::set_parent_id() because we want to allow false
|
||||
* parent IDs, like 0.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param int $value
|
||||
*/
|
||||
public function set_parent_id( $value ) {
|
||||
@@ -945,7 +967,7 @@ class WC_Subscription extends WC_Order {
|
||||
* (which means it doesn't require manual renewal), but we want to consistently use it via get/set as a boolean,
|
||||
* for sanity's sake.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param bool $value
|
||||
*/
|
||||
public function set_requires_manual_renewal( $value ) {
|
||||
@@ -964,7 +986,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Set the switch data on the subscription.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function set_switch_data( $value ) {
|
||||
$this->set_prop( 'switch_data', $value );
|
||||
@@ -973,7 +995,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Set the flag about whether the cancelled email has been sent or not.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public function set_cancelled_email_sent( $value ) {
|
||||
$this->set_prop( 'cancelled_email_sent', $value );
|
||||
@@ -1130,7 +1152,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Get a certain date type for the most recent order on the subscription with that date type,
|
||||
* or the last order, if the order type is specified as 'last'.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param string $date_type Any valid WC 3.0 date property, including 'date_paid', 'date_completed', 'date_created', or 'date_modified'
|
||||
* @param string $order_type The type of orders to return, can be 'last', 'parent', 'switch', 'renewal' or 'any'. Default 'any'. Use 'last' to only check the last order.
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
@@ -1159,7 +1181,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Set a certain date type for the last order on the subscription.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param string $date_type One of 'date_paid', 'date_completed', 'date_modified', or 'date_created'.
|
||||
*/
|
||||
protected function set_last_order_date( $date_type, $date = null ) {
|
||||
@@ -1505,7 +1527,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Sometimes it's necessary to only save changes to date properties, for example, when you
|
||||
* don't want status transitions to be triggered by a full object @see $this->save().
|
||||
*
|
||||
* @since 2.2.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.6
|
||||
*/
|
||||
public function save_dates() {
|
||||
if ( $this->data_store && $this->get_id() ) {
|
||||
@@ -1769,7 +1791,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* When a payment fails, either for the original purchase or a renewal payment, this function processes it.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function payment_failed( $new_status = 'on-hold' ) {
|
||||
|
||||
@@ -1806,7 +1828,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Get order refunds
|
||||
*
|
||||
* @since 2.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2
|
||||
* @return array
|
||||
*/
|
||||
public function get_refunds() {
|
||||
@@ -1816,7 +1838,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Get amount already refunded
|
||||
*
|
||||
* @since 2.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2
|
||||
* @return int|float
|
||||
*/
|
||||
public function get_total_refunded() {
|
||||
@@ -1877,7 +1899,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Extracting the query from get_related_orders and get_last_order so it can be moved in a cached
|
||||
* value.
|
||||
*
|
||||
* @deprecated 2.3.0 Moved to WCS_Subscription_Data_Store_CPT::get_related_order_ids() to separate cache logic from subscription instances and to avoid confusion from the misnomer on this method's name - it gets renewal orders, not related orders - and its ambiguity - it runs a query and returns order IDs, it does not return a SQL query string or order objects.
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0, Moved to WCS_Subscription_Data_Store_CPT::get_related_order_ids() to separate cache logic from subscription instances and to avoid confusion from the misnomer on this method's name - it gets renewal orders, not related orders - and its ambiguity - it runs a query and returns order IDs, it does not return a SQL query string or order objects.
|
||||
* @return array
|
||||
*/
|
||||
public function get_related_orders_query( $subscription_id ) {
|
||||
@@ -1890,7 +1912,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* @param string $return_fields The columns to return, either 'all' or 'ids'
|
||||
* @param array|string $order_types Can include 'any', 'parent', 'renewal', 'resubscribe' and/or 'switch'. Custom types possible via the 'woocommerce_subscription_related_orders' filter. Defaults to array( 'parent', 'renewal', 'switch' ).
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_related_orders( $return_fields = 'ids', $order_types = array( 'parent', 'renewal', 'switch' ) ) {
|
||||
@@ -1929,7 +1951,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* @param string $order_type Can include 'any', 'parent', 'renewal', 'resubscribe' and/or 'switch'. Defaults to 'any'.
|
||||
* @return array List of related order IDs.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
protected function get_related_order_ids( $order_type = 'any' ) {
|
||||
|
||||
@@ -1956,7 +1978,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* @param string $return_fields The columns to return, either 'all' or 'ids'
|
||||
* @param array $order_types Can include any combination of 'parent', 'renewal', 'switch' or 'any' which will return the latest renewal order of any type. Defaults to 'parent' and 'renewal'.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_last_order( $return_fields = 'ids', $order_types = array( 'parent', 'renewal' ) ) {
|
||||
|
||||
@@ -1999,7 +2021,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* @param string $context The context the payment method is being displayed in. Can be 'admin' or 'customer'. Default 'admin'.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_payment_method_to_display( $context = 'admin' ) {
|
||||
|
||||
@@ -2037,7 +2059,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Save new payment method for a subscription
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.0
|
||||
*
|
||||
* @throws InvalidArgumentException An exception is thrown via @see WC_Subscription::set_payment_method_meta() if the payment meta passed is invalid.
|
||||
* @param WC_Payment_Gateway|string $payment_method
|
||||
@@ -2092,7 +2114,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Save payment method meta data for the Subscription
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.0
|
||||
*
|
||||
* @throws InvalidArgumentException An exception if the payment meta variable isn't an array.
|
||||
*
|
||||
@@ -2115,7 +2137,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Now uses the URL /my-account/view-subscription/{post-id} when viewing a subscription from the My Account Page.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_view_order_url() {
|
||||
$view_subscription_url = wc_get_endpoint_url( 'view-subscription', $this->get_id(), wc_get_page_permalink( 'myaccount' ) );
|
||||
@@ -2163,7 +2185,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Check if the subscription has a payment gateway.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
* @return bool
|
||||
*/
|
||||
public function has_payment_gateway() {
|
||||
@@ -2174,7 +2196,7 @@ class WC_Subscription extends WC_Order {
|
||||
* The total sign-up fee for the subscription if any.
|
||||
*
|
||||
* @return int
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_sign_up_fee() {
|
||||
|
||||
@@ -2200,7 +2222,7 @@ class WC_Subscription extends WC_Order {
|
||||
* @param array|int Either an order item (in the array format returned by self::get_items()) or the ID of an order item.
|
||||
* @param string $tax_inclusive_or_exclusive Whether or not to adjust sign up fee if prices inc tax - ensures that the sign up fee paid amount includes the paid tax if inc
|
||||
* @return bool
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function get_items_sign_up_fee( $line_item, $tax_inclusive_or_exclusive = 'exclusive_of_tax' ) {
|
||||
|
||||
@@ -2269,7 +2291,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Determine if the subscription is for one payment only.
|
||||
*
|
||||
* @return bool whether the subscription is for only one payment
|
||||
* @since 2.0.17
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.17
|
||||
*/
|
||||
public function is_one_payment() {
|
||||
|
||||
@@ -2455,7 +2477,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Add a product line item to the subscription.
|
||||
*
|
||||
* @since 2.1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.4
|
||||
* @param WC_Product product
|
||||
* @param int line item quantity.
|
||||
* @param array args
|
||||
@@ -2477,7 +2499,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* The allowed dates includes both subscription date dates, and date types for related orders, like 'last_order_date_created'.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @return array
|
||||
*/
|
||||
protected function get_valid_date_types() {
|
||||
@@ -2505,7 +2527,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Generates a URL to add or change the subscription's payment method from the my account page.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
public function get_change_payment_method_url() {
|
||||
$change_payment_method_url = wc_get_endpoint_url( 'subscription-payment-method', $this->get_id(), wc_get_page_permalink( 'myaccount' ) );
|
||||
@@ -2514,7 +2536,7 @@ class WC_Subscription extends WC_Order {
|
||||
|
||||
/* Get the subscription's payment method meta.
|
||||
*
|
||||
* @since 2.4.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.3
|
||||
* @return array The subscription's payment meta in the format returned by the woocommerce_subscription_payment_meta filter.
|
||||
*/
|
||||
public function get_payment_method_meta() {
|
||||
@@ -2538,7 +2560,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Avoid running the expensive get_date_paid() query on related orders.
|
||||
*
|
||||
* @since 2.2.19
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.19
|
||||
*/
|
||||
public function maybe_set_date_paid() {
|
||||
return null;
|
||||
@@ -2547,7 +2569,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Avoid running the expensive get_date_completed() query on related orders.
|
||||
*
|
||||
* @since 2.2.19
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.19
|
||||
*/
|
||||
protected function maybe_set_date_completed() {
|
||||
return null;
|
||||
@@ -2596,7 +2618,7 @@ class WC_Subscription extends WC_Order {
|
||||
* Update the internal tally of suspensions on this subscription since the last payment.
|
||||
*
|
||||
* @return int The count of suspensions
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public function update_suspension_count( $new_count ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.2.0', __CLASS__ . '::set_suspension_count(), because WooCommerce 3.0+ now uses setters' );
|
||||
@@ -2629,8 +2651,8 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* For backward compatibility we have to use the date created here, see: https://github.com/Prospress/woocommerce-subscriptions/issues/1943
|
||||
*
|
||||
* @deprecated 2.2.0
|
||||
* @since 2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
protected function get_last_payment_date() {
|
||||
wcs_deprecated_function( __METHOD__, '2.2.0', __CLASS__ . '::get_date( "last_order_date_created" )' );
|
||||
@@ -2640,7 +2662,7 @@ class WC_Subscription extends WC_Order {
|
||||
/**
|
||||
* Updated both the _paid_date and post date GMT with the WooCommerce < 3.0 date storage structures.
|
||||
*
|
||||
* @deprecated 2.2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
* @param string $datetime A MySQL formatted date/time string in GMT/UTC timezone.
|
||||
*/
|
||||
protected function update_last_payment_date( $datetime ) {
|
||||
@@ -2668,7 +2690,7 @@ class WC_Subscription extends WC_Order {
|
||||
* subscription was created as a result of a purchase from the front end rather than
|
||||
* manually by the store manager).
|
||||
*
|
||||
* @deprecated 2.6.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public function get_completed_payment_count() {
|
||||
wcs_deprecated_function( __METHOD__, '2.6.0', __CLASS__ . '::get_payment_count()' );
|
||||
@@ -2684,7 +2706,7 @@ class WC_Subscription extends WC_Order {
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @deprecated 2.6.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
protected function apply_deprecated_completed_payment_count_filter( $count ) {
|
||||
$deprecated_filter_hook = 'woocommerce_subscription_payment_completed_count';
|
||||
|
@@ -8,14 +8,14 @@
|
||||
* @subpackage WC_Subscriptions_Addresses
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
class WC_Subscriptions_Addresses {
|
||||
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -39,7 +39,7 @@ class WC_Subscriptions_Addresses {
|
||||
* @param int|WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object.
|
||||
* @param int $user_id The ID of a user.
|
||||
* @return bool Whether the user can edit the subscription's address.
|
||||
* @since 3.0.15
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.15
|
||||
*/
|
||||
private static function can_user_edit_subscription_address( $subscription, $user_id = 0 ) {
|
||||
$subscription = wcs_get_subscription( $subscription );
|
||||
@@ -52,15 +52,14 @@ class WC_Subscriptions_Addresses {
|
||||
* Add a "Change Shipping Address" button to the "My Subscriptions" table for those subscriptions
|
||||
* which require shipping.
|
||||
*
|
||||
* @param array $all_actions The $subscription_id => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
|
||||
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
|
||||
* @since 1.3
|
||||
* @param array $actions The $subscription_id => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
|
||||
* @param \WC_Subscription $subscription the Subscription object that is being viewed.
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function add_edit_address_subscription_action( $actions, $subscription ) {
|
||||
|
||||
if ( $subscription->needs_shipping_address() && $subscription->has_status( array( 'active', 'on-hold' ) ) ) {
|
||||
$actions['change_address'] = array(
|
||||
'url' => add_query_arg( array( 'subscription' => $subscription->get_id() ), wc_get_endpoint_url( 'edit-address', 'shipping' ) ),
|
||||
'url' => esc_url( add_query_arg( array( 'subscription' => $subscription->get_id() ), wc_get_endpoint_url( 'edit-address', 'shipping' ) ) ),
|
||||
'name' => __( 'Change address', 'woocommerce-subscriptions' ),
|
||||
);
|
||||
}
|
||||
@@ -71,7 +70,7 @@ class WC_Subscriptions_Addresses {
|
||||
/**
|
||||
* Redirects to "My Account" when attempting to edit the address on a subscription that doesn't belong to the user.
|
||||
*
|
||||
* @since 3.0.15
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.15
|
||||
*/
|
||||
public static function maybe_restrict_edit_address_endpoint() {
|
||||
if ( ! is_wc_endpoint_url() || 'edit-address' !== WC()->query->get_current_endpoint() || ! isset( $_GET['subscription'] ) ) {
|
||||
@@ -93,7 +92,7 @@ class WC_Subscriptions_Addresses {
|
||||
* also update the address on their active subscriptions. If editing a single subscription's address, the
|
||||
* subscription key is added as a hidden field.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function maybe_add_edit_address_checkbox() {
|
||||
global $wp;
|
||||
@@ -140,7 +139,7 @@ class WC_Subscriptions_Addresses {
|
||||
* the addresses on the initial order for each subscription.
|
||||
*
|
||||
* @param int $user_id The ID of a user who own's the subscription (and address)
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function maybe_update_subscription_addresses( $user_id, $address_type ) {
|
||||
|
||||
@@ -159,21 +158,21 @@ class WC_Subscriptions_Addresses {
|
||||
}
|
||||
|
||||
if ( isset( $_POST['update_all_subscriptions_addresses'] ) ) {
|
||||
|
||||
$users_subscriptions = wcs_get_users_subscriptions( $user_id );
|
||||
|
||||
foreach ( $users_subscriptions as $subscription ) {
|
||||
if ( $subscription->has_status( array( 'active', 'on-hold' ) ) ) {
|
||||
$subscription->set_address( $address, $address_type );
|
||||
wcs_set_order_address( $subscription, $address, $address_type );
|
||||
$subscription->save();
|
||||
}
|
||||
}
|
||||
} elseif ( isset( $_POST['update_subscription_address'] ) ) {
|
||||
|
||||
$subscription = wcs_get_subscription( absint( $_POST['update_subscription_address'] ) );
|
||||
|
||||
if ( $subscription && self::can_user_edit_subscription_address( $subscription->get_id() ) ) {
|
||||
// Update the address only if the user actually owns the subscription
|
||||
$subscription->set_address( $address, $address_type );
|
||||
if ( $subscription && self::can_user_edit_subscription_address( $subscription->get_id() ) ) {
|
||||
wcs_set_order_address( $subscription, $address, $address_type );
|
||||
$subscription->save();
|
||||
|
||||
wp_safe_redirect( $subscription->get_view_order_url() );
|
||||
exit();
|
||||
@@ -185,7 +184,7 @@ class WC_Subscriptions_Addresses {
|
||||
* Prepopulate the address fields on a subscription item
|
||||
*
|
||||
* @param array $address A WooCommerce address array
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function maybe_populate_subscription_addresses( $address ) {
|
||||
$subscription_id = isset( $_GET['subscription'] ) ? absint( $_GET['subscription'] ) : 0;
|
||||
@@ -211,7 +210,7 @@ class WC_Subscriptions_Addresses {
|
||||
*
|
||||
* @param array $subscription A WooCommerce Subscription array
|
||||
* @param array $address_fields Locale aware address fields of the form returned by WC_Countries->get_address_fields() for a given country
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function maybe_update_order_address( $subscription, $address_fields ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Order::set_address() or WC_Subscription::set_address()' );
|
||||
@@ -222,7 +221,7 @@ class WC_Subscriptions_Addresses {
|
||||
*
|
||||
* @param array $crumbs
|
||||
* @return array
|
||||
* @since 2.4.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.2
|
||||
*/
|
||||
public static function change_addresses_breadcrumb( $crumbs ) {
|
||||
if ( isset( $_GET['subscription'] ) && is_wc_endpoint_url() && 'edit-address' === WC()->query->get_current_endpoint() ) {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Cart_Validator
|
||||
* @category Class
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
class WC_Subscriptions_Cart_Validator {
|
||||
|
||||
@@ -28,7 +28,7 @@ class WC_Subscriptions_Cart_Validator {
|
||||
*
|
||||
* If multiple purchase flag is set, allow them to be added at the same time.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function maybe_empty_cart( $valid, $product_id, $quantity, $variation_id = '', $variations = array() ) {
|
||||
$is_subscription = WC_Subscriptions_Product::is_subscription( $product_id );
|
||||
@@ -80,7 +80,7 @@ class WC_Subscriptions_Cart_Validator {
|
||||
* @param $cart WC_Cart the one we got from session
|
||||
* @return WC_Cart $cart
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function validate_cart_contents_for_mixed_checkout( $cart ) {
|
||||
|
||||
@@ -119,7 +119,7 @@ class WC_Subscriptions_Cart_Validator {
|
||||
/**
|
||||
* Don't allow new subscription products to be added to the cart if it contains a subscription renewal already.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function can_add_subscription_product_to_cart( $can_add, $product_id, $quantity, $variation_id = '', $variations = array(), $item_data = array() ) {
|
||||
|
||||
@@ -140,7 +140,7 @@ class WC_Subscriptions_Cart_Validator {
|
||||
* purcahses disabled, the cart already contains products and the customer adds a new item or logs in
|
||||
* causing a cart merge.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param array $fragments The add to cart AJAX args.
|
||||
* @return array $fragments
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* @subpackage WC_Subscriptions_Cart
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
class WC_Subscriptions_Cart {
|
||||
|
||||
@@ -22,42 +22,35 @@ class WC_Subscriptions_Cart {
|
||||
* - 'recurring_total' used to calculate the totals for the recurring amount when the recurring amount differs to to 'combined_total' because of coupons or sign-up fees.
|
||||
* - 'free_trial_total' used to calculate the initial total when there is a free trial period and no sign-up fee. Different to 'combined_total' because shipping is not charged up-front when there is a free trial.
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
private static $calculation_type = 'none';
|
||||
|
||||
/**
|
||||
* An internal pointer to the current recurring cart calculation (if any)
|
||||
*
|
||||
* @since 2.0.12
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.12
|
||||
*/
|
||||
private static $recurring_cart_key = 'none';
|
||||
|
||||
/**
|
||||
* A cache of the calculated recurring shipping packages
|
||||
*
|
||||
* @since 2.0.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.13
|
||||
*/
|
||||
private static $recurring_shipping_packages = array();
|
||||
|
||||
/**
|
||||
* A cache of the calculated shipping package rates
|
||||
*
|
||||
* @since 2.0.18
|
||||
*/
|
||||
private static $shipping_rates = array();
|
||||
|
||||
/**
|
||||
* A cache of the current recurring cart being calculated
|
||||
*
|
||||
* @since 2.0.20
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.20
|
||||
*/
|
||||
private static $cached_recurring_cart = null;
|
||||
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function init() {
|
||||
// Make sure WC calculates total on sign up fee + price per period, and keep a record of the price per period
|
||||
@@ -96,9 +89,6 @@ class WC_Subscriptions_Cart {
|
||||
// Make sure we use our recurring shipping method for recurring shipping calculations not the default method
|
||||
add_filter( 'woocommerce_shipping_chosen_method', array( __CLASS__, 'set_chosen_shipping_method' ), 10, 2 );
|
||||
|
||||
// Cache package rates. Hook in early to ensure we get a full set of rates.
|
||||
add_filter( 'woocommerce_package_rates', __CLASS__ . '::cache_package_rates', 1, 2 );
|
||||
|
||||
// When WooCommerce calculates rates for a recurring shipping package, make sure there is a different set of rates
|
||||
add_filter( 'woocommerce_shipping_package_name', __CLASS__ . '::change_initial_shipping_package_name', 1, 3 );
|
||||
|
||||
@@ -128,7 +118,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Attach dependant callbacks.
|
||||
*
|
||||
* @since 2.5.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.6
|
||||
*/
|
||||
public static function attach_dependant_hooks() {
|
||||
// WooCommerce determines if free shipping is available using the WC->cart total and coupons, we need to recalculate its availability when obtaining shipping methods for a recurring cart
|
||||
@@ -145,7 +135,7 @@ class WC_Subscriptions_Cart {
|
||||
* This function is hooked to "woocommerce_before_calculate_totals" so that WC will calculate a subscription
|
||||
* product's total based on the total of it's price per period and sign up fee (if any).
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function add_calculation_price_filter() {
|
||||
WC()->cart->recurring_carts = array();
|
||||
@@ -164,7 +154,7 @@ class WC_Subscriptions_Cart {
|
||||
* Removes the "set_subscription_prices_for_calculation" filter from the WC Product's woocommerce_get_price hook once
|
||||
* calculations are complete.
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function remove_calculation_price_filter() {
|
||||
remove_filter( 'woocommerce_product_get_price', __CLASS__ . '::set_subscription_prices_for_calculation', 100 );
|
||||
@@ -201,7 +191,7 @@ class WC_Subscriptions_Cart {
|
||||
* If there are subscriptions in the cart and the product is not a subscription, then
|
||||
* set the recurring total to 0.
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function set_subscription_prices_for_calculation( $price, $product ) {
|
||||
|
||||
@@ -249,8 +239,8 @@ class WC_Subscriptions_Cart {
|
||||
* product prices to see whether they include sign-up fees and/or free trial periods and then recalculates the
|
||||
* appropriate totals by using the @see self::$calculation_type flag and cloning the cart to run @see WC_Cart::calculate_totals()
|
||||
*
|
||||
* @since 1.3.5
|
||||
* @version 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function calculate_subscription_totals( $total, $cart ) {
|
||||
if ( ! self::cart_contains_subscription() && ! wcs_cart_contains_resubscribe() ) { // cart doesn't contain subscription
|
||||
@@ -355,7 +345,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Allow third-parties to override whether the fees will be removed from the initial order cart.
|
||||
*
|
||||
* @since 2.4.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.3
|
||||
* @param bool $remove_fees_from_cart Whether the fees will be removed. By default fees will be removed if there is no signup fee and all cart items have a trial.
|
||||
* @param WC_Cart $cart The standard WC cart object.
|
||||
* @param array $recurring_carts All the recurring cart objects.
|
||||
@@ -402,7 +392,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* @internal self::all_cart_items_have_free_trial() is false if non-subscription products are in the cart.
|
||||
*
|
||||
* @since 1.5.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.4
|
||||
*/
|
||||
public static function charge_shipping_up_front() {
|
||||
return apply_filters( 'woocommerce_subscriptions_cart_shipping_up_front', ! self::all_cart_items_have_free_trial() );
|
||||
@@ -411,7 +401,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* The cart needs shipping only if it needs shipping up front and/or for recurring items.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @param boolean $needs_shipping True if shipping is needed for the cart.
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -460,7 +450,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* @param $cart_item_key string The key for a cart item about to be removed from the cart.
|
||||
* @return null
|
||||
* @since 2.0.15
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.15
|
||||
*/
|
||||
public static function maybe_reset_chosen_shipping_methods( $cart_item_key ) {
|
||||
|
||||
@@ -498,7 +488,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* @param string $recurring_cart_key a cart key of the form returned by @see self::get_recurring_cart_key()
|
||||
* @param int $package_index the index of a package
|
||||
* @since 2.0.12
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.12
|
||||
*/
|
||||
public static function get_recurring_shipping_package_key( $recurring_cart_key, $package_index ) {
|
||||
return $recurring_cart_key . '_' . $package_index;
|
||||
@@ -518,7 +508,7 @@ class WC_Subscriptions_Cart {
|
||||
* set of packages in WC()->shipping->packages so that plugins attempting to get the details of recurring
|
||||
* packages can get them with WC()->shipping->get_packages() like any other packages.
|
||||
*
|
||||
* @since 2.0.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.13
|
||||
*/
|
||||
public static function set_global_recurring_shipping_packages() {
|
||||
foreach ( self::$recurring_shipping_packages as $recurring_cart_key => $packages ) {
|
||||
@@ -533,7 +523,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Useful for determining if certain up-front amounts should be charged.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function all_cart_items_have_free_trial() {
|
||||
|
||||
@@ -557,7 +547,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Check if the cart contains a subscription which requires shipping.
|
||||
*
|
||||
* @since 1.5.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.4
|
||||
*/
|
||||
public static function cart_contains_subscriptions_needing_shipping( $cart = null ) {
|
||||
|
||||
@@ -594,7 +584,7 @@ class WC_Subscriptions_Cart {
|
||||
* Filters the cart contents to remove any subscriptions with free trials (or synchronised to a date in the future)
|
||||
* to make sure no shipping amount is calculated for them.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function set_cart_shipping_packages( $packages ) {
|
||||
if ( ! self::cart_contains_subscription() ) {
|
||||
@@ -649,7 +639,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Checks whether or not the COD gateway should be available on checkout when a subscription has a free trial.
|
||||
*
|
||||
* @since 3.0.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.6
|
||||
*
|
||||
* @param array $available_gateways The currently available payment gateways.
|
||||
* @return array All of the available payment gateways.
|
||||
@@ -695,7 +685,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Returns the subtotal for a cart item including the subscription period and duration details
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_formatted_product_subtotal( $product_subtotal, $product, $quantity, $cart ) {
|
||||
|
||||
@@ -746,7 +736,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Checks the cart to see if it contains a subscription product.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cart_contains_subscription() {
|
||||
@@ -763,7 +753,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Checks the cart to see if it contains a subscription product with a free trial
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function cart_contains_free_trial() {
|
||||
|
||||
@@ -784,7 +774,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Gets the cart calculation type flag
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_calculation_type() {
|
||||
return self::$calculation_type;
|
||||
@@ -793,7 +783,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Sets the cart calculation type flag
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function set_calculation_type( $calculation_type ) {
|
||||
self::$calculation_type = $calculation_type;
|
||||
@@ -828,7 +818,7 @@ class WC_Subscriptions_Cart {
|
||||
* Currently short-circuits to return just the sign-up fee of the first subscription, because only
|
||||
* one subscription can be purchased at a time.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_cart_subscription_sign_up_fee() {
|
||||
|
||||
@@ -915,7 +905,7 @@ class WC_Subscriptions_Cart {
|
||||
* the cart page because it triggers the method multiple times for multiple different pricing structures.
|
||||
* This uses the same logic found in WC_Shortcode_Cart::output() to determine the correct estimate.
|
||||
*
|
||||
* @since 1.4.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.10
|
||||
*/
|
||||
private static function maybe_restore_shipping_methods() {
|
||||
WC()->shipping->reset_shipping();
|
||||
@@ -972,7 +962,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Make sure cart product prices correctly include/exclude taxes.
|
||||
*
|
||||
* @since 1.5.8
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.8
|
||||
*/
|
||||
public static function cart_product_price( $price, $product ) {
|
||||
|
||||
@@ -991,20 +981,19 @@ class WC_Subscriptions_Cart {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the recurring totals for items in the cart
|
||||
* Displays the recurring totals for items in the cart.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function display_recurring_totals() {
|
||||
|
||||
if ( self::cart_contains_subscription() ) {
|
||||
|
||||
// We only want shipping for recurring amounts, and they need to be calculated again here
|
||||
if ( self::cart_contains_subscription() && ! empty( WC()->cart->recurring_carts ) ) {
|
||||
// We only want shipping for recurring amounts, and they need to be calculated again here.
|
||||
self::$calculation_type = 'recurring_total';
|
||||
$carts_with_multiple_payments = 0;
|
||||
|
||||
foreach ( WC()->cart->recurring_carts as $recurring_cart ) {
|
||||
// Cart contains more than one payment
|
||||
// Cart contains more than one payment.
|
||||
if ( 0 != $recurring_cart->next_payment_date ) {
|
||||
$carts_with_multiple_payments++;
|
||||
}
|
||||
@@ -1035,7 +1024,7 @@ class WC_Subscriptions_Cart {
|
||||
* to allow products on the same billing schedule to be grouped together - free trials and synchronisation is accounted for by
|
||||
* using the first renewal date (if any) for the susbcription.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_recurring_cart_key( $cart_item, $renewal_time = '' ) {
|
||||
|
||||
@@ -1096,7 +1085,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* @param array $shipping_methods
|
||||
*
|
||||
* @since 2.0.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.13
|
||||
*/
|
||||
public static function filter_recurring_cart_chosen_shipping_method( $shipping_methods ) {
|
||||
|
||||
@@ -1132,37 +1121,47 @@ class WC_Subscriptions_Cart {
|
||||
* Ensures there is at least one chosen shipping method and that the chosen method is valid considering the available
|
||||
* package rates.
|
||||
*
|
||||
* @since 2.0.14
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.14
|
||||
*/
|
||||
public static function validate_recurring_shipping_methods() {
|
||||
$shipping_methods = WC()->checkout()->shipping_methods;
|
||||
$added_invalid_notice = false;
|
||||
$standard_packages = WC()->shipping->get_packages();
|
||||
|
||||
// temporarily store the current calculation type and recurring cart key so we can restore them later
|
||||
// Temporarily store the current calculation type and recurring cart key so we can restore them later.
|
||||
$calculation_type = self::$calculation_type;
|
||||
$recurring_cart_key_flag = self::$recurring_cart_key;
|
||||
$cached_recurring_cart = self::$cached_recurring_cart;
|
||||
|
||||
self::set_calculation_type( 'recurring_total' );
|
||||
|
||||
foreach ( WC()->cart->recurring_carts as $recurring_cart_key => $recurring_cart ) {
|
||||
self::set_recurring_cart_key( $recurring_cart_key );
|
||||
|
||||
if ( false === $recurring_cart->needs_shipping() || 0 == $recurring_cart->next_payment_date ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set the recurring cart flags so shipping calculations have the recurring cart as context.
|
||||
self::set_recurring_cart_key( $recurring_cart_key );
|
||||
self::set_cached_recurring_cart( $recurring_cart );
|
||||
|
||||
foreach ( $recurring_cart->get_shipping_packages() as $recurring_cart_package_key => $recurring_cart_package ) {
|
||||
$package_index = isset( $recurring_cart_package['package_index'] ) ? $recurring_cart_package['package_index'] : 0;
|
||||
$package = self::get_calculated_shipping_for_package( $recurring_cart_package );
|
||||
$package = WC()->shipping->calculate_shipping_for_package( $recurring_cart_package );
|
||||
|
||||
if ( ( isset( $standard_packages[ $package_index ] ) && $package['rates'] == $standard_packages[ $package_index ]['rates'] ) ) {
|
||||
// the recurring package rates match the initial package rates, there won't be a selected shipping method for this recurring cart package move on to the next package.
|
||||
$package_rates_match = false;
|
||||
if ( isset( $standard_packages[ $package_index ] ) ) {
|
||||
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
||||
$package_rates_match = apply_filters( 'wcs_recurring_shipping_package_rates_match_standard_rates', $package['rates'] == $standard_packages[ $package_index ]['rates'], $package['rates'], $standard_packages[ $package_index ]['rates'], $recurring_cart_key );
|
||||
}
|
||||
|
||||
if ( $package_rates_match ) {
|
||||
// The recurring package rates match the initial package rates, there won't be a selected shipping method for this recurring cart package move on to the next package.
|
||||
if ( apply_filters( 'wcs_cart_totals_shipping_html_price_only', true, $package, $recurring_cart ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If the chosen shipping method is not available for this recurring cart package, display an error and unset the selected method.
|
||||
if ( ! isset( $package['rates'][ $shipping_methods[ $recurring_cart_package_key ] ] ) ) {
|
||||
if ( ! $added_invalid_notice ) {
|
||||
wc_add_notice( __( 'Invalid recurring shipping method.', 'woocommerce-subscriptions' ), 'error' );
|
||||
@@ -1179,8 +1178,10 @@ class WC_Subscriptions_Cart {
|
||||
WC()->checkout()->shipping_methods = $shipping_methods;
|
||||
}
|
||||
|
||||
// Restore the calculation type and recurring cart key.
|
||||
self::set_calculation_type( $calculation_type );
|
||||
self::set_recurring_cart_key( $recurring_cart_key_flag );
|
||||
self::set_cached_recurring_cart( $cached_recurring_cart );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1188,7 +1189,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* @param int The product ID or variation ID to look for.
|
||||
* @return bool Whether the product is in the cart.
|
||||
* @since 2.0.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.13
|
||||
*/
|
||||
public static function cart_contains_product( $product_id ) {
|
||||
|
||||
@@ -1211,7 +1212,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* @param int The product ID or variation ID other than which to look for.
|
||||
* @return bool Whether another subscription product is in the cart.
|
||||
* @since 3.0.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.5
|
||||
*/
|
||||
public static function cart_contains_other_subscription_products( $product_id ) {
|
||||
|
||||
@@ -1230,53 +1231,6 @@ class WC_Subscriptions_Cart {
|
||||
return $cart_contains_other_subscription_products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache the package rates calculated by @see WC_Shipping::calculate_shipping_for_package() to avoid multiple calls of calculate_shipping_for_package() per request.
|
||||
*
|
||||
* @param array $rates A set of WC_Shipping_Rate objects.
|
||||
* @param array $package A shipping package in the form returned by @see WC_Cart->get_shipping_packages()
|
||||
* @return array $rates An unaltered set of WC_Shipping_Rate objects passed to the function
|
||||
* @since 2.0.18
|
||||
*/
|
||||
public static function cache_package_rates( $rates, $package ) {
|
||||
self::$shipping_rates[ self::get_package_shipping_rates_cache_key( $package ) ] = $rates;
|
||||
|
||||
return $rates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the shipping rates for a package.
|
||||
*
|
||||
* This function will check cached rates based on a hash of the package contents to avoid re-calculation per page load.
|
||||
* If there are no rates stored in the cache for this package, it will fall back to @see WC_Shipping::calculate_shipping_for_package()
|
||||
*
|
||||
* @param array $package A shipping package in the form returned by @see WC_Cart->get_shipping_packages()
|
||||
* @return array $package
|
||||
* @since 2.0.18
|
||||
*/
|
||||
public static function get_calculated_shipping_for_package( $package ) {
|
||||
$key = self::get_package_shipping_rates_cache_key( $package );
|
||||
|
||||
if ( isset( self::$shipping_rates[ $key ] ) ) {
|
||||
$package['rates'] = apply_filters( 'woocommerce_package_rates', self::$shipping_rates[ $key ], $package );
|
||||
} else {
|
||||
$package = WC()->shipping->calculate_shipping_for_package( $package );
|
||||
}
|
||||
|
||||
return $package;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique package key for a given shipping package to be used for caching package rates.
|
||||
*
|
||||
* @param array $package A shipping package in the form returned by WC_Cart->get_shipping_packages().
|
||||
* @return string key hash
|
||||
* @since 2.0.18
|
||||
*/
|
||||
private static function get_package_shipping_rates_cache_key( $package ) {
|
||||
return md5( json_encode( array( array_keys( $package['contents'] ), $package['contents_cost'], $package['applied_coupons'] ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* When calculating the free shipping method availability, WC uses the WC->cart object. During shipping calculations for
|
||||
* recurring carts we need the recurring cart's total and coupons to be the base for checking its availability
|
||||
@@ -1285,7 +1239,7 @@ class WC_Subscriptions_Cart {
|
||||
* @param array $package
|
||||
* @return bool $is_available a revised version of is_available based off the recurring cart object
|
||||
*
|
||||
* @since 2.0.20
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.20
|
||||
*/
|
||||
public static function maybe_recalculate_shipping_method_availability( $is_available, $package ) {
|
||||
|
||||
@@ -1325,7 +1279,7 @@ class WC_Subscriptions_Cart {
|
||||
* By default WooCommerce core checks the initial cart for shipping method availability. For recurring carts,
|
||||
* shipping method availability is based whether the recurring total and coupons meet the requirements.
|
||||
*
|
||||
* @since 2.5.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.6
|
||||
*
|
||||
* @param bool $is_available Whether the shipping method is available or not.
|
||||
* @param array $package a shipping package.
|
||||
@@ -1355,7 +1309,7 @@ class WC_Subscriptions_Cart {
|
||||
* Allow third-parties to apply fees which apply to the cart to recurring carts.
|
||||
*
|
||||
* @param WC_Cart
|
||||
* @since 2.2.16
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.16
|
||||
*/
|
||||
public static function apply_recurring_fees( $cart ) {
|
||||
|
||||
@@ -1386,7 +1340,7 @@ class WC_Subscriptions_Cart {
|
||||
* that those packages no longer use the previously selected shipping method.
|
||||
*
|
||||
* @param string $encoded_form_data Encoded checkout form data.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public static function update_chosen_shipping_methods( $encoded_form_data ) {
|
||||
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() );
|
||||
@@ -1406,7 +1360,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Removes all subscription products from the shopping cart.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function remove_subscriptions_from_cart() {
|
||||
|
||||
@@ -1426,7 +1380,7 @@ class WC_Subscriptions_Cart {
|
||||
* We need to record these base tax rates to be able to honour grandfathered subscription
|
||||
* recurring prices in renewal carts.
|
||||
*
|
||||
* @since 3.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.10
|
||||
* @param WC_Cart $cart The cart object. Could be the global (initial cart) or a recurring cart.
|
||||
*/
|
||||
public static function record_base_tax_rates( $cart ) {
|
||||
@@ -1463,7 +1417,7 @@ class WC_Subscriptions_Cart {
|
||||
* use the recurring cart key instead of numeric index. Therefore, we need to hook in to override
|
||||
* the default shipping method when WooCommerce could not find a matching shipping method.
|
||||
*
|
||||
* @since 2.0.12
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.12
|
||||
*
|
||||
* @param string $default_method the default shipping method for the customer/store returned by WC_Shipping::get_default_method()
|
||||
* @param array $available_methods set of shipping rates for this calculation
|
||||
@@ -1491,7 +1445,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Only enabled if multiple checkout is not enabled.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $url The cart redirect $url.
|
||||
* @return string $url.
|
||||
@@ -1529,11 +1483,43 @@ class WC_Subscriptions_Cart {
|
||||
|
||||
/* Deprecated */
|
||||
|
||||
/**
|
||||
* Calculates the shipping rates for a package.
|
||||
*
|
||||
* This function will check cached rates based on a hash of the package contents to avoid re-calculation per page load.
|
||||
* If there are no rates stored in the cache for this package, it will fall back to @see WC_Shipping::calculate_shipping_for_package()
|
||||
*
|
||||
* @deprecated 5.4.0
|
||||
*
|
||||
* @param array $package A shipping package in the form returned by @see WC_Cart->get_shipping_packages()
|
||||
* @return array $package
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.18
|
||||
*/
|
||||
public static function get_calculated_shipping_for_package( $package ) {
|
||||
_deprecated_function( __METHOD__, 'subscriptions-core 5.4.0', 'WC()->shipping->calculate_shipping_for_package()' );
|
||||
return WC()->shipping->calculate_shipping_for_package( $package );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache the package rates calculated by @see WC_Shipping::calculate_shipping_for_package() to avoid multiple calls of calculate_shipping_for_package() per request.
|
||||
*
|
||||
* @deprecated 5.4.0
|
||||
*
|
||||
* @param array $rates A set of WC_Shipping_Rate objects.
|
||||
* @param array $package A shipping package in the form returned by @see WC_Cart->get_shipping_packages()
|
||||
* @return array $rates An unaltered set of WC_Shipping_Rate objects passed to the function
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.18
|
||||
*/
|
||||
public static function cache_package_rates( $rates, $package ) {
|
||||
_deprecated_function( __METHOD__, 'subscriptions-core 5.4.0' );
|
||||
return $rates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't allow new subscription products to be added to the cart if it contains a subscription renewal already.
|
||||
*
|
||||
* @deprecated 2.6.0
|
||||
* @since 2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function check_valid_add_to_cart( $is_valid, $product_id, $quantity, $variation_id = '', $variations = array(), $item_data = array() ) {
|
||||
_deprecated_function( __METHOD__, '2.6.0', 'WC_Subscriptions_Cart_Validator::check_valid_add_to_cart' );
|
||||
@@ -1551,8 +1537,8 @@ class WC_Subscriptions_Cart {
|
||||
* Make sure cart totals are calculated when the cart widget is populated via the get_refreshed_fragments() method
|
||||
* so that @see self::get_formatted_cart_subtotal() returns the correct subtotal price string.
|
||||
*
|
||||
* @since 1.5.11
|
||||
* @deprecated 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.11
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
public static function pre_get_refreshed_fragments() {
|
||||
wcs_deprecated_function( __METHOD__, '2.5.0' );
|
||||
@@ -1567,8 +1553,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Returns the cart_item containing the product renewal, else false.
|
||||
*
|
||||
* @deprecated 2.0
|
||||
* @since 1.3
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function cart_contains_subscription_renewal( $role = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_cart_contains_renewal( $role )' );
|
||||
@@ -1580,8 +1566,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Returns the cart_item containing the product renewal, else false.
|
||||
*
|
||||
* @deprecated 2.0
|
||||
* @since 1.4
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function cart_contains_failed_renewal_order_payment() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_cart_contains_failed_renewal_order_payment()' );
|
||||
@@ -1593,7 +1579,7 @@ class WC_Subscriptions_Cart {
|
||||
* Restore renewal flag when cart is reset and modify Product object with
|
||||
* renewal order related info
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function get_cart_item_from_session( $session_data, $values, $key ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::get_cart_item_from_session( $session_data, $values, $key )' );
|
||||
@@ -1602,7 +1588,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* For subscription renewal via cart, use original order discount
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function before_calculate_totals( $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::set_renewal_discounts( $cart )' );
|
||||
@@ -1613,7 +1599,7 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* No longer required as of 1.3.5 as totals are calculated correctly internally.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function get_discounted_price_for_renewal( $price, $values, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::get_discounted_price_for_renewal( $price, $values, $cart )' );
|
||||
@@ -1623,8 +1609,8 @@ class WC_Subscriptions_Cart {
|
||||
* Returns a string with the cart discount and subscription period.
|
||||
*
|
||||
* @return mixed formatted price or false if there are none
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_formatted_discounts_before_tax( $discount, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1635,8 +1621,8 @@ class WC_Subscriptions_Cart {
|
||||
* Gets the order discount amount - these are applied after tax
|
||||
*
|
||||
* @return mixed formatted price or false if there are none
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_formatted_discounts_after_tax( $discount, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1649,8 +1635,8 @@ class WC_Subscriptions_Cart {
|
||||
* @param string $discount_html String of the coupon's discount amount
|
||||
* @param string $coupon WC_Coupon object for the coupon to which this line item relates
|
||||
* @return string formatted subscription price string if the cart includes a coupon being applied to recurring amount
|
||||
* @since 1.4.6
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.6
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function cart_coupon_discount_amount_html( $discount_html, $coupon ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1663,8 +1649,8 @@ class WC_Subscriptions_Cart {
|
||||
* @param string $discount_html String of the coupon's discount amount
|
||||
* @param string $coupon WC_Coupon object for the coupon to which this line item relates
|
||||
* @return string formatted subscription price string if the cart includes a coupon being applied to recurring amount
|
||||
* @since 1.4.6
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.6
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function cart_totals_fee_html( $cart_totals_fee_html, $fee ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1674,9 +1660,9 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Includes the sign-up fee total in the cart total (after calculation).
|
||||
*
|
||||
* @since 1.5.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.10
|
||||
* @return string formatted price
|
||||
* @deprecated 2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_formatted_cart_total( $cart_contents_total ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1686,8 +1672,8 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Includes the sign-up fee subtotal in the subtotal displayed in the cart.
|
||||
*
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_formatted_cart_subtotal( $cart_subtotal, $compound, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1698,8 +1684,8 @@ class WC_Subscriptions_Cart {
|
||||
* Returns an array of taxes merged by code, formatted with recurring amount ready for output.
|
||||
*
|
||||
* @return array Array of tax_id => tax_amounts for items in the cart
|
||||
* @since 1.3.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_recurring_tax_totals( $tax_totals, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1711,8 +1697,8 @@ class WC_Subscriptions_Cart {
|
||||
* recurring amount.
|
||||
*
|
||||
* @return array Array of tax_id => tax_amounts for items in the cart
|
||||
* @since 1.4.10
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.10
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_taxes_total_html( $total ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1723,8 +1709,8 @@ class WC_Subscriptions_Cart {
|
||||
* Appends the cart subscription string to a cart total using the @see self::get_cart_subscription_string and then returns it.
|
||||
*
|
||||
* @return string Formatted subscription price string for the cart total.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_formatted_total( $total ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1735,8 +1721,8 @@ class WC_Subscriptions_Cart {
|
||||
* Appends the cart subscription string to a cart total using the @see self::get_cart_subscription_string and then returns it.
|
||||
*
|
||||
* @return string Formatted subscription price string for the cart total.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_formatted_total_ex_tax( $total_ex_tax ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1746,8 +1732,8 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Returns an array of the recurring total fields
|
||||
*
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_recurring_totals_fields() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'recurring total values stored in WC()->cart->recurring_carts' );
|
||||
@@ -1759,8 +1745,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Deprecated because a cart can now contain multiple subscription products, so there is no single period for the entire cart.
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_cart_subscription_period() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1782,8 +1768,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Deprecated because a cart can now contain multiple subscription products, so there is no single interval for the entire cart.
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_cart_subscription_interval() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1803,8 +1789,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Deprecated because a cart can now contain multiple subscription products, so there is no single length for the entire cart.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_cart_subscription_length() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1828,8 +1814,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Deprecated because a cart can now contain multiple subscription products, so there is no single trial length for the entire cart.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_cart_subscription_trial_length() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1853,8 +1839,8 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* Deprecated because a cart can now contain multiple subscription products, so there is no single trial period for the entire cart.
|
||||
*
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_cart_subscription_trial_period() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1880,7 +1866,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return float price
|
||||
* @deprecated 2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_recurring_cart_contents_total() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1904,7 +1890,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring item subtotal amount less tax for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_subtotal_ex_tax() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1924,7 +1910,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring item subtotal amount for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_subtotal() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1944,7 +1930,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring cart discount amount for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_discount_cart() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1964,7 +1950,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_recurring_discount_cart_tax() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -1984,7 +1970,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring discount amount for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_discount_total() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2006,7 +1992,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring shipping tax amount for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_shipping_tax_total() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2028,7 +2014,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring shipping amount for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_shipping_total() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2048,7 +2034,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return array Array of tax_id => tax_amounts for items in the cart
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_taxes() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2072,7 +2058,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return array Array of fee_id => fee_details for items in the cart
|
||||
* @since 1.4.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
*/
|
||||
public static function get_recurring_fees() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2092,7 +2078,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring tax amount tax for items in the cart (maybe not including compound taxes)
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_taxes_total( $compound = true ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2123,7 +2109,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring tax amount tax for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_total_tax() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2143,7 +2129,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring amount less tax for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_total_ex_tax() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2156,7 +2142,7 @@ class WC_Subscriptions_Cart {
|
||||
* Deprecated because the cart can now contain subscriptions on multiple billing schedules so there is no one "total"
|
||||
*
|
||||
* @return double The total recurring amount for items in the cart.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_total() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2174,8 +2160,8 @@ class WC_Subscriptions_Cart {
|
||||
* Calculate the total amount of recurring shipping needed. Removes any item from the calculation that
|
||||
* is not a subscription and calculates the totals.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function calculate_recurring_shipping() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2193,8 +2179,8 @@ class WC_Subscriptions_Cart {
|
||||
* @param string $initial_amount The initial amount to be displayed for the subscription as passed through the @see woocommerce_price() function.
|
||||
* @param float $recurring_amount The price to display in the subscription.
|
||||
* @param array $args (optional) Flags to customise to display the trial and length of the subscription. Default to false - don't display.
|
||||
* @since 1.0
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_cart_subscription_string( $initial_amount, $recurring_amount, $args = array() ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2271,8 +2257,8 @@ class WC_Subscriptions_Cart {
|
||||
* Uses the a subscription's combined price total calculated by WooCommerce to determine the
|
||||
* total price that should be charged per period.
|
||||
*
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function set_calculated_total( $total ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'values from WC()->cart->recurring_carts' );
|
||||
@@ -2282,7 +2268,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Get the recurring amounts values from the session
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_cart_from_session() {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2291,7 +2277,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Store the sign-up fee cart values in the session
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function set_session() {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2300,7 +2286,7 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Reset the sign-up fee fields in the current session
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function reset() {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2310,7 +2296,7 @@ class WC_Subscriptions_Cart {
|
||||
* Returns a cart item's product ID. For a variation, this will be a variation ID, for a simple product,
|
||||
* it will be the product's ID.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function get_items_product_id( $cart_item ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_get_canonical_product_id( $cart_item )' );
|
||||
@@ -2340,7 +2326,7 @@ class WC_Subscriptions_Cart {
|
||||
* Don't display shipping prices if the initial order won't require shipping (i.e. all the products in the cart are subscriptions with a free trial or synchronised to a date in the future)
|
||||
*
|
||||
* @return string Label for a shipping method
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function get_cart_shipping_method_full_label( $label, $method ) {
|
||||
_deprecated_function( __METHOD__, '2.0.12' );
|
||||
@@ -2522,9 +2508,9 @@ class WC_Subscriptions_Cart {
|
||||
* We can't do this on the cart page unfortunately because it doesn't pass the entire forms post data and instead only
|
||||
* sends the shipping methods with a numerical index.
|
||||
*
|
||||
* @deprecated 3.1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
* @return null
|
||||
* @since 2.0.12
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.12
|
||||
*/
|
||||
public static function add_shipping_method_post_data() {
|
||||
wcs_deprecated_function( __METHOD__, '3.1.0' );
|
||||
@@ -2566,10 +2552,10 @@ class WC_Subscriptions_Cart {
|
||||
*
|
||||
* For more details, see: https://github.com/Prospress/woocommerce-subscriptions/pull/1187#issuecomment-186091152
|
||||
*
|
||||
* @deprecated 3.1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*
|
||||
* @param array $packages An array of shipping package of the form returned by WC_Cart->get_shipping_packages() which includes the package's contents, cost, customer, destination and alternative rates
|
||||
* @since 2.0.19
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.19
|
||||
*/
|
||||
public static function reset_shipping_method_counts( $packages ) {
|
||||
wcs_deprecated_function( __METHOD__, '3.1.0' );
|
||||
@@ -2583,8 +2569,8 @@ class WC_Subscriptions_Cart {
|
||||
/**
|
||||
* Checks to see if payment method is required on a subscription product with a $0 initial payment.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @deprecated 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function zero_initial_payment_requires_payment() {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Zero_Initial_Payment_Checkout_Manager::zero_initial_checkout_requires_payment() if available.' );
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* @subpackage WC_Subscriptions_Change_Payment_Gateway
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
class WC_Subscriptions_Change_Payment_Gateway {
|
||||
|
||||
@@ -22,7 +22,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -78,7 +78,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* Set a flag to indicate that the current request is for changing payment. Better than requiring other extensions
|
||||
* to check the $_GET global as it allows for the flag to be overridden.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function set_change_payment_method_flag() {
|
||||
if ( isset( $_GET['change_payment_method'] ) ) {
|
||||
@@ -91,7 +91,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* This is particularly important for those occasions when the new payment method caused and error or failure.
|
||||
*
|
||||
* @since 2.3.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.6
|
||||
*/
|
||||
public static function store_pay_shortcode_messages() {
|
||||
self::$notices = wc_get_notices();
|
||||
@@ -100,9 +100,8 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
/**
|
||||
* Store messages ore errors added by other plugins.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 2.3.6 Deprecated in favor of the method with proper spelling.
|
||||
* @deprecated
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.6, Deprecated in favor of the method with proper spelling.
|
||||
*/
|
||||
public static function store_pay_shortcode_mesages() {
|
||||
wcs_deprecated_function( __METHOD__, '2.3.6', __CLASS__ . '::store_pay_shortcode_messages' );
|
||||
@@ -112,7 +111,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
/**
|
||||
* If requesting a payment method change, replace the woocommerce_pay_shortcode() with a change payment form.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function maybe_replace_pay_shortcode() {
|
||||
global $wp;
|
||||
@@ -148,7 +147,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* Action that allows payment methods to modify the subscription object so, for example,
|
||||
* if the new payment method still hasn't been set, they can set it temporarily (without saving).
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.0
|
||||
*
|
||||
* @param WC_Subscription $subscription
|
||||
*/
|
||||
@@ -214,7 +213,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* Will display a customer facing notice if the request is invalid.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.0
|
||||
*
|
||||
* @param WC_Subscription $subscription
|
||||
* @return bool Whether the request is valid or not.
|
||||
@@ -247,7 +246,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
|
||||
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function change_payment_method_button( $actions, $subscription ) {
|
||||
|
||||
@@ -275,7 +274,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function change_payment_method_via_pay_shortcode() {
|
||||
|
||||
@@ -332,7 +331,12 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
// Process payment for the new method (with a $0 order total)
|
||||
if ( wc_notice_count( 'error' ) == 0 ) {
|
||||
|
||||
try {
|
||||
$result = $available_gateways[ $new_payment_method ]->process_payment( $subscription->get_id() );
|
||||
} catch ( Exception $e ) {
|
||||
wc_add_notice( $e->getMessage(), 'error' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'success' == $result['result'] && wc_get_page_permalink( 'myaccount' ) == $result['redirect'] ) {
|
||||
$result['redirect'] = $subscription->get_view_order_url();
|
||||
@@ -344,6 +348,14 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* After processing the payment result, make sure we get a new instance of the subscription.
|
||||
*
|
||||
* Because process_payment() is sent an ID, all subscription meta changes would occur on a different instance on the subscription.
|
||||
* We need a new instance to ensure we have the latest changes when processing the update all subscription payment method request below.
|
||||
*/
|
||||
$subscription = wcs_get_subscription( $subscription->get_id() );
|
||||
|
||||
$subscription->set_requires_manual_renewal( false );
|
||||
$subscription->save();
|
||||
|
||||
@@ -365,7 +377,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
|
||||
// Redirect to success/confirmation/payment page
|
||||
wc_add_notice( $notice );
|
||||
wp_redirect( $result['redirect'] );
|
||||
wp_safe_redirect( $result['redirect'] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -379,7 +391,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* @param WC_Subscription $subscription An instance of a WC_Subscription object.
|
||||
* @param string $new_payment_method The ID of the new payment method.
|
||||
* @return bool Were other subscriptions updated.
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
public static function update_all_payment_methods_from_subscription( $subscription, $new_payment_method ) {
|
||||
|
||||
@@ -432,7 +444,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* @param WC_Payment_Gateway $gateway The payment gateway to check.
|
||||
* @param WC_Subscription $subscription An instance of a WC_Subscription object.
|
||||
* @return bool Gateway supports updating all current subscriptions.
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
public static function can_update_all_subscription_payment_methods( $gateway, $subscription ) {
|
||||
|
||||
@@ -456,7 +468,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @param WC_Subscription $subscription An instance of a WC_Subscription object.
|
||||
* @return bool Subscription will update all current subscriptions.
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
public static function will_subscription_update_all_payment_methods( $subscription ) {
|
||||
if ( ! wcs_is_subscription( $subscription ) ) {
|
||||
@@ -472,7 +484,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* @param WC_Subscription $subscription An instance of a WC_Subscription object.
|
||||
* @param string $new_payment_method The ID of the new payment method.
|
||||
* @param array $new_payment_method_meta The meta for the new payment method. Optional. Default false.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function update_payment_method( $subscription, $new_payment_method, $new_payment_method_meta = false ) {
|
||||
|
||||
@@ -550,7 +562,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* when requesting to change the payment method.
|
||||
*
|
||||
* @param array $available_gateways The payment gateways which are currently being allowed.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function get_available_payment_gateways( $available_gateways ) {
|
||||
$is_change_payment_method_request = isset( $_GET['change_payment_method'] );
|
||||
@@ -589,7 +601,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
/**
|
||||
* Make sure certain totals are set to 0 when the request is to change the payment method without charging anything.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function maybe_zero_total( $total, $subscription ) {
|
||||
global $wp;
|
||||
@@ -607,7 +619,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
/**
|
||||
* Redirect back to the "My Account" page instead of the "Thank You" page after changing the payment method.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function get_return_url( $return_url ) {
|
||||
|
||||
@@ -626,7 +638,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
|
||||
* @param WC_Order $original_order The original order in which the subscription was purchased.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function change_failing_payment_method( $renewal_order, $subscription ) {
|
||||
|
||||
@@ -655,7 +667,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* @param bool $subscription_can_be_changed Flag of whether the subscription can be changed.
|
||||
* @param WC_Subscription $subscription The subscription to check.
|
||||
* @return bool Flag indicating whether the subscription payment method can be updated.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function can_subscription_be_updated_to_new_payment_method( $subscription_can_be_changed, $subscription ) {
|
||||
|
||||
@@ -693,7 +705,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @param string $title
|
||||
* @return string
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function change_payment_method_page_title( $title ) {
|
||||
|
||||
@@ -717,7 +729,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @param array $crumbs
|
||||
* @return array
|
||||
* @since 2.4.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.4.2
|
||||
*/
|
||||
public static function change_payment_method_breadcrumb( $crumbs ) {
|
||||
|
||||
@@ -752,7 +764,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
/**
|
||||
* Get the Change Payment Method page title (also used for the page breadcrumb)
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @param WC_Subscription $subscription
|
||||
* @return string
|
||||
*/
|
||||
@@ -774,7 +786,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* @param bool $needs_payment
|
||||
* @param WC_Subscription $subscription
|
||||
* @return bool
|
||||
* @since 2.0.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.7
|
||||
*/
|
||||
public static function maybe_override_needs_payment( $needs_payment ) {
|
||||
|
||||
@@ -790,7 +802,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* @param string $content The default HTML page content.
|
||||
* @return string $content.
|
||||
* @since 2.5.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.0
|
||||
*/
|
||||
public static function maybe_request_log_in( $content ) {
|
||||
global $wp;
|
||||
@@ -822,8 +834,8 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* Update the recurring payment method on a subscription order.
|
||||
*
|
||||
* @param array $available_gateways The payment gateways which are currently being allowed.
|
||||
* @since 1.4
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function update_recurring_payment_method( $subscription_key, $order, $new_payment_method ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::update_payment_method()' );
|
||||
@@ -835,8 +847,8 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* Deprecated as we now operate on a WC_Subscription object instead of the parent order, so we don't need to hack around date changes.
|
||||
*
|
||||
* @since 1.4
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function store_original_order_dates( $new_order_status, $subscription_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -847,8 +859,8 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
*
|
||||
* Deprecated as we now operate on a WC_Subscription object instead of the parent order, so we don't need to hack around date changes.
|
||||
*
|
||||
* @since 1.4
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function restore_original_order_dates( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -870,7 +882,7 @@ class WC_Subscriptions_Change_Payment_Gateway {
|
||||
* 'order' WC_Order The order which recorded the successful payment (to make up for the failed automatic payment).
|
||||
* 'payment_gateway' WC_Payment_Gateway The subscription's recurring payment gateway
|
||||
* 'order_uses_manual_payments' bool A boolean flag indicating whether the subscription requires manual renewal payment.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function can_subscription_be_changed_to( $subscription_can_be_changed, $new_status_or_meta, $args ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::can_subscription_be_updated_to_new_payment_method()' );
|
||||
|
@@ -16,7 +16,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -49,10 +49,13 @@ class WC_Subscriptions_Checkout {
|
||||
|
||||
// Override the WC default "Add to cart" text to "Sign up now" (in various places/templates)
|
||||
add_filter( 'woocommerce_order_button_text', array( __CLASS__, 'order_button_text' ) );
|
||||
|
||||
// Check the "Ship to different address" checkbox if the shipping address of the originating order is different to the billing address.
|
||||
add_filter( 'woocommerce_ship_to_different_address_checked', array( __CLASS__, 'maybe_check_ship_to_different_address' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.2.17
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.17
|
||||
*/
|
||||
public static function attach_dependant_hooks() {
|
||||
// Make sure guest checkout is not enabled in option param passed to WC JS
|
||||
@@ -69,7 +72,7 @@ class WC_Subscriptions_Checkout {
|
||||
*
|
||||
* @param int $order_id The post_id of a shop_order post/WC_Order object
|
||||
* @param array $posted_data The data posted on checkout
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function process_checkout( $order_id, $posted_data = array() ) {
|
||||
|
||||
@@ -85,11 +88,13 @@ class WC_Subscriptions_Checkout {
|
||||
$subscriptions = wcs_get_subscriptions_for_order( wcs_get_objects_property( $order, 'id' ), array( 'order_type' => 'parent' ) );
|
||||
|
||||
if ( ! empty( $subscriptions ) ) {
|
||||
remove_action( 'before_delete_post', 'WC_Subscriptions_Manager::maybe_cancel_subscription' );
|
||||
$action_hook = wcs_is_custom_order_tables_usage_enabled() ? 'woocommerce_before_delete_subscription' : 'before_delete_post';
|
||||
|
||||
remove_action( $action_hook, 'WC_Subscriptions_Manager::maybe_cancel_subscription' );
|
||||
foreach ( $subscriptions as $subscription ) {
|
||||
wp_delete_post( $subscription->get_id() );
|
||||
$subscription->delete( true );
|
||||
}
|
||||
add_action( 'before_delete_post', 'WC_Subscriptions_Manager::maybe_cancel_subscription' );
|
||||
add_action( $action_hook, 'WC_Subscriptions_Manager::maybe_cancel_subscription' );
|
||||
}
|
||||
|
||||
WC_Subscriptions_Cart::set_global_recurring_shipping_packages();
|
||||
@@ -117,7 +122,7 @@ class WC_Subscriptions_Checkout {
|
||||
*
|
||||
* @param WC_Order $order
|
||||
* @param WC_Cart $cart
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function create_subscription( $order, $cart, $posted_data ) {
|
||||
|
||||
@@ -257,7 +262,13 @@ class WC_Subscriptions_Checkout {
|
||||
return new WP_Error( 'checkout-error', $e->getMessage() );
|
||||
}
|
||||
|
||||
return $subscription;
|
||||
/**
|
||||
* Fetch and return a fresh instance of the subscription from the database.
|
||||
*
|
||||
* After saving the subscription, we need to fetch the subscription from the database as the current object state may not match the loaded state.
|
||||
* This occurs because different instances of the subscription might have been saved in any one of the processes above resulting in this object being out of sync.
|
||||
*/
|
||||
return wcs_get_subscription( $subscription );
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +287,7 @@ class WC_Subscriptions_Checkout {
|
||||
if ( $cart->needs_shipping() ) {
|
||||
foreach ( $cart->get_shipping_packages() as $recurring_cart_package_key => $recurring_cart_package ) {
|
||||
$package_index = isset( $recurring_cart_package['package_index'] ) ? $recurring_cart_package['package_index'] : 0;
|
||||
$package = WC_Subscriptions_Cart::get_calculated_shipping_for_package( $recurring_cart_package );
|
||||
$package = WC()->shipping->calculate_shipping_for_package( $recurring_cart_package );
|
||||
$shipping_method_id = isset( WC()->checkout()->shipping_methods[ $package_index ] ) ? WC()->checkout()->shipping_methods[ $package_index ] : '';
|
||||
|
||||
if ( isset( WC()->checkout()->shipping_methods[ $recurring_cart_package_key ] ) ) {
|
||||
@@ -289,7 +300,7 @@ class WC_Subscriptions_Checkout {
|
||||
if ( isset( $package['rates'][ $shipping_method_id ] ) ) {
|
||||
$shipping_rate = $package['rates'][ $shipping_method_id ];
|
||||
$item = new WC_Order_Item_Shipping();
|
||||
$item->legacy_package_key = $package_key; // @deprecated For legacy actions.
|
||||
$item->legacy_package_key = $package_key; // @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions, For legacy actions.
|
||||
$item->set_props(
|
||||
array(
|
||||
'method_title' => $shipping_rate->label,
|
||||
@@ -333,7 +344,7 @@ class WC_Subscriptions_Checkout {
|
||||
* @param string $cart_item_key The hash used to identify the item in the cart
|
||||
* @param array $cart_item The cart item's data.
|
||||
* @param WC_Order|WC_Subscription $subscription The order or subscription object to which the line item relates
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function remove_backorder_meta_from_subscription_line_item( $item, $cart_item_key, $cart_item, $subscription ) {
|
||||
|
||||
@@ -349,7 +360,7 @@ class WC_Subscriptions_Checkout {
|
||||
* @param string $cart_item_key The item's cart item key.
|
||||
* @param array $cart_item The cart item.
|
||||
* @param WC_Subscription $subscription The subscription the item is being added to.
|
||||
* @since 2.6.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
*/
|
||||
public static function maybe_add_free_trial_item_meta( $item, $cart_item_key, $cart_item, $subscription ) {
|
||||
if ( wcs_is_subscription( $subscription ) && WC_Subscriptions_Product::get_trial_length( $item->get_product() ) > 0 ) {
|
||||
@@ -360,7 +371,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Add a cart item to a subscription.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_cart_item( $subscription, $cart_item, $cart_item_key ) {
|
||||
_deprecated_function( __METHOD__, '2.2.0', 'WC_Checkout::create_order_line_items( $subscription, $cart )' );
|
||||
@@ -401,7 +412,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* When a new order is inserted, add subscriptions related order meta.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function add_order_meta( $order_id, $posted ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -410,7 +421,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Add each subscription product's details to an order so that the state of the subscription persists even when a product is changed
|
||||
*
|
||||
* @since 1.2.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
*/
|
||||
public static function add_order_item_meta( $item_id, $values ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -423,7 +434,7 @@ class WC_Subscriptions_Checkout {
|
||||
* @param string $handle Default empty string ('').
|
||||
* @param array $woocommerce_params
|
||||
*
|
||||
* @since 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_woocommerce_script_parameters( $woocommerce_params, $handle = '' ) {
|
||||
@@ -442,7 +453,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Stores the subtracted base location tax totals in the subscription line item meta.
|
||||
*
|
||||
* @since 3.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.10
|
||||
*
|
||||
* @param WC_Line_Item_Product $line_item The line item added to the order/subscription.
|
||||
* @param string $cart_item_key The key of the cart item being added to the cart.
|
||||
@@ -459,8 +470,8 @@ class WC_Subscriptions_Checkout {
|
||||
* Also make sure the guest checkout option value passed to the woocommerce.js forces registration.
|
||||
* Otherwise the registration form is hidden by woocommerce.js.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated 2.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.3
|
||||
*/
|
||||
public static function filter_woocommerce_script_paramaters( $woocommerce_params, $handle = '' ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.5.3', 'WC_Subscriptions_Admin::filter_woocommerce_script_parameters( $woocommerce_params, $handle )' );
|
||||
@@ -471,7 +482,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Enables the 'registeration required' (guest checkout) setting when purchasing subscriptions.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*
|
||||
* @param bool $account_required Whether an account is required to checkout.
|
||||
* @return bool
|
||||
@@ -487,7 +498,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* During the checkout process, force registration when the cart contains a subscription.
|
||||
*
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
* @param $woocommerce_params This parameter is not used.
|
||||
*/
|
||||
public static function force_registration_during_checkout( $woocommerce_params ) {
|
||||
@@ -504,7 +515,7 @@ class WC_Subscriptions_Checkout {
|
||||
*
|
||||
* The message will redirect the customer to the My Account page if registration is enabled there, otherwise a generic 'you need an account' message will be displayed.
|
||||
*
|
||||
* @since 3.0.11
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.11
|
||||
* @return string The error message.
|
||||
*/
|
||||
private static function get_registration_error_message() {
|
||||
@@ -523,7 +534,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Enables registration for carts containing subscriptions if admin allow it.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*
|
||||
* @param bool $registration_enabled Whether registration is enabled on checkout by default.
|
||||
* @return bool
|
||||
@@ -549,8 +560,8 @@ class WC_Subscriptions_Checkout {
|
||||
* When creating an order at checkout, if the checkout is to renew a subscription from a failed
|
||||
* payment, hijack the order creation to make a renewal order - not a plain WooCommerce order.
|
||||
*
|
||||
* @since 1.3
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function filter_woocommerce_create_order( $order_id, $checkout_object ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -560,7 +571,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Customise which actions are shown against a subscriptions order on the My Account page.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function filter_woocommerce_my_account_my_orders_actions( $actions, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::filter_my_account_my_orders_actions()' );
|
||||
@@ -570,8 +581,8 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* If shopping cart contains subscriptions, make sure a user can register on the checkout page
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*/
|
||||
public static function make_checkout_registration_possible( $checkout = '' ) {
|
||||
wcs_deprecated_function( __METHOD__, '3.1.0' );
|
||||
@@ -590,8 +601,8 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Make sure account fields display the required "*" when they are required.
|
||||
*
|
||||
* @since 1.3.5
|
||||
* @deprecated 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*/
|
||||
public static function make_checkout_account_fields_required( $checkout_fields ) {
|
||||
wcs_deprecated_function( __METHOD__, '3.1.0' );
|
||||
@@ -616,8 +627,8 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* After displaying the checkout form, restore the store's original registration settings.
|
||||
*
|
||||
* @since 1.1
|
||||
* @deprecated 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*/
|
||||
public static function restore_checkout_registration_settings( $checkout = '' ) {
|
||||
wcs_deprecated_function( __METHOD__, '3.1.0' );
|
||||
@@ -632,7 +643,7 @@ class WC_Subscriptions_Checkout {
|
||||
/**
|
||||
* Overrides the "Place order" button text with "Sign up now" when the cart contains initial subscription purchases.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $button_text The place order button text.
|
||||
* @return string $button_text
|
||||
@@ -649,4 +660,45 @@ class WC_Subscriptions_Checkout {
|
||||
|
||||
return apply_filters( 'wcs_place_subscription_order_text', __( 'Sign up now', 'woocommerce-subscriptions' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the cart contains a renewal order, resubscribe order or a subscription switch
|
||||
* that needs to ship to an address that is different to the order's billing address,
|
||||
* tell the checkout to check the "Ship to different address" checkbox.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*
|
||||
* @param bool $ship_to_different_address Whether the order will check the "Ship to different address" checkbox
|
||||
* @return bool $ship_to_different_address
|
||||
*/
|
||||
public static function maybe_check_ship_to_different_address( $ship_to_different_address ) {
|
||||
$switch_items = wcs_cart_contains_switches();
|
||||
$renewal_item = wcs_cart_contains_renewal();
|
||||
$resubscribe_item = wcs_cart_contains_resubscribe();
|
||||
|
||||
if ( ! $switch_items && ! $renewal_item && ! $resubscribe_item ) {
|
||||
return $ship_to_different_address;
|
||||
}
|
||||
|
||||
if ( ! $ship_to_different_address ) {
|
||||
// Get the subscription ID from the corresponding cart item
|
||||
if ( $switch_items ) {
|
||||
$subscription_id = array_values( $switch_items )[0]['subscription_id'];
|
||||
} elseif ( $renewal_item ) {
|
||||
$subscription_id = $renewal_item['subscription_renewal']['subscription_id'];
|
||||
} elseif ( $resubscribe_item ) {
|
||||
$subscription_id = $resubscribe_item['subscription_resubscribe']['subscription_id'];
|
||||
}
|
||||
|
||||
$order = wc_get_order( $subscription_id );
|
||||
|
||||
// If the order's addresses are different, we need to display the shipping fields otherwise the billing address will override it
|
||||
$addresses_are_equal = wcs_compare_order_billing_shipping_address( $order );
|
||||
if ( ! $addresses_are_equal ) {
|
||||
$ship_to_different_address = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $ship_to_different_address;
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* WooCommerce Subscriptions setup
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
@@ -13,11 +13,10 @@ require_once dirname( __FILE__ ) . '/class-wcs-core-autoloader.php';
|
||||
class WC_Subscriptions_Core_Plugin {
|
||||
|
||||
/**
|
||||
* The plugin version core is based off.
|
||||
*
|
||||
* The version of subscriptions-core library.
|
||||
* @var string
|
||||
*/
|
||||
protected $plugin_version = '3.1.6';
|
||||
protected $library_version = '5.8.0'; // WRCS: DEFINED_VERSION.
|
||||
|
||||
/**
|
||||
* The subscription scheduler instance.
|
||||
@@ -58,6 +57,9 @@ class WC_Subscriptions_Core_Plugin {
|
||||
$this->autoloader->register();
|
||||
}
|
||||
|
||||
// Load the Order Tables/Data Store Controller class early.
|
||||
new WCS_Orders_Table_Data_Store_Controller();
|
||||
|
||||
$this->define_constants();
|
||||
$this->includes();
|
||||
$this->init();
|
||||
@@ -70,7 +72,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Gets the Subscriptions Core instance.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @return WC_Subscriptions_Core_Plugin
|
||||
*/
|
||||
public static function instance() {
|
||||
@@ -206,7 +208,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Attaches the hooks to init/setup the plugin.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function init_hooks() {
|
||||
register_deactivation_hook( $this->get_plugin_file(), array( $this, 'deactivate_plugin' ) );
|
||||
@@ -234,7 +236,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Gets the subscriptions core directory.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @param string $path Optional. The path to append.
|
||||
* @return string
|
||||
*/
|
||||
@@ -245,7 +247,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Gets the subscriptions core directory url.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @param string $path Optional. The path to append.
|
||||
* @return string
|
||||
*/
|
||||
@@ -256,10 +258,20 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Gets the plugin's version
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @deprecated 5.0.0 This function is no longer recommended for version detection. Use get_library_version() instead.
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function get_plugin_version() {
|
||||
return $this->plugin_version;
|
||||
return $this->library_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subscription-core library version.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function get_library_version() {
|
||||
return $this->library_version;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,7 +313,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Gets the core Payment Gateways handler class
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_gateways_handler_class() {
|
||||
@@ -311,7 +323,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Registers Subscriptions order types.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function register_order_types() {
|
||||
$subscriptions_exist = $this->cache->cache_and_get( 'wcs_do_subscriptions_exist', 'wcs_do_subscriptions_exist' );
|
||||
@@ -382,7 +394,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Registers data stores.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
* @return string[]
|
||||
*/
|
||||
public function add_data_stores( $data_stores ) {
|
||||
@@ -400,7 +412,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Registers our custom post statuses, used for subscription statuses.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function register_post_statuses() {
|
||||
$subscription_statuses = wcs_get_subscription_statuses();
|
||||
@@ -438,7 +450,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Runs the required processes when the plugin is deactivated.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function deactivate_plugin() {
|
||||
delete_option( WC_Subscriptions_Admin::$option_prefix . '_is_active' );
|
||||
@@ -449,7 +461,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Runs the required process on plugin activation.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function activate_plugin() {
|
||||
$is_active = get_option( WC_Subscriptions_Admin::$option_prefix . '_is_active', false );
|
||||
@@ -492,7 +504,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Registers plugin translation files.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
$plugin_rel_path = apply_filters( 'woocommerce_subscriptions_translation_file_rel_path', $this->get_subscriptions_core_directory() . '/languages' );
|
||||
@@ -504,7 +516,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Adds the settings, docs and support links to the plugin screen.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string[] $links The plugin's links displayed on the plugin screen.
|
||||
* @return string[]
|
||||
@@ -522,7 +534,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Displays an upgrade notice for stores upgrading to 2.0.0.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param array $plugin_data Information about the plugin.
|
||||
* @param array $r response from the server about the new version.
|
||||
@@ -545,7 +557,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
/**
|
||||
* Sets up the Blocks integration class.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public function setup_blocks_integration() {
|
||||
/**
|
||||
@@ -572,7 +584,7 @@ class WC_Subscriptions_Core_Plugin {
|
||||
* Renewals use a lot more memory on WordPress multisite (10-15mb instead of 0.1-1mb) so
|
||||
* we need to reduce the number of renewals run in each request.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param int $batch_size The default Action Scheduler batch size.
|
||||
* @return int
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* @subpackage WC_Subscriptions_Coupon
|
||||
* @category Class
|
||||
* @author Max Rice
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
class WC_Subscriptions_Coupon {
|
||||
|
||||
@@ -25,7 +25,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Stores the coupons not applied to a given calculation (so they can be applied later)
|
||||
*
|
||||
* @since 1.3.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
* @deprecated
|
||||
*/
|
||||
private static $removed_coupons = array();
|
||||
@@ -64,7 +64,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Set up the class, including it's hooks & filters, when the file is loaded.
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
**/
|
||||
public static function init() {
|
||||
|
||||
@@ -103,7 +103,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param string $coupon_html Html string of the recurring coupon's cell in the Cart totals table
|
||||
* @param WC_coupon $coupon WC_Coupon object of the recurring coupon
|
||||
* @return string $coupon_html Modified html string of the coupon containing the marking
|
||||
* @since 2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3
|
||||
*/
|
||||
public static function mark_recurring_coupon_in_initial_cart_for_hiding( $coupon_html, $coupon ) {
|
||||
$displaying_initial_cart_totals = false;
|
||||
@@ -124,7 +124,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Add discount types
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function add_discount_types( $discount_types ) {
|
||||
|
||||
@@ -142,7 +142,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Get the discount amount for Subscriptions coupon types
|
||||
*
|
||||
* @since 2.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.10
|
||||
*/
|
||||
public static function get_discount_amount( $discount, $discounting_amount, $item, $single, $coupon ) {
|
||||
|
||||
@@ -158,7 +158,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Get the discount amount which applies for a cart item for subscription coupon types
|
||||
*
|
||||
* @since 2.2.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.13
|
||||
* @param array $cart_item
|
||||
* @param float $discount the original discount amount
|
||||
* @param float $discounting_amount the cart item price/total which the coupon should apply to
|
||||
@@ -317,7 +317,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* Uses methods and data structures introduced in WC 3.0.
|
||||
*
|
||||
* @since 2.2.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.13
|
||||
* @param WC_Order_Item $line_item
|
||||
* @param float $discount the original discount amount
|
||||
* @param float $discounting_amount the line item price/total
|
||||
@@ -368,7 +368,7 @@ class WC_Subscriptions_Coupon {
|
||||
* - 'recurring_fee' for the recurring amount subscription coupon
|
||||
* - 'sign_up_fee' for the sign-up fee subscription coupon
|
||||
*
|
||||
* @since 1.3.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
*/
|
||||
public static function cart_contains_discount( $coupon_type = 'any' ) {
|
||||
|
||||
@@ -399,7 +399,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param WC_Coupon $coupon
|
||||
* @param WC_Discounts $discount Added in WC 3.2 the WC_Discounts object contains information about the coupon being applied to either carts or orders - Optional
|
||||
* @return boolean Whether the coupon is valid or not
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function validate_subscription_coupon( $valid, $coupon, $discount = null ) {
|
||||
|
||||
@@ -429,7 +429,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Check if a subscription coupon is valid for the cart.
|
||||
*
|
||||
* @since 2.2.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.13
|
||||
* @param boolean $valid
|
||||
* @param WC_Coupon $coupon
|
||||
* @return bool whether the coupon is valid
|
||||
@@ -480,7 +480,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Check if a subscription coupon is valid for an order/subscription.
|
||||
*
|
||||
* @since 2.2.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.13
|
||||
* @param WC_Coupon $coupon The subscription coupon being validated. Can accept recurring_fee, recurring_percent, sign_up_fee or sign_up_fee_percent coupon types.
|
||||
* @param WC_Order|WC_Subscription $order The order or subscription object to which the coupon is being applied
|
||||
* @return bool whether the coupon is valid
|
||||
@@ -511,7 +511,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Returns a subscription coupon-specific error if validation failed
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function add_coupon_error( $error ) {
|
||||
|
||||
@@ -529,7 +529,7 @@ class WC_Subscriptions_Coupon {
|
||||
* This function is hooked to "woocommerce_before_calculate_totals" so that WC will calculate a subscription
|
||||
* product's total based on the total of it's price per period and sign up fee (if any).
|
||||
*
|
||||
* @since 1.3.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
*
|
||||
* @param WC_Cart $cart
|
||||
*/
|
||||
@@ -601,7 +601,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* @param string $code coupon code
|
||||
* @return array subtotal
|
||||
* @since 2.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.10
|
||||
*/
|
||||
private static function get_renewal_subtotal( $code ) {
|
||||
|
||||
@@ -636,7 +636,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param int|WC_Product $product_id
|
||||
* @param array $cart_item
|
||||
* @return boolean whether a product is a renewal order line item
|
||||
* @since 2.0.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.10
|
||||
*/
|
||||
private static function is_subscription_renewal_line_item( $product_id, $cart_item ) {
|
||||
|
||||
@@ -665,7 +665,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* @param array $coupon_types
|
||||
* @return array supported coupon types
|
||||
* @since 2.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2
|
||||
*/
|
||||
public static function add_pseudo_coupon_types( $coupon_types ) {
|
||||
return array_merge(
|
||||
@@ -685,7 +685,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param string $label
|
||||
* @param WC_Coupon $coupon
|
||||
* @return string
|
||||
* @since 2.2.8
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.8
|
||||
*/
|
||||
public static function get_pseudo_coupon_label( $label, $coupon ) {
|
||||
// If the coupon is one of our pseudo coupons, rather than displaying "Coupon: discount_renewal" display a nicer label.
|
||||
@@ -724,7 +724,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Checks if a coupon is one of our virtual coupons applied to renewal carts.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $coupon_type The coupon's type.
|
||||
* @return bool Whether the coupon is a recuring cart virtual coupon.
|
||||
@@ -736,7 +736,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Checks if a coupon is one of our recurring coupons.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*
|
||||
* @param string $coupon_type The coupon's type.
|
||||
* @return bool Whether the coupon is a recuring cart virtual coupon.
|
||||
@@ -750,7 +750,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Apply sign up fee or recurring fee discount
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function apply_subscription_discount( $original_price, $cart_item, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0.10', 'Have moved to filtering on "woocommerce_coupon_get_discount_amount" to return discount amount. See: ' . __CLASS__ . '::get_discount_amount()' );
|
||||
@@ -870,7 +870,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Validates a subscription coupon's use for a given product.
|
||||
*
|
||||
* @since 2.5.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.5.4
|
||||
*
|
||||
* @param bool $is_valid Whether the coupon is valid for the product.
|
||||
* @param WC_Product $product The product object.
|
||||
@@ -905,7 +905,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Store how much discount each coupon grants.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @param WC_Cart $cart The WooCommerce cart object.
|
||||
* @param mixed $code
|
||||
* @param mixed $amount
|
||||
@@ -926,7 +926,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Restores discount coupons which had been removed for special subscription calculations.
|
||||
*
|
||||
* @since 1.3.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.5
|
||||
*/
|
||||
public static function restore_coupons( $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -954,7 +954,7 @@ class WC_Subscriptions_Coupon {
|
||||
* This function overrides that by ensuring the limit is accounted for across all recurring carts.
|
||||
* The items which the coupon applied to in initial cart are the items in recurring carts that the coupon will apply to.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.0
|
||||
*
|
||||
* @param int $apply_quantity The item quantity to apply the coupon to.
|
||||
* @param object $item The stdClass cart item object. @see WC_Discounts::set_items_from_cart() for an example of object properties.
|
||||
@@ -1021,7 +1021,7 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Apply sign up fee or recurring fee discount before tax is calculated
|
||||
*
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function apply_subscription_discount_before_tax( $original_price, $cart_item, $cart ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::apply_subscription_discount( $original_price, $cart_item, $cart )' );
|
||||
@@ -1031,8 +1031,8 @@ class WC_Subscriptions_Coupon {
|
||||
/**
|
||||
* Apply sign up fee or recurring fee discount after tax is calculated
|
||||
*
|
||||
* @since 1.2
|
||||
* @version 1.3.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.6
|
||||
*/
|
||||
public static function apply_subscription_discount_after_tax( $coupon, $cart_item, $price ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WooCommerce 2.3 removed after tax discounts. Use ' . __CLASS__ . '::apply_subscription_discount( $original_price, $cart_item, $cart )' );
|
||||
@@ -1045,7 +1045,7 @@ class WC_Subscriptions_Coupon {
|
||||
* this functionality in older versions of WC, so we require 3.2+ to enable this.
|
||||
*
|
||||
* @author Jeremy Pry
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function maybe_add_recurring_coupon_hooks() {
|
||||
_deprecated_function( __METHOD__, '4.0.0' );
|
||||
@@ -1058,7 +1058,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @author Jeremy Pry
|
||||
*
|
||||
* @param int $id The coupon ID.
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function add_coupon_fields( $id ) {
|
||||
_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::add_coupon_fields( $id ) if available' );
|
||||
@@ -1074,7 +1074,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @author Jeremy Pry
|
||||
*
|
||||
* @param int $post_id
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function save_coupon_fields( $post_id ) {
|
||||
_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::save_coupon_fields( $post_id ) if available' );
|
||||
@@ -1089,7 +1089,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @author Jeremy Pry
|
||||
*
|
||||
* @param WC_Subscription $subscription The current subscription.
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function check_coupon_usages( $subscription ) {
|
||||
_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::check_coupon_usages( $subscription ) if available' );
|
||||
@@ -1105,7 +1105,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* @param string $column_name The name of the current column in the table.
|
||||
* @param int $post_id The coupon post ID.
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function add_limit_to_list_table( $column_name, $post_id ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::add_limit_to_list_table( $column_name, $post_id ) if available' );
|
||||
@@ -1122,7 +1122,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param WC_Payment_Gateway[] $gateways The available payment gateways.
|
||||
*
|
||||
* @return array The filtered payment gateways.
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function gateways_subscription_amount_changes( $gateways ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::gateways_subscription_amount_changes( $gateways ) if available' );
|
||||
@@ -1141,7 +1141,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @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.
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function no_available_payment_methods_message( $message ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::no_available_payment_methods_message() if available' );
|
||||
@@ -1156,7 +1156,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param string $code The coupon code.
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function coupon_is_limited( $code ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::coupon_is_limited() if available' );
|
||||
@@ -1172,7 +1172,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* @author Jeremy Pry
|
||||
* @return bool
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function cart_contains_limited_recurring_coupon() {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::cart_contains_limited_recurring_coupon() if available' );
|
||||
@@ -1191,7 +1191,7 @@ class WC_Subscriptions_Coupon {
|
||||
* @param WC_Order|WC_Subscription $order
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function order_has_limited_recurring_coupon( $order ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::order_has_limited_recurring_coupon( $order ) if available' );
|
||||
@@ -1211,7 +1211,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* @return false|int False for non-recurring coupons, or the limit number for recurring coupons.
|
||||
* A value of 0 is for unlimited usage.
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function get_coupon_limit( $code ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::get_coupon_limit( $code ) if available' );
|
||||
@@ -1227,7 +1227,7 @@ class WC_Subscriptions_Coupon {
|
||||
*
|
||||
* @param WC_Cart $recurring_cart The recurring cart object.
|
||||
* @return bool
|
||||
* @deprecated 4.0.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v4.0.0
|
||||
*/
|
||||
public static function recurring_cart_contains_expiring_coupon( $recurring_cart ) {
|
||||
wcs_deprecated_function( __METHOD__, '4.0.0', 'WCS_Limited_Recurring_Coupon_Manager::recurring_cart_contains_expiring_coupon( $recurring_cart ) if available' );
|
||||
|
546
vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-data-copier.php
vendored
Normal file
546
vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-data-copier.php
vendored
Normal file
@@ -0,0 +1,546 @@
|
||||
<?php
|
||||
/**
|
||||
* Woocommerce Subscriptions Data Copier
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class WC_Subscriptions_Data_Copier {
|
||||
|
||||
/**
|
||||
* The default copy type.
|
||||
*/
|
||||
const DEFAULT_COPY_TYPE = 'subscription';
|
||||
|
||||
/**
|
||||
* The default data keys that are excluded from the copy.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
const DEFAULT_EXCLUDED_META_KEYS = [
|
||||
'_paid_date',
|
||||
'_date_paid',
|
||||
'_completed_date',
|
||||
'_date_completed',
|
||||
'_edit_last',
|
||||
'_subscription_switch_data',
|
||||
'_order_key',
|
||||
'_edit_lock',
|
||||
'_wc_points_earned',
|
||||
'_transaction_id',
|
||||
'_billing_interval',
|
||||
'_billing_period',
|
||||
'_subscription_resubscribe',
|
||||
'_subscription_renewal',
|
||||
'_subscription_switch',
|
||||
'_payment_method',
|
||||
'_payment_method_title',
|
||||
'_suspension_count',
|
||||
'_requires_manual_renewal',
|
||||
'_cancelled_email_sent',
|
||||
'_trial_period',
|
||||
'_created_via',
|
||||
'_order_stock_reduced',
|
||||
];
|
||||
|
||||
/**
|
||||
* The subscription or order being copied.
|
||||
*
|
||||
* @var WC_Order
|
||||
*/
|
||||
private $from_object = null;
|
||||
|
||||
/**
|
||||
* The subscription or order being copied to.
|
||||
*
|
||||
* @var WC_Order
|
||||
*/
|
||||
private $to_object = null;
|
||||
|
||||
/**
|
||||
* The type of copy. Can be 'subscription' or 'renewal'.
|
||||
*
|
||||
* Used in dynamic filters to allow third parties to target specific meta keys in different copying contexts.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $copy_type = '';
|
||||
|
||||
/**
|
||||
* Copies data from one object to another.
|
||||
*
|
||||
* This function acts as a publicly accessible wrapper for obtaining an instance of the copier and completing the copy.
|
||||
*
|
||||
* @param WC_Order $from_object The object to copy data from.
|
||||
* @param WC_Order $to_object The object to copy data to.
|
||||
* @param string $copy_type Optional. The type of copy. Can be 'subscription', 'parent', 'renewal_order' or 'resubscribe_order'. Default is 'subscription'.
|
||||
*/
|
||||
public static function copy( $from_object, $to_object, $copy_type = self::DEFAULT_COPY_TYPE ) {
|
||||
$instance = new self( $from_object, $to_object, $copy_type );
|
||||
$instance->copy_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param WC_Order $from_object The object to copy data from.
|
||||
* @param WC_Order $to_object The object to copy data to.
|
||||
* @param string $copy_type Optional. The type of copy. Can be 'subscription', 'parent', 'renewal_order' or 'resubscribe_order'. Default is 'subscription'.
|
||||
*/
|
||||
public function __construct( $from_object, $to_object, $copy_type = self::DEFAULT_COPY_TYPE ) {
|
||||
$this->from_object = $from_object;
|
||||
$this->to_object = $to_object;
|
||||
$this->copy_type = $copy_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the data from the "from" object to the "to" object.
|
||||
*/
|
||||
public function copy_data() {
|
||||
|
||||
if ( ! wcs_is_custom_order_tables_usage_enabled() ) {
|
||||
$data_array = $GLOBALS['wpdb']->get_results( $this->get_deprecated_meta_query(), ARRAY_A );
|
||||
$data = wp_list_pluck( $data_array, 'meta_value', 'meta_key' );
|
||||
} else {
|
||||
$data = $this->get_meta_data();
|
||||
$data += $this->get_order_data();
|
||||
$data += $this->get_operational_data();
|
||||
$data += $this->get_address_data();
|
||||
|
||||
// Payment token meta isn't accounted from in the above methods, so we need to add it separately.
|
||||
if ( ! isset( $data['_payment_tokens'] ) ) {
|
||||
$tokens = $this->from_object->get_payment_tokens();
|
||||
|
||||
if ( ! empty( $tokens ) ) {
|
||||
$data['_payment_tokens'] = $tokens;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any excluded meta keys.
|
||||
$data = $this->filter_excluded_meta_keys_via_query( $data );
|
||||
}
|
||||
|
||||
$data = $this->apply_deprecated_filter( $data );
|
||||
|
||||
/**
|
||||
* Filters the data to be copied from one object to another.
|
||||
*
|
||||
* This filter name contains a dynamic part, $this->copy_type. The full set of hooks include:
|
||||
* - wc_subscriptions_subscription_data
|
||||
* - wc_subscriptions_parent_data
|
||||
* - wc_subscriptions_renewal_order_data
|
||||
* - wc_subscriptions_resubscribe_order_data
|
||||
*
|
||||
* @since subscriptions-core 2.5.0
|
||||
*
|
||||
* @param array $data {
|
||||
* The data to be copied to the "to" object. Each value is keyed by the meta key. Example format [ '_meta_key' => 'meta_value' ].
|
||||
*
|
||||
* @type mixed $meta_value The meta value to be copied.
|
||||
* }
|
||||
* @param WC_Order $from_object The object to copy data from.
|
||||
* @param WC_Order $to_object The object to copy data to.
|
||||
*/
|
||||
$data = apply_filters( "wc_subscriptions_{$this->copy_type}_data", $data, $this->to_object, $this->from_object );
|
||||
|
||||
/**
|
||||
* Filters the data to be copied from one object to another.
|
||||
*
|
||||
* @since subscriptions-core 2.5.0
|
||||
*
|
||||
* @param array $data {
|
||||
* The data to be copied to the "to" object. Each value is keyed by the meta key. Example format [ '_meta_key' => 'meta_value' ].
|
||||
*
|
||||
* @type mixed $meta_value The meta value to be copied.
|
||||
* }
|
||||
* @param WC_Order $from_object The object to copy data from.
|
||||
* @param WC_Order $to_object The object to copy data to.
|
||||
*/
|
||||
$data = apply_filters( 'wc_subscriptions_object_data', $data, $this->to_object, $this->from_object, $this->copy_type );
|
||||
|
||||
foreach ( $data as $key => $value ) {
|
||||
$this->set_data( $key, maybe_unserialize( $value ) );
|
||||
}
|
||||
|
||||
$this->to_object->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a piece of data on the "to" object.
|
||||
*
|
||||
* This function uses a setter where appropriate, otherwise it sets the data directly.
|
||||
* Values which are stored as a bool in memory are converted before being set. eg 'no' -> false, 'yes' -> true.
|
||||
*
|
||||
* @param string $key The data key to set.
|
||||
* @param mixed $value The value to set.
|
||||
*/
|
||||
private function set_data( $key, $value ) {
|
||||
|
||||
// WC will automatically set/update these keys when a shipping/billing address attribute changes so we can ignore these keys.
|
||||
if ( in_array( $key, [ '_shipping_address_index', '_billing_address_index' ], true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The WC_Order setter for these keys will expect an array of values, return early if the value is not an array.
|
||||
if (
|
||||
in_array( $key, [ '_shipping_address', '_shipping', '_billing_address', '_billing' ], true )
|
||||
&& ! is_array( $value )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Special cases where properties with setters don't map nicely to their function names.
|
||||
$setter_map = [
|
||||
'_cart_discount' => 'set_discount_total',
|
||||
'_cart_discount_tax' => 'set_discount_tax',
|
||||
'_customer_user' => 'set_customer_id',
|
||||
'_order_tax' => 'set_cart_tax',
|
||||
'_order_shipping' => 'set_shipping_total',
|
||||
'_order_currency' => 'set_currency',
|
||||
'_order_shipping_tax' => 'set_shipping_tax',
|
||||
'_order_total' => 'set_total',
|
||||
'_order_version' => 'set_version',
|
||||
];
|
||||
|
||||
$setter = isset( $setter_map[ $key ] ) ? $setter_map[ $key ] : 'set_' . ltrim( $key, '_' );
|
||||
|
||||
if ( is_callable( [ $this->to_object, $setter ] ) ) {
|
||||
// Re-bool the value before setting it. Setters like `set_prices_include_tax()` expect a bool.
|
||||
if ( is_string( $value ) && in_array( $value, [ 'yes', 'no' ], true ) ) {
|
||||
$value = 'yes' === $value;
|
||||
}
|
||||
|
||||
$this->to_object->{$setter}( $value );
|
||||
} elseif ( '_payment_tokens' === $key ) {
|
||||
// Payment tokens don't have a setter and cannot be set via metadata so we need to set them via the datastore.
|
||||
$this->to_object->get_data_store()->update_payment_token_ids( $this->to_object, $value );
|
||||
} else {
|
||||
$this->to_object->update_meta_data( $key, $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if there are callbacks attached to the deprecated "wcs_{$this->copy_type}_meta_query" filter.
|
||||
*
|
||||
* @return bool True if there are callbacks attached to the deprecated "wcs_{$this->copy_type}_meta_query" filter. False otherwise.
|
||||
*/
|
||||
private function has_filter_on_meta_query_hook() {
|
||||
return has_filter( "wcs_{$this->copy_type}_meta_query" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the "from" object's meta data.
|
||||
*
|
||||
* @return string[] The meta data.
|
||||
*/
|
||||
private function get_meta_data() {
|
||||
$meta_data = [];
|
||||
|
||||
foreach ( $this->from_object->get_meta_data() as $meta ) {
|
||||
$meta_data[ $meta->key ] = $meta->value;
|
||||
}
|
||||
|
||||
return $meta_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the "from" object's operational data that was previously stored in wp post meta.
|
||||
*
|
||||
* @return string[] The operational data with the legacy meta key.
|
||||
*/
|
||||
private function get_operational_data() {
|
||||
return [
|
||||
'_created_via' => $this->from_object->get_created_via( 'edit' ),
|
||||
'_order_version' => $this->from_object->get_version( 'edit' ),
|
||||
'_prices_include_tax' => wc_bool_to_string( $this->from_object->get_prices_include_tax( 'edit' ) ),
|
||||
'_recorded_coupon_usage_counts' => wc_bool_to_string( $this->from_object->get_recorded_coupon_usage_counts( 'edit' ) ),
|
||||
'_download_permissions_granted' => wc_bool_to_string( $this->from_object->get_download_permissions_granted( 'edit' ) ),
|
||||
'_cart_hash' => $this->from_object->get_cart_hash( 'edit' ),
|
||||
'_new_order_email_sent' => wc_bool_to_string( $this->from_object->get_new_order_email_sent( 'edit' ) ),
|
||||
'_order_key' => $this->from_object->get_order_key( 'edit' ),
|
||||
'_order_stock_reduced' => $this->from_object->get_order_stock_reduced( 'edit' ),
|
||||
'_date_paid' => $this->from_object->get_date_paid( 'edit' ),
|
||||
'_date_completed' => $this->from_object->get_date_completed( 'edit' ),
|
||||
'_order_shipping_tax' => $this->from_object->get_shipping_tax( 'edit' ),
|
||||
'_order_shipping' => $this->from_object->get_shipping_total( 'edit' ),
|
||||
'_cart_discount_tax' => $this->from_object->get_discount_tax( 'edit' ),
|
||||
'_cart_discount' => $this->from_object->get_discount_total( 'edit' ),
|
||||
'_recorded_sales' => wc_bool_to_string( $this->from_object->get_recorded_sales( 'edit' ) ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the "from" object's core data that was previously stored in wp post meta.
|
||||
*
|
||||
* @return string[] The core data with the legacy meta keys.
|
||||
*/
|
||||
private function get_order_data() {
|
||||
return [
|
||||
'_order_currency' => $this->from_object->get_currency( 'edit' ),
|
||||
'_order_tax' => $this->from_object->get_cart_tax( 'edit' ),
|
||||
'_order_total' => $this->from_object->get_total( 'edit' ),
|
||||
'_customer_user' => $this->from_object->get_customer_id( 'edit' ),
|
||||
'_billing_email' => $this->from_object->get_billing_email( 'edit' ),
|
||||
'_payment_method' => $this->from_object->get_payment_method( 'edit' ),
|
||||
'_payment_method_title' => $this->from_object->get_payment_method_title( 'edit' ),
|
||||
'_customer_ip_address' => $this->from_object->get_customer_ip_address( 'edit' ),
|
||||
'_customer_user_agent' => $this->from_object->get_customer_user_agent( 'edit' ),
|
||||
'_transaction_id' => $this->from_object->get_transaction_id( 'edit' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the "from" object's address data that was previously stored in wp post meta.
|
||||
*
|
||||
* @return string[] The address data with the legacy meta keys.
|
||||
*/
|
||||
private function get_address_data() {
|
||||
return array_filter(
|
||||
[
|
||||
'_billing_first_name' => $this->from_object->get_billing_first_name( 'edit' ),
|
||||
'_billing_last_name' => $this->from_object->get_billing_last_name( 'edit' ),
|
||||
'_billing_company' => $this->from_object->get_billing_company( 'edit' ),
|
||||
'_billing_address_1' => $this->from_object->get_billing_address_1( 'edit' ),
|
||||
'_billing_address_2' => $this->from_object->get_billing_address_2( 'edit' ),
|
||||
'_billing_city' => $this->from_object->get_billing_city( 'edit' ),
|
||||
'_billing_state' => $this->from_object->get_billing_state( 'edit' ),
|
||||
'_billing_postcode' => $this->from_object->get_billing_postcode( 'edit' ),
|
||||
'_billing_country' => $this->from_object->get_billing_country( 'edit' ),
|
||||
'_billing_email' => $this->from_object->get_billing_email( 'edit' ),
|
||||
'_billing_phone' => $this->from_object->get_billing_phone( 'edit' ),
|
||||
'_shipping_first_name' => $this->from_object->get_shipping_first_name( 'edit' ),
|
||||
'_shipping_last_name' => $this->from_object->get_shipping_last_name( 'edit' ),
|
||||
'_shipping_company' => $this->from_object->get_shipping_company( 'edit' ),
|
||||
'_shipping_address_1' => $this->from_object->get_shipping_address_1( 'edit' ),
|
||||
'_shipping_address_2' => $this->from_object->get_shipping_address_2( 'edit' ),
|
||||
'_shipping_city' => $this->from_object->get_shipping_city( 'edit' ),
|
||||
'_shipping_state' => $this->from_object->get_shipping_state( 'edit' ),
|
||||
'_shipping_postcode' => $this->from_object->get_shipping_postcode( 'edit' ),
|
||||
'_shipping_country' => $this->from_object->get_shipping_country( 'edit' ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the meta keys excluded via the deprecated from the set of data to be copied.
|
||||
*
|
||||
* @param array $data The data to be copied.
|
||||
* @return array The data to be copied with the excluded keys removed.
|
||||
*/
|
||||
public function filter_excluded_meta_keys_via_query( $data ) {
|
||||
$excluded_keys = $this->get_excluded_data_keys();
|
||||
|
||||
foreach ( $data as $meta_key => $meta_value ) {
|
||||
if ( isset( $excluded_keys['in'] ) && in_array( $meta_key, $excluded_keys['in'], true ) ) {
|
||||
unset( $data[ $meta_key ] );
|
||||
} elseif ( isset( $excluded_keys['regex'] ) ) {
|
||||
foreach ( $excluded_keys['regex'] as $regex ) {
|
||||
if ( preg_match( $regex, $meta_key ) ) {
|
||||
unset( $data[ $meta_key ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the deprecated meta database query that returns the "from" objects meta data.
|
||||
*
|
||||
* Triggers a deprecation notice if the deprecated "wcs_{$this->copy_type}_meta_query" filter is in use by at least 1 third-party.
|
||||
*
|
||||
* @return string SQL SELECT query.
|
||||
*/
|
||||
private function get_deprecated_meta_query() {
|
||||
global $wpdb;
|
||||
|
||||
$meta_query = sprintf(
|
||||
"SELECT `meta_key`, `meta_value`
|
||||
FROM %s
|
||||
WHERE `post_id` = %d
|
||||
AND `meta_key` NOT LIKE '%s'
|
||||
AND `meta_key` NOT IN ('%s')",
|
||||
$wpdb->postmeta,
|
||||
$this->from_object->get_id(),
|
||||
'_schedule_%',
|
||||
implode( "', '", self::DEFAULT_EXCLUDED_META_KEYS )
|
||||
);
|
||||
|
||||
if ( in_array( $this->copy_type, [ 'renewal_order', 'parent' ], true ) ) {
|
||||
$meta_query .= " AND `meta_key` NOT LIKE '_download_permissions_granted' ";
|
||||
}
|
||||
|
||||
if ( $this->has_filter_on_meta_query_hook() ) {
|
||||
/**
|
||||
* Filters the data to be copied from one object to another.
|
||||
*
|
||||
* This filter name contains a dynamic part, $this->copy_type. The full set of hooks include:
|
||||
* - wcs_subscription_meta_query
|
||||
* - wcs_parent_meta_query
|
||||
* - wcs_renewal_order_meta_query
|
||||
* - wcs_resubscribe_order_meta_query
|
||||
*
|
||||
* @deprecated subscriptions-core 2.5.0
|
||||
*
|
||||
* @param string $meta_query The SQL query to fetch the meta data to be copied.
|
||||
* @param WC_Order $this->to_object The object to copy data to.
|
||||
* @param WC_Order $this->from_object The object to copy data from.
|
||||
*/
|
||||
$meta_query = apply_filters( "wcs_{$this->copy_type}_meta_query", $meta_query, $this->to_object, $this->from_object );
|
||||
wcs_deprecated_hook( "wcs_{$this->copy_type}_meta_query", 'subscriptions-core 2.5.0', "wc_subscriptions_{$this->copy_type}_data" );
|
||||
}
|
||||
|
||||
return $meta_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the deprecated "wcs_{$this->copy_type}_meta filter.
|
||||
*
|
||||
* Triggers a deprecation notice if the deprecated "wcs_{$this->copy_type}_meta" filter is in use by at least 1 third-party.
|
||||
*
|
||||
* @param array $data The data to copy.
|
||||
* @return array The filtered set of data to copy.
|
||||
*/
|
||||
private function apply_deprecated_filter( $data ) {
|
||||
// Only continue if the filter is use.
|
||||
if ( ! has_filter( "wcs_{$this->copy_type}_meta" ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Convert the data into the backwards compatible format ready for filtering - wpdb's ARRAY_A format.
|
||||
$data_array = [];
|
||||
|
||||
foreach ( $data as $key => $value ) {
|
||||
$data_array[] = [
|
||||
'meta_key' => $key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- This is a meta key, not a query.
|
||||
'meta_value' => $value, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- This is a meta value, not a query.
|
||||
];
|
||||
}
|
||||
|
||||
wcs_deprecated_hook( "wcs_{$this->copy_type}_meta", 'wcs-core 2.5.0', "wc_subscriptions_{$this->copy_type}_data" );
|
||||
|
||||
/**
|
||||
* Filters the data to be copied from one object to another.
|
||||
*
|
||||
* This filter name contains a dynamic part, $this->copy_type. The full set of hooks include:
|
||||
* - wcs_subscription_meta
|
||||
* - wcs_parent_meta
|
||||
* - wcs_renewal_order_meta
|
||||
* - wcs_resubscribe_order_meta
|
||||
*
|
||||
* @deprecated subscriptions-core 2.5.0
|
||||
*
|
||||
* @param array[] $data_array {
|
||||
* The metadata to be copied to the "to" object.
|
||||
*
|
||||
* @type array $meta_data {
|
||||
* The metadata to be copied.
|
||||
*
|
||||
* @type string $meta_key The meta key to be copied.
|
||||
* @type mixed $meta_value The meta value to be copied.
|
||||
* }
|
||||
* }
|
||||
* @param WC_Order $this->to_object The object to copy data to.
|
||||
* @param WC_Order $this->from_object The object to copy data from.
|
||||
*/
|
||||
$data_array = apply_filters( "wcs_{$this->copy_type}_meta", $data_array, $this->to_object, $this->from_object );
|
||||
|
||||
// Return the data to a key => value format.
|
||||
return wp_list_pluck( $data_array, 'meta_value', 'meta_key' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of meta keys to exclude from the copy.
|
||||
*
|
||||
* If third-parties are hooked onto the "wcs_{$this->copy_type}_meta_query" filter, this function will attempt
|
||||
* to pluck the excluded meta keys from the filtered SQL query. There is no guarantee that this will work for all
|
||||
* queries, however it should work under most standard circumstances.
|
||||
*
|
||||
* If no third-parties are hooked onto the "wcs_{$this->copy_type}_meta_query" filter, this function will simply return
|
||||
* the default list of excluded meta keys.
|
||||
*
|
||||
* @return string[][] An array of excluded meta keys. The array has two keys: 'in' and 'regex'. The 'in' key contains an array of meta keys to exclude. The 'regex' key contains an array of regular expressions to exclude.
|
||||
*/
|
||||
private function get_excluded_data_keys() {
|
||||
$excluded_keys = [];
|
||||
|
||||
// If there are no third-parties hooked into the deprecated filter, there is no need to parse the query.
|
||||
if ( ! $this->has_filter_on_meta_query_hook() ) {
|
||||
$excluded_keys['in'] = self::DEFAULT_EXCLUDED_META_KEYS;
|
||||
|
||||
if ( in_array( $this->copy_type, [ 'renewal_order', 'parent' ], true ) ) {
|
||||
$excluded_keys['regex'][] = $this->get_keys_from_like_clause( '_download_permissions_granted' );
|
||||
}
|
||||
|
||||
return $excluded_keys;
|
||||
}
|
||||
|
||||
// Get the deprecated meta query and attempt to pull the excluded keys from it.
|
||||
$meta_query = $this->get_deprecated_meta_query();
|
||||
|
||||
// Normalize the query.
|
||||
$meta_query = str_replace( [ "\r", "\n", "\t" ], ' ', $meta_query ); // Remove line breaks, tabs, etc.
|
||||
$meta_query = preg_replace( '/\s+/', ' ', $meta_query ); // Remove duplicate whitespace.
|
||||
$meta_query = str_replace( '`', '', $meta_query ); // Remove backticks.
|
||||
$meta_query = str_replace( '"', "'", $meta_query ); // Replace double quotes with single quotes.
|
||||
|
||||
// Handle all the NOT LIKE clauses.
|
||||
preg_match_all( "/meta_key NOT LIKE '(.*?)'/", $meta_query, $not_like_clauses );
|
||||
|
||||
if ( ! empty( $not_like_clauses[1] ) ) {
|
||||
foreach ( $not_like_clauses[1] as $not_like_clause ) {
|
||||
$excluded_keys['regex'][] = $this->get_keys_from_like_clause( $not_like_clause );
|
||||
}
|
||||
}
|
||||
|
||||
// Handle all the NOT IN clauses.
|
||||
preg_match_all( '/meta_key NOT IN \((.*?)\)/', $meta_query, $not_in_clauses );
|
||||
|
||||
if ( ! empty( $not_in_clauses[1] ) ) {
|
||||
$excluded_keys['in'] = [];
|
||||
foreach ( $not_in_clauses[1] as $not_in_clause ) {
|
||||
$excluded_keys['in'] = array_merge( $excluded_keys['in'], $this->get_keys_from_in_clause( $not_in_clause ) );
|
||||
}
|
||||
}
|
||||
|
||||
return $excluded_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of meta keys from a SQL IN clause.
|
||||
*
|
||||
* @param string $in_clause The concatenated string of meta keys from the IN clause. eg: '_paid_date', '_date_paid', '_completed_date' ...
|
||||
* @return string[] The meta keys from the IN clause. eg: [ '_paid_date', '_date_paid', '_completed_date' ]
|
||||
*/
|
||||
private function get_keys_from_in_clause( $in_clause ) {
|
||||
// Remove single quotes.
|
||||
$in_keys = str_replace( "'", '', $in_clause );
|
||||
|
||||
// Split into an array.
|
||||
$in_keys = explode( ',', $in_keys );
|
||||
|
||||
// Trim whitespace from each key.
|
||||
$in_keys = array_map( 'trim', $in_keys );
|
||||
|
||||
return $in_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a LIKE clause into a regex pattern.
|
||||
*
|
||||
* @param string $like_clause A SQL LIKE clause. eg: '_schedule_%%'
|
||||
* @return string A regex pattern. eg: '/^_schedule_.*$/'
|
||||
*/
|
||||
private function get_keys_from_like_clause( $like_clause ) {
|
||||
// Remove the surrounding quotes.
|
||||
$like_clause = str_replace( "'", '', $like_clause );
|
||||
|
||||
// Replace the wildcard with a regex wildcard.
|
||||
$like_clause = str_replace( '%', '.*?', $like_clause );
|
||||
|
||||
// Add the regex wildcard to the beginning and end of the string.
|
||||
return '^' . trim( $like_clause ) . '$^';
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@ class WC_Subscriptions_Email {
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -31,7 +31,7 @@ class WC_Subscriptions_Email {
|
||||
/**
|
||||
* Add Subscriptions' email classes.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function add_emails( $email_classes ) {
|
||||
$email_classes['WCS_Email_New_Renewal_Order'] = new WCS_Email_New_Renewal_Order();
|
||||
@@ -51,7 +51,7 @@ class WC_Subscriptions_Email {
|
||||
/**
|
||||
* Hooks up all of Subscription's transaction emails after the WooCommerce object is constructed.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function hook_transactional_emails() {
|
||||
|
||||
@@ -105,7 +105,7 @@ class WC_Subscriptions_Email {
|
||||
* Init the mailer and call for the cancelled email notification hook.
|
||||
*
|
||||
* @param $subscription WC Subscription
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function send_cancelled_email( $subscription ) {
|
||||
WC()->mailer();
|
||||
@@ -119,7 +119,7 @@ class WC_Subscriptions_Email {
|
||||
* Init the mailer and call for the expired email notification hook.
|
||||
*
|
||||
* @param $subscription WC Subscription
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function send_expired_email( $subscription ) {
|
||||
WC()->mailer();
|
||||
@@ -131,7 +131,7 @@ class WC_Subscriptions_Email {
|
||||
* Init the mailer and call for the suspended email notification hook.
|
||||
*
|
||||
* @param $subscription WC Subscription
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function send_on_hold_email( $subscription ) {
|
||||
WC()->mailer();
|
||||
@@ -261,7 +261,7 @@ class WC_Subscriptions_Email {
|
||||
* @param bool $sent_to_admin Whether the email is sent to admin - defaults to false
|
||||
* @param bool $plain_text Whether the email should use plain text templates - defaults to false
|
||||
* @param WC_Email $email
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
|
||||
|
||||
@@ -297,7 +297,7 @@ class WC_Subscriptions_Email {
|
||||
*
|
||||
* @param string Optional. The action hook or filter to detach WC core's transactional emails from. Defaults to the current filter.
|
||||
* @param int Optional. The priority the function runs on. Default 10.
|
||||
* @since 2.2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.3
|
||||
*/
|
||||
public static function detach_woocommerce_transactional_email( $hook = '', $priority = 10 ) {
|
||||
|
||||
@@ -316,7 +316,7 @@ class WC_Subscriptions_Email {
|
||||
* @param string Optional. The action hook or filter to attach WC core's transactional emails to. Defaults to the current filter.
|
||||
* @param int Optional. The priority the function should run on. Default 10.
|
||||
* @param int Optional. The number of arguments the function accepts. Default 10.
|
||||
* @since 2.2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.3
|
||||
*/
|
||||
public static function attach_woocommerce_transactional_email( $hook = '', $priority = 10, $accepted_args = 10 ) {
|
||||
|
||||
@@ -338,7 +338,7 @@ class WC_Subscriptions_Email {
|
||||
* @param bool $sent_to_admin Whether the email is sent to admin - defaults to false
|
||||
* @param bool $plain_text Whether the email should use plain text templates - defaults to false
|
||||
* @param WC_Email $email
|
||||
* @since 2.2.17
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.17
|
||||
*/
|
||||
public static function order_download_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
|
||||
if ( is_callable( array( 'WC_Emails', 'order_downloads' ) ) ) {
|
||||
@@ -352,7 +352,7 @@ class WC_Subscriptions_Email {
|
||||
* @param int $user_id The ID of the user who the subscription belongs to
|
||||
* @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
|
||||
* @return void
|
||||
* @deprecated 2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function send_subscription_email( $user_id, $subscription_key ) {
|
||||
_deprecated_function( __FUNCTION__, '2.0' );
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* for each subscription item
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since WCBLOCKS-DEV
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Package;
|
||||
@@ -46,7 +46,7 @@ class WC_Subscriptions_Extend_Store_Endpoint {
|
||||
/**
|
||||
* Bootstraps the class and hooks required data.
|
||||
*
|
||||
* @since WCBLOCKS-DEV
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions
|
||||
*/
|
||||
public static function init() {
|
||||
self::$schema = class_exists( 'Automattic\WooCommerce\StoreApi\StoreApi' ) ? Automattic\WooCommerce\StoreApi\StoreApi::container()->get( Automattic\WooCommerce\StoreApi\SchemaController::class ) : Package::container()->get( Automattic\WooCommerce\Blocks\StoreApi\SchemaController::class );
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* Enqueues WC Subscriptions frontend scripts.
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 3.1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.3
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
@@ -21,7 +21,7 @@ class WC_Subscriptions_Frontend_Scripts {
|
||||
/**
|
||||
* Gets the plugin URL for an assets file.
|
||||
*
|
||||
* @since 3.1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.3
|
||||
* @return string The file URL.
|
||||
*/
|
||||
public static function get_file_url( $file_relative_url = '' ) {
|
||||
@@ -31,15 +31,15 @@ class WC_Subscriptions_Frontend_Scripts {
|
||||
/**
|
||||
* Enqueues scripts for frontend.
|
||||
*
|
||||
* @since 3.1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.3
|
||||
*/
|
||||
public static function enqueue_scripts() {
|
||||
$dependencies = array( 'jquery' );
|
||||
|
||||
if ( is_cart() || is_checkout() ) {
|
||||
wp_enqueue_script( 'wcs-cart', self::get_file_url( 'assets/js/frontend/wcs-cart.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_plugin_version(), true );
|
||||
wp_enqueue_script( 'wcs-cart', self::get_file_url( 'assets/js/frontend/wcs-cart.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_library_version(), true );
|
||||
} elseif ( is_product() ) {
|
||||
wp_enqueue_script( 'wcs-single-product', self::get_file_url( 'assets/js/frontend/single-product.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_plugin_version(), true );
|
||||
wp_enqueue_script( 'wcs-single-product', self::get_file_url( 'assets/js/frontend/single-product.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_library_version(), true );
|
||||
} elseif ( wcs_is_view_subscription_page() ) {
|
||||
$subscription = wcs_get_subscription( absint( get_query_var( 'view-subscription' ) ) );
|
||||
|
||||
@@ -54,7 +54,7 @@ class WC_Subscriptions_Frontend_Scripts {
|
||||
'has_payment_gateway' => $subscription->has_payment_gateway() && wc_get_payment_gateway_by_order( $subscription )->supports( 'subscriptions' ),
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'wcs-view-subscription', self::get_file_url( 'assets/js/frontend/view-subscription.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_plugin_version(), true );
|
||||
wp_enqueue_script( 'wcs-view-subscription', self::get_file_url( 'assets/js/frontend/view-subscription.js' ), $dependencies, WC_Subscriptions_Core_Plugin::instance()->get_library_version(), true );
|
||||
wp_localize_script( 'wcs-view-subscription', 'WCSViewSubscription', apply_filters( 'woocommerce_subscriptions_frontend_view_subscription_script_parameters', $script_params ) );
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class WC_Subscriptions_Frontend_Scripts {
|
||||
/**
|
||||
* Enqueues stylesheets.
|
||||
*
|
||||
* @since 3.1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.3
|
||||
*/
|
||||
public static function enqueue_styles( $styles ) {
|
||||
|
||||
@@ -78,7 +78,7 @@ class WC_Subscriptions_Frontend_Scripts {
|
||||
$styles['wcs-view-subscription'] = array(
|
||||
'src' => str_replace( array( 'http:', 'https:' ), '', self::get_file_url( 'assets/css/view-subscription.css' ) ),
|
||||
'deps' => 'woocommerce-smallscreen',
|
||||
'version' => WC_Subscriptions_Core_Plugin::instance()->get_plugin_version(),
|
||||
'version' => WC_Subscriptions_Core_Plugin::instance()->get_library_version(),
|
||||
'media' => 'all',
|
||||
);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -7,20 +7,9 @@
|
||||
* @package WooCommerce Subscriptions
|
||||
* @subpackage WC_Subscriptions_Order
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
*/
|
||||
class WC_Subscriptions_Order {
|
||||
|
||||
/**
|
||||
* Store a record of which product/item IDs need to have subscriptions details updated
|
||||
* whenever a subscription is saved via the "Edit Order" page.
|
||||
*/
|
||||
private static $requires_update = array(
|
||||
'next_billing_date' => array(),
|
||||
'trial_expiration' => array(),
|
||||
'expiration_date' => array(),
|
||||
);
|
||||
|
||||
/**
|
||||
* A flag to indicate whether subscription price strings should include the subscription length
|
||||
*/
|
||||
@@ -29,7 +18,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -88,7 +77,7 @@ class WC_Subscriptions_Order {
|
||||
* line totals for each non-subscription product.
|
||||
*
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @since 1.5.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.3
|
||||
*/
|
||||
public static function get_non_subscription_total( $order ) {
|
||||
|
||||
@@ -115,7 +104,7 @@ class WC_Subscriptions_Order {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return float The initial sign-up fee charged when the subscription product in the order was first purchased, if any.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_sign_up_fee( $order, $product_id = '' ) {
|
||||
|
||||
@@ -150,7 +139,7 @@ class WC_Subscriptions_Order {
|
||||
* This function checks if the 'product_id' field exists on an order item before falling back to 'id'.
|
||||
*
|
||||
* @param array $order_item An order item in the structure returned by WC_Order::get_items()
|
||||
* @since 1.2.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
*/
|
||||
public static function get_items_product_id( $order_item ) {
|
||||
return ( isset( $order_item['product_id'] ) ) ? $order_item['product_id'] : $order_item['id'];
|
||||
@@ -161,7 +150,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param WC_Order|int $order The WC_Order object or ID of the order for which the meta should be sought.
|
||||
* @param int $product_id The product/post ID of a subscription product.
|
||||
* @since 1.2.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
*/
|
||||
public static function get_item_by_product_id( $order, $product_id = '' ) {
|
||||
|
||||
@@ -183,7 +172,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param WC_Order|int $order The WC_Order object or ID of the order for which the meta should be sought.
|
||||
* @param int $product_id The product/post ID of a subscription product.
|
||||
* @since 1.2.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
*/
|
||||
public static function get_item_by_subscription_key( $subscription_key ) {
|
||||
|
||||
@@ -200,7 +189,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param WC_Order|int $order The WC_Order object or ID of the order for which the meta should be sought.
|
||||
* @param int $product_id The product/post ID of a subscription product.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function get_item_id_by_subscription_key( $subscription_key ) {
|
||||
global $wpdb;
|
||||
@@ -226,7 +215,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order|int $order The WC_Order object or ID of the order for which the meta should be sought.
|
||||
* @param int $item_id The product/post ID of a subscription. Option - if no product id is provided, the first item's meta will be returned
|
||||
* @return array $item An array containing the order_item_id, order_item_name, order_item_type, order_id and any item_meta. Array structure matches that returned by WC_Order::get_items()
|
||||
* @since 1.2.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
*/
|
||||
public static function get_item_by_id( $order_item_id ) {
|
||||
global $wpdb;
|
||||
@@ -261,7 +250,7 @@ class WC_Subscriptions_Order {
|
||||
* @param string $meta_key The key as stored in the post meta table for the meta item.
|
||||
* @param int $product_id The product/post ID of a subscription. Option - if no product id is provided, we will loop through the order and find the subscription
|
||||
* @param mixed $default (optional) The default value to return if the meta key does not exist. Default 0.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_item_meta( $order, $meta_key, $product_id = '', $default = 0 ) {
|
||||
|
||||
@@ -292,7 +281,7 @@ class WC_Subscriptions_Order {
|
||||
* set of parameters.
|
||||
*
|
||||
* @param int $meta_id The order item meta data ID of the item you want to get.
|
||||
* @since 1.2.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
*/
|
||||
public static function get_item_meta_data( $meta_id ) {
|
||||
global $wpdb;
|
||||
@@ -311,7 +300,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param WC_Order|int $order The WC_Order object or ID of the order for which the meta should be sought.
|
||||
* @param int $product_id The product/post ID of a subscription. Option - if no product id is provided, it is expected that only one item exists and the last item's meta will be returned
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_item_name( $order, $product_id = '' ) {
|
||||
|
||||
@@ -330,7 +319,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param int $order_id
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function subscription_thank_you( $order_id ) {
|
||||
if ( wcs_order_contains_subscription( $order_id, 'any' ) ) {
|
||||
@@ -378,7 +367,7 @@ class WC_Subscriptions_Order {
|
||||
* that can result in "requested URL's length exceeds the capacity limit" errors when bulk editing orders.
|
||||
*
|
||||
* @param string $column The string of the current column.
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
*/
|
||||
public static function add_contains_subscription_hidden_field( $column ) {
|
||||
global $post;
|
||||
@@ -394,7 +383,7 @@ class WC_Subscriptions_Order {
|
||||
* in that row contains a subscription or not.
|
||||
*
|
||||
* @param string $column The string of the current column.
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
*/
|
||||
public static function contains_subscription_hidden_field( $order_id ) {
|
||||
|
||||
@@ -408,7 +397,7 @@ class WC_Subscriptions_Order {
|
||||
* parent of a subscription, a renewal order for a subscription, or a regular order.
|
||||
*
|
||||
* @param array $columns The current list of columns
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function add_contains_subscription_column( $columns ) {
|
||||
|
||||
@@ -425,7 +414,7 @@ class WC_Subscriptions_Order {
|
||||
* regular order.
|
||||
*
|
||||
* @param string $column The string of the current column
|
||||
* @since 2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1
|
||||
*/
|
||||
public static function add_contains_subscription_column_content( $column ) {
|
||||
global $post;
|
||||
@@ -446,25 +435,30 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Records the initial payment against a subscription.
|
||||
*
|
||||
* This function is called when an orders status is changed to completed or processing
|
||||
* This function is called when an order's status is changed to completed or processing
|
||||
* for those gateways which never call @see WC_Order::payment_complete(), like the core
|
||||
* WooCommerce Cheque and Bank Transfer gateways.
|
||||
*
|
||||
* It will also set the start date on the subscription to the time the payment is completed.
|
||||
*
|
||||
* @param $order_id int|WC_Order
|
||||
* @param $old_order_status
|
||||
* @param $new_order_status
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*
|
||||
* @param int|WC_Order $order_id The order ID or WC_Order object.
|
||||
* @param string $old_order_status The old order status.
|
||||
* @param string $new_order_status The new order status.
|
||||
*/
|
||||
public static function maybe_record_subscription_payment( $order_id, $old_order_status, $new_order_status ) {
|
||||
|
||||
if ( wcs_order_contains_subscription( $order_id, 'parent' ) ) {
|
||||
if ( ! wcs_order_contains_subscription( $order_id, 'parent' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriptions = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'parent' ) );
|
||||
$was_activated = false;
|
||||
$order = wc_get_order( $order_id );
|
||||
$order_completed = in_array( $new_order_status, array( apply_filters( 'woocommerce_payment_complete_order_status', 'processing', $order_id, $order ), 'processing', 'completed' ) ) && in_array( $old_order_status, apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'on-hold', 'failed' ), $order ) );
|
||||
$paid_statuses = array( apply_filters( 'woocommerce_payment_complete_order_status', 'processing', $order_id, $order ), 'processing', 'completed' );
|
||||
$unpaid_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'on-hold', 'failed' ), $order );
|
||||
$order_completed = in_array( $new_order_status, $paid_statuses, true ) && in_array( $old_order_status, $unpaid_statuses, true );
|
||||
|
||||
foreach ( $subscriptions as $subscription ) {
|
||||
// A special case where payment completes after user cancels subscription
|
||||
@@ -539,7 +533,6 @@ class WC_Subscriptions_Order {
|
||||
do_action( 'subscriptions_activated_for_order', $order_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Order Price Getters */
|
||||
|
||||
@@ -548,7 +541,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @param array $item | int An array representing an order item or a product ID of an item in an order (not an order item ID)
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function is_item_subscription( $order, $order_item ) {
|
||||
|
||||
@@ -578,7 +571,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns all parent subscription orders for a user, specificed with $user_id
|
||||
*
|
||||
* @return array An array of order IDs.
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function get_users_subscription_orders( $user_id = 0 ) {
|
||||
global $wpdb;
|
||||
@@ -681,7 +674,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Adds the subscription information to our order emails.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function add_sub_info_email( $order, $is_admin_email, $plaintext = false ) {
|
||||
|
||||
@@ -708,7 +701,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Add admin dropdown for order types to Woocommerce -> Orders screen
|
||||
*
|
||||
* @since version 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function restrict_manage_subscriptions() {
|
||||
global $typenow;
|
||||
@@ -748,7 +741,7 @@ class WC_Subscriptions_Order {
|
||||
* Including or excluding posts with a '_subscription_renewal' meta value includes or excludes
|
||||
* renewal orders, as required.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function orders_by_type_query( $vars ) {
|
||||
global $typenow, $wpdb;
|
||||
@@ -812,7 +805,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Add related subscriptions below order details tables.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_subscriptions_to_view_order_templates( $order_id ) {
|
||||
|
||||
@@ -835,7 +828,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Loads the related orders table on the view subscription page
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_related_orders_template( $subscription ) {
|
||||
|
||||
@@ -857,7 +850,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Unset pay action for an order if a more recent order exists
|
||||
*
|
||||
* @since 2.2.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.9
|
||||
*/
|
||||
public static function maybe_remove_pay_action( $actions, $order ) {
|
||||
|
||||
@@ -879,7 +872,7 @@ class WC_Subscriptions_Order {
|
||||
* Allow subscription order items to be edited in WC 2.2. until Subscriptions 2.0 introduces
|
||||
* its own WC_Subscription object.
|
||||
*
|
||||
* @since 1.5.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.10
|
||||
*/
|
||||
public static function is_order_editable( $is_editable, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::is_editable()' );
|
||||
@@ -899,7 +892,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order $order A WC_Order object
|
||||
* @param int $product_id The product/post ID of a subscription
|
||||
* @return null|object A subscription from the order, either with an item to the product ID (if any) or just the first subscription purchase in the order.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
private static function get_matching_subscription( $order, $product_id = '' ) {
|
||||
|
||||
@@ -937,7 +930,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order $order A WC_Order object
|
||||
* @param int $product_id The product/post ID of a subscription
|
||||
* @return array The line item for this product on the subscription object
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
private static function get_matching_subscription_item( $order, $product_id = '' ) {
|
||||
|
||||
@@ -957,7 +950,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Don't display migrated subscription meta data on the Edit Order screen
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function hide_order_itemmeta( $hidden_meta_keys ) {
|
||||
|
||||
@@ -1011,7 +1004,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param $order_id
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_cancel_subscription_on_full_refund( $order ) {
|
||||
|
||||
@@ -1039,8 +1032,8 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param $order_id
|
||||
*
|
||||
* @since 2.0
|
||||
* @deprecated 2.3.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.3
|
||||
*/
|
||||
public static function maybe_cancel_subscription_on_partial_refund( $order_id ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.3.3' );
|
||||
@@ -1056,7 +1049,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @return bool $needs_shipping whether an order needs to display the shipping address
|
||||
*
|
||||
* @since 2.0.14
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.14
|
||||
*/
|
||||
public static function maybe_display_shipping_address( $needs_shipping, $hidden_shipping_methods, $order ) {
|
||||
$order_shipping_methods = $order->get_shipping_methods();
|
||||
@@ -1089,7 +1082,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @return string $new_order_status
|
||||
*
|
||||
* @since 2.1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.3
|
||||
*/
|
||||
public static function maybe_autocomplete_order( $new_order_status, $order_id, $order = null ) {
|
||||
// Exit early if the order has no ID, or if the new order status is not 'processing'.
|
||||
@@ -1164,7 +1157,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Map subscription related order arguments passed to @see wc_get_orders() to WP_Query args.
|
||||
*
|
||||
* @since 2.2.20
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.20
|
||||
* @param array $query WP_Query arguments.
|
||||
* @param array $args @see wc_get_orders() arguments.
|
||||
* @return array The WP_Query query arguments.
|
||||
@@ -1232,8 +1225,8 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @return bool True if the order contains a subscription, otherwise false.
|
||||
* @version 1.2
|
||||
* @since 1.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function order_contains_subscription( $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_order_contains_subscription( $order )' );
|
||||
@@ -1246,7 +1239,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* With the advent of a separate subscription object in 2.0, this became unnecessary.
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function set_recurring_payment_method( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1257,7 +1250,7 @@ class WC_Subscriptions_Order {
|
||||
* to files purchased on the order.
|
||||
*
|
||||
* @return bool False if the order contains a subscription that has expired or is cancelled/on-hold, otherwise, the original value of $download_permitted
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function is_download_permitted( $download_permitted, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1271,8 +1264,8 @@ class WC_Subscriptions_Order {
|
||||
* are stored against a 'shop_subscription' post, not the 'shop_order' used to purchase the subscription.
|
||||
*
|
||||
* @param item_id int An order_item_id as returned by the insert statement of @see woocommerce_add_order_item()
|
||||
* @since 1.2.5
|
||||
* @version 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.5
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
* @return void
|
||||
*/
|
||||
public static function prefill_order_item_meta( $item, $item_id ) {
|
||||
@@ -1287,7 +1280,7 @@ class WC_Subscriptions_Order {
|
||||
* are stored against a 'shop_subscription' post, not the 'shop_order' used to purchase the subscription.
|
||||
*
|
||||
* Based on the @see woocommerce_calc_line_taxes() function.
|
||||
* @since 1.2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.4
|
||||
* @return void
|
||||
*/
|
||||
public static function calculate_recurring_line_taxes() {
|
||||
@@ -1332,7 +1325,7 @@ class WC_Subscriptions_Order {
|
||||
* are stored against a 'shop_subscription' post, not the 'shop_order' used to purchase the subscription.
|
||||
*
|
||||
* @param int $post_id The post ID of the shop_order post object.
|
||||
* @since 1.2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.4
|
||||
* @return void
|
||||
*/
|
||||
public static function recurring_order_totals_meta_box_section( $post_id ) {
|
||||
@@ -1349,7 +1342,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param int $post_id The ID of the post which is the WC_Order object.
|
||||
* @param Object $post The post object of the order.
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
*/
|
||||
public static function pre_process_shop_order_meta( $post_id, $post ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1363,7 +1356,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param int $post_id The ID of the post which is the WC_Order object.
|
||||
* @param Object $post The post object of the order.
|
||||
* @since 1.2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.4
|
||||
*/
|
||||
public static function process_shop_order_item_meta( $post_id, $post ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1375,7 +1368,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @return bool True if the subscription exists and requires manual payments, false if the subscription uses automatic payments (defaults to false for backward compatibility).
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function requires_manual_renewal( $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::is_manual()' );
|
||||
@@ -1400,7 +1393,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @return float The total initial amount charged when the subscription product in the order was first purchased, if any.
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
*/
|
||||
public static function get_total_initial_payment( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Order::get_total()' );
|
||||
@@ -1418,7 +1411,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order $order A WC_Order object
|
||||
* @param int $product_id The product/post ID of a subscription
|
||||
* @return float The total amount to be charged for each billing period, if any, not including failed payments.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_item_recurring_amount( $order, $product_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the item on the subscription object rather than the value on the original order. A line item can be deleted from a subscription since Subscriptions v2.0, so even if it exists on an order, it may not exist as a subscription. That means for accurate results, you must use the value on the subscription object' );
|
||||
@@ -1438,7 +1431,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns the proportion of cart discount that is recurring for the product specified with $product_id
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_discount_cart( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different discounts, so use the subscription object' );
|
||||
@@ -1468,7 +1461,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns the proportion of cart discount tax that is recurring for the product specified with $product_id
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_discount_cart_tax( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different discounts, so use the subscription object' );
|
||||
@@ -1498,7 +1491,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns the proportion of total discount that is recurring for the product specified with $product_id
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_discount_total( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different discounts, so use the subscription object' );
|
||||
@@ -1544,7 +1537,7 @@ class WC_Subscriptions_Order {
|
||||
* this is equal to @see WC_Order::get_total_tax()
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_shipping_tax_total( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different amounts, so use the subscription object' );
|
||||
@@ -1576,7 +1569,7 @@ class WC_Subscriptions_Order {
|
||||
* equal to @see WC_Order::get_total_shipping()
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_shipping_total( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different amounts, so use the subscription object' );
|
||||
@@ -1623,7 +1616,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns an array of taxes on an order with their recurring totals.
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_taxes( $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the taxes for the subscription object rather than the original order. Taxes are stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different taxes, so use the subscription object' );
|
||||
@@ -1641,7 +1634,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns the proportion of total tax on an order that is recurring for the product specified with $product_id
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_total_tax( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different amounts, so use the subscription object' );
|
||||
@@ -1671,7 +1664,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns the proportion of total before tax on an order that is recurring for the product specified with $product_id
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_total_ex_tax( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the value for the subscription object rather than the value on the original order. The value is stored against the subscription since Subscriptions v2.0 as an order can be used to create multiple different subscriptions with different amounts, so use the subscription object' );
|
||||
@@ -1683,7 +1676,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_total( $order ) {
|
||||
$recurring_total = 0;
|
||||
@@ -1713,7 +1706,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order $order A WC_Order object.
|
||||
* @param mixed $deprecated Never used.
|
||||
* @param mixed $deprecated Never used.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_order_subscription_string( $order, $deprecated_price = '', $deprecated_sign_up_fee = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_formatted_order_total()' );
|
||||
@@ -1729,7 +1722,7 @@ class WC_Subscriptions_Order {
|
||||
* Returns an array of items in an order which are recurring along with their recurring totals.
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_recurring_items( $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the items on each individual subscription object (i.e. "shop_subscription")' );
|
||||
@@ -1773,7 +1766,7 @@ class WC_Subscriptions_Order {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return string A string representation of the period for the subscription, i.e. day, week, month or year.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_subscription_period( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the billing period for each individual subscription object. Since Subscriptions v2.0, an order can be used to create multiple different subscriptions with different billing schedules, so use the subscription object' );
|
||||
@@ -1808,7 +1801,7 @@ class WC_Subscriptions_Order {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return int The billing interval for a each subscription product in an order.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_subscription_interval( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the billing interval for each individual subscription object. Since Subscriptions v2.0, an order can be used to create multiple different subscriptions with different billing schedules, so use the subscription object' );
|
||||
@@ -1843,7 +1836,7 @@ class WC_Subscriptions_Order {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return int The number of periods for which the subscription will recur. For example, a $5/month subscription for one year would return 12. A $10 every 3 month subscription for one year would also return 12.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_subscription_length( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the end date each individual subscription object. Since Subscriptions v2.0, an order can be used to create multiple different subscriptions with different billing schedules. The length of a subscription is also no longer stored against the subscription and instead, it is used simply to calculate the end date for the subscription when it is purchased. Therefore, you must use the end date of a subscription object' );
|
||||
@@ -1860,7 +1853,7 @@ class WC_Subscriptions_Order {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return int The number of periods the trial period lasts for. For no trial, this will return 0, for a 3 period trial, it will return 3.
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
*/
|
||||
public static function get_subscription_trial_length( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the first payment date for each individual subscription object. Since Subscriptions v2.0, an order can be used to create multiple different subscriptions with different billing schedules. The trial length of a subscription is also no longer stored against the subscription and instead, it is used simply to calculate the first payment date for the subscription when it is purchased. Therefore, you must use the first payment date of a subscription object' );
|
||||
@@ -1877,7 +1870,7 @@ class WC_Subscriptions_Order {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id (optional) The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return string A string representation of the period for the subscription, i.e. day, week, month or year.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_subscription_trial_period( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'the billing period for each individual subscription object. Since Subscriptions v2.0, an order can be used to create multiple different subscriptions with different billing schedules. The trial period of a subscription is also no longer stored against the subscription and instead, it is used simply to calculate the first payment date for the subscription when it is purchased. Therefore, you must use the billing period of a subscription object' );
|
||||
@@ -1894,8 +1887,8 @@ class WC_Subscriptions_Order {
|
||||
* @param int $product_id The product/post ID of the subscription
|
||||
* @param mixed $deprecated Never used.
|
||||
* @return int If no more payments are due, returns 0, otherwise returns a timestamp of the date the next payment is due.
|
||||
* @version 1.2
|
||||
* @since 1.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_next_payment_timestamp( $order, $product_id, $deprecated = null ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_time( "next_payment" )' );
|
||||
@@ -1920,8 +1913,8 @@ class WC_Subscriptions_Order {
|
||||
* @param int $product_id The product/post ID of the subscription
|
||||
* @param mixed $deprecated Never used.
|
||||
* @return mixed If no more payments are due, returns 0, otherwise it returns the MySQL formatted date/time string for the next payment date.
|
||||
* @version 1.2
|
||||
* @since 1.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_next_payment_date( $order, $product_id, $deprecated = null ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_date( "next_payment" )' );
|
||||
@@ -1946,8 +1939,8 @@ class WC_Subscriptions_Order {
|
||||
* @param int $product_id The product/post ID of the subscription
|
||||
* @param mixed $deprecated Never used.
|
||||
* @return mixed If no more payments are due, returns 0, otherwise it returns the MySQL formatted date/time string for the next payment date.
|
||||
* @version 1.2.1
|
||||
* @since 1.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v1.2.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_last_payment_date( $order, $product_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_date( "last_payment" )' );
|
||||
@@ -1980,7 +1973,7 @@ class WC_Subscriptions_Order {
|
||||
* @param string $type (optional) The format for the Either 'mysql' or 'timestamp'.
|
||||
* @param mixed $from_date A MySQL formatted date/time string from which to calculate the next payment date, or empty (default), which will use the last payment on the subscription, or today's date/time if no previous payments have been made.
|
||||
* @return mixed If there is no future payment set, returns 0, otherwise it will return a date of the next payment in the form specified by $type
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function calculate_next_payment_date( $order, $product_id, $type = 'mysql', $from_date = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::calculate_date( "next_payment" )' );
|
||||
@@ -2005,7 +1998,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order $order The WC_Order object of the order for which you want to determine the number of failed payments.
|
||||
* @param product_id int The ID of the subscription product.
|
||||
* @return string The key representing the given subscription.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_failed_payment_count( $order, $product_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_failed_payment_count()' );
|
||||
@@ -2028,7 +2021,7 @@ class WC_Subscriptions_Order {
|
||||
* @param WC_Order $order The WC_Order object of the order for which you want to determine the number of failed payments.
|
||||
* @param product_id int The ID of the subscription product.
|
||||
* @return string The key representing the given subscription.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_outstanding_balance( $order, $product_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2045,7 +2038,7 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param int $user_id The id of the user who purchased the subscription
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1.2
|
||||
*/
|
||||
public static function safeguard_scheduled_payments( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2054,7 +2047,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Appends the subscription period/duration string to order total
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_formatted_line_total( $formatted_total, $item, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_formatted_line_subtotal()' );
|
||||
@@ -2064,7 +2057,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Appends the subscription period/duration string to order subtotal
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_subtotal_to_display( $subtotal, $compound, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_subtotal_to_display()' );
|
||||
@@ -2074,7 +2067,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Appends the subscription period/duration string to order total
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_cart_discount_to_display( $discount, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_discount_to_display()' );
|
||||
@@ -2084,7 +2077,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Appends the subscription period/duration string to order total
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_order_discount_to_display( $discount, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_discount_to_display()' );
|
||||
@@ -2094,7 +2087,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Appends the subscription period/duration string to order total
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_formatted_order_total( $formatted_total, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_formatted_order_total()' );
|
||||
@@ -2104,7 +2097,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Appends the subscription period/duration string to shipping fee
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_shipping_to_display( $shipping_to_display, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_shipping_to_display()' );
|
||||
@@ -2114,7 +2107,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Individual totals are taken care of by filters, but taxes and fees are not, so we need to override them here.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_order_item_totals( $total_rows, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_order_item_totals()' );
|
||||
@@ -2124,7 +2117,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Load Subscription related order data when populating an order
|
||||
*
|
||||
* @since 1.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4
|
||||
*/
|
||||
public static function load_order_data( $order_data ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2134,7 +2127,7 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Add request filter for order types to Woocommerce -> Orders screen
|
||||
*
|
||||
* @since version 1.5.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.4
|
||||
*/
|
||||
public static function order_shipping_method( $shipping_method, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -2146,8 +2139,8 @@ class WC_Subscriptions_Order {
|
||||
*
|
||||
* @param WC_Order $order A WC_Order object
|
||||
* @param int $product_id The product/post ID of a subscription
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_item_sign_up_fee( $order, $product_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_items_sign_up_fee() or WC_Subscriptions_Order::get_sign_up_fee()' );
|
||||
@@ -2165,8 +2158,8 @@ class WC_Subscriptions_Order {
|
||||
* It will also set the start date on the subscription to the time the payment is completed.
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_record_order_payment( $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . 'maybe_record_subscription_payment::( $order, $old_status, $new_status )' );
|
||||
@@ -2189,8 +2182,8 @@ class WC_Subscriptions_Order {
|
||||
/**
|
||||
* Wrapper around @see WC_Order::get_order_currency() for versions of WooCommerce prior to 2.1.
|
||||
*
|
||||
* @since version 1.4.9
|
||||
* @deprecated 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function get_order_currency( $order ) {
|
||||
_deprecated_function( __METHOD__, '2.2.0', 'wcs_get_objects_property( $order, "currency" ) or $order->get_currency()' );
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* @subpackage WC_Subscriptions_Product
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
class WC_Subscriptions_Product {
|
||||
|
||||
@@ -28,7 +28,7 @@ class WC_Subscriptions_Product {
|
||||
/**
|
||||
* Set up the class, including it's hooks & filters, when the file is loaded.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
**/
|
||||
public static function init() {
|
||||
|
||||
@@ -94,7 +94,7 @@ class WC_Subscriptions_Product {
|
||||
* When the received arg is a product object, make sure it is passed into the filter intact in order to retain any properties added on the fly.
|
||||
*
|
||||
* @param int|WC_Product $product Either a product object or product's post ID.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function is_subscription( $product ) {
|
||||
|
||||
@@ -118,7 +118,7 @@ class WC_Subscriptions_Product {
|
||||
* Output subscription string as the price html for grouped products and make sure that
|
||||
* sign-up fees are taken into account for price.
|
||||
*
|
||||
* @since 1.3.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.4
|
||||
*/
|
||||
public static function get_grouped_price_html( $price, $grouped_product ) {
|
||||
|
||||
@@ -180,7 +180,7 @@ class WC_Subscriptions_Product {
|
||||
/**
|
||||
* Output subscription string in Gravity Form fields.
|
||||
*
|
||||
* @since 1.1
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.1
|
||||
*/
|
||||
public static function get_gravity_form_prices( $price, $product ) {
|
||||
|
||||
@@ -210,7 +210,7 @@ class WC_Subscriptions_Product {
|
||||
* 'subscription_length' => true to include subscription's length (default) or false to exclude it
|
||||
* 'sign_up_fee' => true to include subscription's sign up fee (default) or false to exclude it
|
||||
* 'price' => string a price to short-circuit the price calculations and use in a string for the product
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_price_string( $product, $include = array() ) {
|
||||
global $wp_locale;
|
||||
@@ -410,7 +410,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return string The price charged per period for the subscription, or an empty string if the product is not a subscription.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_price( $product ) {
|
||||
$product = self::maybe_get_product_instance( $product );
|
||||
@@ -437,7 +437,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return string
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function get_regular_price( $product, $context = 'view' ) {
|
||||
|
||||
@@ -455,7 +455,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return string
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function get_sale_price( $product, $context = 'view' ) {
|
||||
|
||||
@@ -473,7 +473,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return string A string representation of the period, either Day, Week, Month or Year, or an empty string if product is not a subscription.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_period( $product ) {
|
||||
return apply_filters( 'woocommerce_subscriptions_product_period', self::get_meta_data( $product, 'subscription_period', '' ), self::maybe_get_product_instance( $product ) );
|
||||
@@ -484,7 +484,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return int An integer representing the subscription interval, or 1 if the product is not a subscription or there is no interval
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_interval( $product ) {
|
||||
return apply_filters( 'woocommerce_subscriptions_product_period_interval', self::get_meta_data( $product, 'subscription_period_interval', 1, 'use_default_value' ), self::maybe_get_product_instance( $product ) );
|
||||
@@ -495,7 +495,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return int An integer representing the length of the subscription, or 0 if the product is not a subscription or the subscription continues for perpetuity
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_length( $product ) {
|
||||
return apply_filters( 'woocommerce_subscriptions_product_length', self::get_meta_data( $product, 'subscription_length', 0, 'use_default_value' ), self::maybe_get_product_instance( $product ) );
|
||||
@@ -506,7 +506,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return int An integer representing the length of the subscription trial, or 0 if the product is not a subscription or there is no trial
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_trial_length( $product ) {
|
||||
return apply_filters( 'woocommerce_subscriptions_product_trial_length', self::get_meta_data( $product, 'subscription_trial_length', 0, 'use_default_value' ), self::maybe_get_product_instance( $product ) );
|
||||
@@ -517,7 +517,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return string A string representation of the period, either Day, Week, Month or Year, or an empty string if product is not a subscription or there is no trial
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function get_trial_period( $product ) {
|
||||
return apply_filters( 'woocommerce_subscriptions_product_trial_period', self::get_meta_data( $product, 'subscription_trial_period', '' ), self::maybe_get_product_instance( $product ) );
|
||||
@@ -528,7 +528,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return int|string The value of the sign-up fee, or 0 if the product is not a subscription or the subscription has no sign-up fee
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_sign_up_fee( $product ) {
|
||||
return apply_filters( 'woocommerce_subscriptions_product_sign_up_fee', self::get_meta_data( $product, 'subscription_sign_up_fee', 0, 'use_default_value' ), self::maybe_get_product_instance( $product ) );
|
||||
@@ -542,7 +542,7 @@ class WC_Subscriptions_Product {
|
||||
* @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date, or empty (default), which will use today's date/time.
|
||||
* @param string $type The return format for the date, either 'mysql', or 'timezone'. Default 'mysql'.
|
||||
* @param string $timezone The timezone for the returned date, either 'site' for the site's timezone, or 'gmt'. Default, 'site'.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_first_renewal_payment_date( $product, $from_date = '', $timezone = 'gmt' ) {
|
||||
|
||||
@@ -565,7 +565,7 @@ class WC_Subscriptions_Product {
|
||||
* @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date, or empty (default), which will use today's date/time.
|
||||
* @param string $type The return format for the date, either 'mysql', or 'timezone'. Default 'mysql'.
|
||||
* @param string $timezone The timezone for the returned date, either 'site' for the site's timezone, or 'gmt'. Default, 'site'.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_first_renewal_payment_time( $product, $from_date = '', $timezone = 'gmt' ) {
|
||||
|
||||
@@ -614,7 +614,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param int|WC_Product $product The product instance or product/post ID of a subscription product.
|
||||
* @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date, or empty (default), which will use today's date/time.
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_expiration_date( $product, $from_date = '' ) {
|
||||
|
||||
@@ -648,7 +648,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param int|WC_Product $product The product instance or product/post ID of a subscription product.
|
||||
* @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date (in UTC timezone), or empty (default), which will use today's date/time (in UTC timezone).
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function get_trial_expiration_date( $product, $from_date = '' ) {
|
||||
|
||||
@@ -677,7 +677,7 @@ class WC_Subscriptions_Product {
|
||||
* WC_Product_Variation class).
|
||||
*
|
||||
* @return string $classname The name of the WC_Product_* class which should be instantiated to create an instance of this product.
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function set_subscription_variation_class( $classname, $product_type, $post_type, $product_id ) {
|
||||
|
||||
@@ -702,7 +702,7 @@ class WC_Subscriptions_Product {
|
||||
* Ensures a price is displayed for subscription variation where WC would normally ignore it (i.e. when prices are equal).
|
||||
*
|
||||
* @return array $variation_details Set of name/value pairs representing the subscription.
|
||||
* @since 1.3.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3.6
|
||||
*/
|
||||
public static function maybe_set_variations_price_html( $variation_details, $variable_product, $variation ) {
|
||||
|
||||
@@ -719,7 +719,7 @@ class WC_Subscriptions_Product {
|
||||
* Those with appropriate capabilities can still trash the product, but they will not be able to permanently
|
||||
* delete the product if it is associated with an order (i.e. been purchased).
|
||||
*
|
||||
* @since 1.4.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
*/
|
||||
public static function user_can_not_delete_subscription( $allcaps, $caps, $args ) {
|
||||
global $wpdb;
|
||||
@@ -754,7 +754,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @return array $actions Array of actions that can be performed on the post.
|
||||
* @return array $post Array of post values for the current product (or post object if it is not a product).
|
||||
* @since 1.4.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
*/
|
||||
public static function subscription_row_actions( $actions, $post ) {
|
||||
global $the_product;
|
||||
@@ -782,7 +782,7 @@ class WC_Subscriptions_Product {
|
||||
* deletion (or get any more detailed information about which item can't be deleted and why).
|
||||
*
|
||||
* @return array $actions Array of actions that can be performed on the post.
|
||||
* @since 1.4.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
*/
|
||||
public static function subscription_bulk_actions( $actions ) {
|
||||
|
||||
@@ -796,7 +796,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return bool True if the product requires only one time shipping, false otherwise.
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function needs_one_time_shipping( $product ) {
|
||||
$product = self::maybe_get_product_instance( $product );
|
||||
@@ -814,7 +814,7 @@ class WC_Subscriptions_Product {
|
||||
* purged from the trash. We want to make sure Subscriptions products are not automatically purged (but still want
|
||||
* to keep a record of when the product was trashed).
|
||||
*
|
||||
* @since 1.4.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
*/
|
||||
public static function prevent_scheduled_deletion() {
|
||||
global $wpdb;
|
||||
@@ -838,7 +838,7 @@ class WC_Subscriptions_Product {
|
||||
* request will either terminate or in the case of bulk deleting, the variation's ID will be removed
|
||||
* from the $_POST.
|
||||
*
|
||||
* @since 1.4.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.4.9
|
||||
*/
|
||||
public static function remove_variations() {
|
||||
|
||||
@@ -884,7 +884,7 @@ class WC_Subscriptions_Product {
|
||||
* @param array $data An array of data relating to the bulk edit action. $data['value'] represents the new value for the meta.
|
||||
* @param int $variable_product_id The post ID of the parent variable product.
|
||||
* @param array $variation_ids An array of post IDs for the variable prodcut's variations.
|
||||
* @since 1.5.29
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.29
|
||||
*/
|
||||
public static function bulk_edit_variations( $bulk_action, $data, $variable_product_id, $variation_ids ) {
|
||||
if ( 'delete_all_no_subscriptions' === $bulk_action && isset( $data['allowed'] ) && 'true' == $data['allowed'] ) {
|
||||
@@ -959,7 +959,7 @@ class WC_Subscriptions_Product {
|
||||
* @param int $loop Position of the variation inside the variations loop.
|
||||
* @param array $variation_data Array of variation data.
|
||||
* @param WP_Post $variation The variation's WP post.
|
||||
* @since 2.2.17
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.17
|
||||
*/
|
||||
public static function add_variation_removal_flag( $loop, $variation_data, $variation ) {
|
||||
|
||||
@@ -983,7 +983,7 @@ class WC_Subscriptions_Product {
|
||||
* Processes an AJAX request to check if a product has a variation which is either sync'd or has a trial.
|
||||
* Once at least one variation with a trial or sync date is found, this will terminate and return true, otherwise false.
|
||||
*
|
||||
* @since 2.0.18
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.18
|
||||
*/
|
||||
public static function check_product_variations_for_syncd_or_trial() {
|
||||
|
||||
@@ -1024,7 +1024,7 @@ class WC_Subscriptions_Product {
|
||||
* This function, triggered after saving variations or triggering the trial length bulk action, ensures one time shipping settings
|
||||
* are updated after determining if one time shipping is still available to the product.
|
||||
*
|
||||
* @since 2.0.18
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.18
|
||||
*/
|
||||
public static function maybe_update_one_time_shipping_on_variation_edits() {
|
||||
|
||||
@@ -1048,7 +1048,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param mixed $product A WC_Product object or product ID
|
||||
* @return WC_Product
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
private static function maybe_get_product_instance( $product ) {
|
||||
|
||||
@@ -1067,7 +1067,7 @@ class WC_Subscriptions_Product {
|
||||
* @param mixed $default_value The value to return if the meta doesn't exist or isn't set
|
||||
* @param string $empty_handling (optional) How empty values should be handled -- can be 'use_default_value' or 'allow_empty'. Defaults to 'allow_empty' returning the empty value.
|
||||
* @return mixed
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function get_meta_data( $product, $meta_key, $default_value, $empty_handling = 'allow_empty' ) {
|
||||
|
||||
@@ -1101,7 +1101,7 @@ class WC_Subscriptions_Product {
|
||||
* sync variable product min/max prices with WC 3.0
|
||||
*
|
||||
* @param WC_Product_Variable $product
|
||||
* @since 2.2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.0
|
||||
*/
|
||||
public static function variable_subscription_product_sync( $product ) {
|
||||
|
||||
@@ -1150,7 +1150,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param WC_Product The product object to get parents from.
|
||||
* @return array Parent IDs
|
||||
* @since 2.2.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.4
|
||||
*/
|
||||
public static function get_parent_ids( $product ) {
|
||||
global $wpdb;
|
||||
@@ -1177,7 +1177,7 @@ class WC_Subscriptions_Product {
|
||||
*
|
||||
* @param WC_Product The product object to get parents from.
|
||||
* @return array The product's grouped parent IDs.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public static function get_visible_grouped_parent_product_ids( $product ) {
|
||||
$parent_product_ids = self::get_parent_ids( $product );
|
||||
@@ -1197,7 +1197,7 @@ class WC_Subscriptions_Product {
|
||||
/**
|
||||
* Gets the add to cart text for subscription products.
|
||||
*
|
||||
* @since 3.0.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.7
|
||||
* @return string The add to cart text.
|
||||
*/
|
||||
public static function get_add_to_cart_text() {
|
||||
@@ -1207,7 +1207,7 @@ class WC_Subscriptions_Product {
|
||||
/**
|
||||
* Validates an ajax request to delete a subscription variation.
|
||||
*
|
||||
* @since 3.x.x
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.x.x
|
||||
*/
|
||||
public static function validate_variation_deletion() {
|
||||
check_admin_referer( 'wc_subscriptions_admin', 'nonce' );
|
||||
@@ -1225,8 +1225,8 @@ class WC_Subscriptions_Product {
|
||||
/**
|
||||
* Override the WooCommerce "Add to cart" text with "Sign up now".
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 3.0.7
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.7
|
||||
*/
|
||||
public static function add_to_cart_text( $button_text, $product_type = '' ) {
|
||||
_deprecated_function( __METHOD__, '3.0.7', 'WC_Subscriptions_Product::get_add_to_cart_text' );
|
||||
@@ -1243,7 +1243,7 @@ class WC_Subscriptions_Product {
|
||||
* If a product is being marked as not purchasable because it is limited and the customer has a subscription,
|
||||
* but the current request is to resubscribe to the subscription, then mark it as purchasable.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_purchasable( $is_purchasable, $product ) {
|
||||
|
@@ -8,14 +8,14 @@
|
||||
* @subpackage WC_Subscriptions_Order
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
class WC_Subscriptions_Renewal_Order {
|
||||
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.0
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
@@ -39,7 +39,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Trigger a special hook for payments on a completed renewal order.
|
||||
*
|
||||
* @since 1.5.4
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.4
|
||||
*/
|
||||
public static function trigger_renewal_payment_complete( $order_id ) {
|
||||
if ( wcs_order_contains_renewal( $order_id ) ) {
|
||||
@@ -50,16 +50,28 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Check if a given renewal order was created to replace a failed renewal order.
|
||||
*
|
||||
* @since 1.5.12
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.12
|
||||
* @param int ID of the renewal order you want to check against
|
||||
* @return mixed If the renewal order did replace a failed order, the ID of the fail order, else false
|
||||
*/
|
||||
public static function get_failed_order_replaced_by( $renewal_order_id ) {
|
||||
global $wpdb;
|
||||
|
||||
$failed_order_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_failed_order_replaced_by' AND meta_value = %s", $renewal_order_id ) );
|
||||
// Get orders where order meta '_failed_order_replaced_by' = $renewal_order_id
|
||||
$failed_orders = wcs_get_orders_with_meta_query(
|
||||
[
|
||||
'limit' => 1,
|
||||
'return' => 'ids',
|
||||
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
[
|
||||
'key' => '_failed_order_replaced_by',
|
||||
'compare' => '=',
|
||||
'value' => $renewal_order_id,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
return ( null === $failed_order_id ) ? false : $failed_order_id;
|
||||
return $failed_orders[0] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +81,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* subscriptions are updated even if payment is processed by a manual payment gateways (which would never trigger the
|
||||
* 'woocommerce_payment_complete' hook) or by some other means that circumvents that hook.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_record_subscription_payment( $order_id, $orders_old_status, $orders_new_status ) {
|
||||
|
||||
@@ -141,7 +153,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param WC_Order|int $renewal_order
|
||||
* @param WC_Subscription|int $subscription
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_order_note( $renewal_order, $subscription ) {
|
||||
if ( ! is_object( $subscription ) ) {
|
||||
@@ -167,7 +179,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Do not allow customers to cancel renewal orders.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function prevent_cancelling_renewal_orders() {
|
||||
if ( isset( $_GET['cancel_order'] ) && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
|
||||
@@ -191,7 +203,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Removes switch line item meta data so it isn't copied to renewal order line items
|
||||
*
|
||||
* @since 2.0.16
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.16
|
||||
* @param array $order_items
|
||||
* @return array $order_items
|
||||
*/
|
||||
@@ -228,8 +240,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param int $user_id The id of the user who purchased the subscription
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function generate_paid_renewal_order( $user_id, $subscription_key ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_create_renewal_order( WC_Subscription $subscription )' );
|
||||
@@ -247,8 +259,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param int $user_id The id of the user who purchased the subscription
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function generate_failed_payment_renewal_order( $user_id, $subscription_key ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_create_renewal_order( WC_Subscription $subscription )' );
|
||||
@@ -268,7 +280,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param int $user_id The id of the user who purchased the subscription
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function maybe_generate_manual_renewal_order( $user_id, $subscription_key ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::maybe_create_manual_renewal_order( WC_Subscription $subscription )' );
|
||||
@@ -282,8 +294,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* parent order.
|
||||
*
|
||||
* @param WC_Order|int $order The WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_parent_order_id( $renewal_order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_get_subscriptions_for_renewal_order()' );
|
||||
@@ -300,8 +312,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* parent order.
|
||||
*
|
||||
* @param WC_Order|int $order The WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0 self::get_parent_subscription() is the better function to use now as a renewal order
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0, self::get_parent_subscription() is the better function to use now as a renewal order
|
||||
*/
|
||||
public static function get_parent_order( $renewal_order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_get_subscriptions_for_renewal_order()' );
|
||||
@@ -326,8 +338,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* Returns the number of renewals for a given parent order
|
||||
*
|
||||
* @param int $order_id The ID of a WC_Order object.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_renewal_order_count( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_related_orders()' );
|
||||
@@ -358,8 +370,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* Deprecated because the use of a $subscription_key is deprecated.
|
||||
*
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_users_renewal_link( $subscription_key, $role = 'parent' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_get_users_resubscribe_link( $subscription )' );
|
||||
@@ -372,8 +384,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* Deprecated because the use of a $subscription_key is deprecated.
|
||||
*
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_users_renewal_link_for_product( $product_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_get_users_resubscribe_link_for_product( $subscription )' );
|
||||
@@ -387,8 +399,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @param int $user_id The ID of the user who owns the subscriptions. Although this parameter is optional, if you have the User ID you should pass it to improve performance.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function can_subscription_be_renewed( $subscription_key, $user_id = '' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_can_user_resubscribe_to( $subscription, $user_id )' );
|
||||
@@ -399,8 +411,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* Checks if the current request is by a user to renew their subscription, and if it is
|
||||
* set up a subscription renewal via the cart for the product/variation that is being renewed.
|
||||
*
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_create_renewal_order_for_user() {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::maybe_setup_resubscribe_via_cart()' );
|
||||
@@ -411,8 +423,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* a subscription renewal, do not adjust the price because the original order's price will
|
||||
* be used, and this includes the addons amounts.
|
||||
*
|
||||
* @since 1.5.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function product_addons_adjust_price( $adjust_price, $cart_item ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::product_addons_adjust_price()' );
|
||||
@@ -427,8 +439,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* 'new_order_role' string A flag to indicate whether the new order should become the master order for the subscription. Accepts either 'parent' or 'child'. Defaults to 'parent' - replace the existing order.
|
||||
* 'checkout_renewal' bool Indicates if invoked from an interactive cart/checkout session and certain order items are not set, like taxes, shipping as they need to be set in teh calling function, like @see WC_Subscriptions_Checkout::filter_woocommerce_create_order(). Default false.
|
||||
* 'failed_order_id' int For checkout_renewal true, indicates order id being replaced
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function generate_renewal_order( $original_order, $product_id, $args = array() ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_create_renewal_order() or wcs_create_resubscribe_order()' );
|
||||
@@ -461,8 +473,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* If a product is being marked as not purchasable because it is limited and the customer has a subscription,
|
||||
* but the current request is to resubscribe to the subscription, then mark it as purchasable.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function is_purchasable( $is_purchasable, $product ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::is_purchasable()' );
|
||||
@@ -476,7 +488,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* @param array $args (optional) An array of name => value flags:
|
||||
* 'order_role' string (optional) A specific role to check the order against. Either 'parent' or 'child'.
|
||||
* 'via_checkout' Indicates whether to check if the renewal order was via the cart/checkout process.
|
||||
* @since 1.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function is_renewal( $order, $args = array() ) {
|
||||
|
||||
@@ -508,8 +520,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param int $order_id The ID of a WC_Order object.
|
||||
* @param string $output (optional) How you'd like the result. Can be 'ID' for IDs only or 'WC_Order' for order objects.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_renewal_orders( $order_id, $output = 'ID' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WC_Subscription::get_related_orders()' );
|
||||
@@ -535,8 +547,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* This is particularly important to ensure renewals of limited subscriptions can be completed.
|
||||
*
|
||||
* @since 1.5.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_checkout_payment_url( $pay_url, $order ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::get_checkout_payment_url() or WCS_Cart_Resubscribe::get_checkout_payment_url()' );
|
||||
@@ -546,8 +558,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Process a renewal payment when a customer has completed the payment for a renewal payment which previously failed.
|
||||
*
|
||||
* @since 1.3
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_process_failed_renewal_order_payment( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Renewal::maybe_change_subscription_status( $order_id, $orders_old_status, $orders_new_status )' );
|
||||
@@ -559,8 +571,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* never be called. This function makes sure it is called.
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function process_failed_renewal_order_payment( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -579,8 +591,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* Records manual payment of a renewal order against a subscription.
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_record_renewal_order_payment( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -599,8 +611,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
* Records manual payment of a renewal order against a subscription.
|
||||
*
|
||||
* @param WC_Order|int $order A WC_Order object or ID of a WC_Order order.
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_record_renewal_order_payment_failure( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -621,8 +633,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
*
|
||||
* @param int $user_id The id of the user who purchased the subscription
|
||||
* @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
|
||||
* @since 1.2
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function process_subscription_payment_on_child_order( $order_id, $payment_status = 'completed' ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -650,8 +662,8 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Adds a renewal orders section to the Related Orders meta box displayed on subscription orders.
|
||||
*
|
||||
* @deprecated 2.0
|
||||
* @since 1.2
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.2
|
||||
*/
|
||||
public static function renewal_orders_meta_box_section( $order, $post ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -660,7 +672,7 @@ class WC_Subscriptions_Renewal_Order {
|
||||
/**
|
||||
* Trigger a hook when a subscription suspended due to a failed renewal payment is reactivated
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.3
|
||||
*/
|
||||
public static function trigger_processed_failed_renewal_order_payment_hook( $user_id, $subscription_key ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::maybe_record_subscription_payment( $order_id, $orders_old_status, $orders_new_status )' );
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* @subpackage WC_Subscriptions_Sync
|
||||
* @category Class
|
||||
* @author Brent Shepherd
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
class WC_Subscriptions_Synchroniser {
|
||||
|
||||
@@ -38,7 +38,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Bootstraps the class and hooks required actions & filters.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function init() {
|
||||
self::$setting_id = WC_Subscriptions_Admin::$option_prefix . '_sync_payments';
|
||||
@@ -93,7 +93,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
add_filter( 'woocommerce_subscriptions_cart_get_price', __CLASS__ . '::set_prorated_price_for_calculation', 10, 2 );
|
||||
|
||||
// When creating a subscription check if it contains a synced product and make sure the correct meta is set on the subscription
|
||||
add_action( 'save_post', __CLASS__ . '::maybe_add_subscription_meta', 10, 1 );
|
||||
add_action( 'woocommerce_new_subscription', __CLASS__ . '::maybe_add_subscription_meta', 10, 1 );
|
||||
|
||||
// When adding an item to a subscription, check if it is for a synced product to make sure the sync meta is set on the subscription. We can't attach to just the 'woocommerce_new_order_item' here because the '_product_id' and '_variation_id' meta are not set before it fires
|
||||
add_action( 'woocommerce_ajax_add_order_item_meta', __CLASS__ . '::ajax_maybe_add_meta_for_item', 10, 2 );
|
||||
@@ -173,7 +173,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Check if payment syncing is enabled on the store.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function is_syncing_enabled() {
|
||||
return 'yes' === get_option( self::$setting_id, 'no' );
|
||||
@@ -182,7 +182,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Check if payments can be prorated on the store.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function is_sync_proration_enabled() {
|
||||
return 'no' !== get_option( self::$setting_id_proration, 'no' );
|
||||
@@ -191,7 +191,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Add sync settings to the Subscription's settings page.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function add_settings( $settings ) {
|
||||
$synchronisation_settings = array(
|
||||
@@ -253,7 +253,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Add the sync setting fields to the Edit Product screen
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function subscription_product_fields() {
|
||||
global $post, $wp_locale;
|
||||
@@ -324,7 +324,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Add the sync setting fields to the variation section of the Edit Product screen
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function variable_subscription_product_fields( $loop, $variation_data, $variation ) {
|
||||
|
||||
@@ -357,7 +357,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Save sync options when a subscription product is saved
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function save_subscription_meta( $post_id ) {
|
||||
|
||||
@@ -390,7 +390,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Save sync options when a variable subscription product is saved
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function process_product_meta_variable_subscription( $post_id ) {
|
||||
|
||||
@@ -405,7 +405,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Save sync options when a variable subscription product is saved
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function save_product_variation( $variation_id, $index ) {
|
||||
|
||||
@@ -433,7 +433,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Add translated syncing options for our client side script
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function admin_script_parameters( $script_parameters ) {
|
||||
|
||||
@@ -459,7 +459,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* specific day (instead of at the time of sign-up).
|
||||
*
|
||||
* @return (bool) True is the product's first payment will be synced to a certain day.
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function is_product_synced( $product ) {
|
||||
|
||||
@@ -480,7 +480,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Determine whether a product, specified with $product, should have its first payment processed on a
|
||||
* at the time of sign-up but prorated to the sync day.
|
||||
*
|
||||
* @since 1.5.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.10
|
||||
*
|
||||
* @param WC_Product $product
|
||||
*
|
||||
@@ -575,7 +575,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* synchronised to.
|
||||
*
|
||||
* @return int The day the products payments should be processed, or 0 if the payments should not be sync'd to a specific day.
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function get_products_payment_day( $product ) {
|
||||
|
||||
@@ -596,7 +596,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param WC_Product $product A subscription product.
|
||||
* @param string $type (optional) The format to return the first payment date in, either 'mysql' or 'timestamp'. Default 'mysql'.
|
||||
* @param string $from_date (optional) The date to calculate the first payment from in GMT/UTC timzeone. If not set, it will use the current date. This should not include any trial period on the product.
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function calculate_first_payment_date( $product, $type = 'mysql', $from_date = '' ) {
|
||||
|
||||
@@ -736,7 +736,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Return an i18n'ified associative array of sync options for 'year' as billing period
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.0
|
||||
*/
|
||||
public static function get_year_sync_options() {
|
||||
global $wp_locale;
|
||||
@@ -750,7 +750,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Return an i18n'ified associative array of all possible subscription periods.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function get_billing_period_ranges( $billing_period = '' ) {
|
||||
global $wp_locale;
|
||||
@@ -791,7 +791,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Add the first payment date to a products summary section
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function products_first_payment_date( $echo = false ) {
|
||||
global $product;
|
||||
@@ -808,7 +808,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Return a string explaining when the first payment will be completed for the subscription.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function get_products_first_payment_date( $product ) {
|
||||
|
||||
@@ -845,7 +845,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* If a product is synchronised to a date in the future, make sure that is set as the product's first payment date
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function products_first_renewal_payment_time( $first_renewal_timestamp, $product_id, $from_date, $timezone ) {
|
||||
|
||||
@@ -868,7 +868,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Make sure a synchronised subscription's price includes a free trial, unless it's first payment is today.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function maybe_set_free_trial( $total = '' ) {
|
||||
|
||||
@@ -892,7 +892,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Make sure a synchronised subscription's price includes a free trial, unless it's first payment is today.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function maybe_unset_free_trial( $total = '' ) {
|
||||
|
||||
@@ -917,7 +917,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Check if the cart includes a subscription that needs to be synced.
|
||||
*
|
||||
* @return bool Returns true if any item in the cart is a subscription sync request, otherwise, false.
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function cart_contains_synced_subscription( $cart = null ) {
|
||||
$cart = ( empty( $cart ) && isset( WC()->cart ) ) ? WC()->cart : $cart;
|
||||
@@ -953,7 +953,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param mixed $trial_expiration_date MySQL formatted date on which the subscription's trial will end, or 0 if it has no trial
|
||||
* @param mixed $product_id The product object or post ID of the subscription product
|
||||
* @return mixed MySQL formatted date on which the subscription's trial is set to end, or 0 if it has no trial
|
||||
* @since 2.0.13
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.13
|
||||
*/
|
||||
public static function recalculate_product_trial_expiration_date( $trial_expiration_date, $product_id ) {
|
||||
|
||||
@@ -983,7 +983,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param string $expiration_date MySQL formatted date on which the subscription is set to expire
|
||||
* @param mixed $product_id The product/post ID of the subscription
|
||||
* @param mixed $from_date A MySQL formatted date/time string from which to calculate the expiration date, or empty (default), which will use today's date/time.
|
||||
* @since 1.5
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
*/
|
||||
public static function recalculate_product_expiration_date( $expiration_date, $product_id, $from_date ) {
|
||||
|
||||
@@ -1019,7 +1019,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return float The initial sign-up fee charged when the subscription product in the order was first purchased, if any.
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_synced_sign_up_fee( $sign_up_fee, $subscription, $product_id ) {
|
||||
|
||||
@@ -1033,7 +1033,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Removes the "set_subscription_prices_for_calculation" filter from the WC Product's woocommerce_get_price hook once
|
||||
*
|
||||
* @since 1.5.10
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.10
|
||||
*
|
||||
* @param int $price The current price.
|
||||
* @param WC_Product $product The product object.
|
||||
@@ -1086,7 +1086,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* by using 1 (one). So the week starts with 1 (one)
|
||||
* and ends on Sunday with is fetched by using 7 (seven).
|
||||
*
|
||||
* @since 1.5.8
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.8
|
||||
* @access public
|
||||
*
|
||||
* @param int $weekday_number 1 for Monday through 7 Sunday
|
||||
@@ -1133,23 +1133,24 @@ class WC_Subscriptions_Synchroniser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add subscription meta for subscription that contains a synced product.
|
||||
* Adds meta on a subscription that contains a synced product.
|
||||
*
|
||||
* @param WC_Order Parent order for the subscription
|
||||
* @param WC_Subscription new subscription
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*
|
||||
* @param WC_Subscription|int Subscription object or ID.
|
||||
*/
|
||||
public static function maybe_add_subscription_meta( $post_id ) {
|
||||
|
||||
if ( 'shop_subscription' == get_post_type( $post_id ) && ! self::subscription_contains_synced_product( $post_id ) ) {
|
||||
|
||||
$subscription = wcs_get_subscription( $post_id );
|
||||
public static function maybe_add_subscription_meta( $subscription ) {
|
||||
if ( ! is_object( $subscription ) ) {
|
||||
$subscription = wcs_get_subscription( $subscription );
|
||||
}
|
||||
|
||||
if ( $subscription && ! self::subscription_contains_synced_product( $subscription ) ) {
|
||||
foreach ( $subscription->get_items() as $item ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( self::is_product_synced( $product ) ) {
|
||||
update_post_meta( $subscription->get_id(), '_contains_synced_subscription', 'true' );
|
||||
$subscription->update_meta_data( '_contains_synced_subscription', 'true' );
|
||||
$subscription->save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1162,7 +1163,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* @param int The order item ID of an item that was just added to the order
|
||||
* @param array The order item details
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function ajax_maybe_add_meta_for_item( $item_id, $item ) {
|
||||
|
||||
@@ -1180,7 +1181,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param int The post ID of a WC_Order or child object
|
||||
* @param int The order item ID of an item that was just added to the order
|
||||
* @param object The WC_Product for which an item was just added
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_add_meta_for_new_product( $subscription_id, $item_id, $product ) {
|
||||
if ( self::is_product_synced( $product ) ) {
|
||||
@@ -1189,25 +1190,25 @@ class WC_Subscriptions_Synchroniser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given subscription is synced to a certain day.
|
||||
* Checks if a given subscription is synced to a certain day.
|
||||
*
|
||||
* @param int|WC_Subscription Accepts either a subscription object of post id
|
||||
* @return bool
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*
|
||||
* @param int|WC_Subscription Accepts either a subscription object or ID.
|
||||
* @return bool True if the subscription is synced, false otherwise.
|
||||
*/
|
||||
public static function subscription_contains_synced_product( $subscription_id ) {
|
||||
|
||||
if ( is_object( $subscription_id ) ) {
|
||||
$subscription_id = $subscription_id->get_id();
|
||||
public static function subscription_contains_synced_product( $subscription ) {
|
||||
if ( ! is_object( $subscription ) ) {
|
||||
$subscription = wcs_get_subscription( $subscription );
|
||||
}
|
||||
|
||||
return 'true' == get_post_meta( $subscription_id, '_contains_synced_subscription', true );
|
||||
return is_a( $subscription, 'WC_Subscription' ) && 'true' === $subscription->get_meta( '_contains_synced_subscription' );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the cart item is synced, add a '_synced' string to the recurring cart key.
|
||||
*
|
||||
* @since 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_to_recurring_cart_key( $cart_key, $cart_item ) {
|
||||
$product = $cart_item['data'];
|
||||
@@ -1228,7 +1229,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param int The new line item id
|
||||
* @param WC_Order_Item
|
||||
* @param int The post ID of a WC_Subscription
|
||||
* @since 2.2.3
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.3
|
||||
*/
|
||||
public static function maybe_add_meta_for_new_line_item( $item_id, $item, $subscription_id ) {
|
||||
if ( is_callable( array( $item, 'get_product' ) ) ) {
|
||||
@@ -1251,7 +1252,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param WC_Order_Item_Product $item The order item object.
|
||||
* @param string $cart_item_key The hash used to identify the item in the cart
|
||||
* @param array $cart_item The cart item's data.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public static function maybe_add_line_item_meta( $item, $cart_item_key, $cart_item ) {
|
||||
if ( self::is_product_synced( $cart_item['data'] ) && ! self::is_today( self::calculate_first_payment_date( $cart_item['data'], 'timestamp' ) ) ) {
|
||||
@@ -1266,7 +1267,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* @param int $item_id The order item ID.
|
||||
* @param array $cart_item The cart item's data.
|
||||
* @since 2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
public static function maybe_add_order_item_meta( $item_id, $cart_item ) {
|
||||
if ( self::is_product_synced( $cart_item['data'] ) && ! self::is_today( self::calculate_first_payment_date( $cart_item['data'], 'timestamp' ) ) ) {
|
||||
@@ -1277,7 +1278,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Hides synced subscription meta on the edit order and subscription screen on non-debug sites.
|
||||
*
|
||||
* @since 2.6.2
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.2
|
||||
* @param array $hidden_meta_keys the list of meta keys hidden on the edit order and subscription screen.
|
||||
* @return array $hidden_meta_keys
|
||||
*/
|
||||
@@ -1293,7 +1294,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
/**
|
||||
* Gets the number of sign-up grace period days.
|
||||
*
|
||||
* @since 3.0.6
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.6
|
||||
* @return int The number of days in the grace period. 0 will be returned if the stroe isn't charging the full recurring price on sign-up -- a prerequiste for setting a grace period.
|
||||
*/
|
||||
private static function get_number_of_grace_period_days() {
|
||||
@@ -1306,7 +1307,7 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Automatically set the order's status to complete if all the subscriptions in an order
|
||||
* are synced and the order total is zero.
|
||||
*
|
||||
* @since 1.5.17
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.17
|
||||
*/
|
||||
public static function order_autocomplete( $new_order_status, $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.1.3', 'WC_Subscriptions_Order::maybe_autocomplete_order' );
|
||||
@@ -1318,8 +1319,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* Deprecated because the first renewal date is displayed by default now on recurring totals.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function customise_subscription_price_string( $subscription_string ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1347,8 +1348,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* Deprecated because free trials are no longer displayed on cart totals, only the first renewal date is displayed.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_hide_free_trial( $subscription_details ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1371,8 +1372,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Let other functions know shipping should not be charged on the initial order when
|
||||
* the cart contains a synchronised subscription and no other items which need shipping.
|
||||
*
|
||||
* @since 1.5.8
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.8
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function charge_shipping_up_front( $charge_shipping_up_front ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1417,8 +1418,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
* This is necessary as the self::calculate_first_payment_date() is not called when the subscription is active
|
||||
* (which it isn't until the first payment is completed and the subscription is activated).
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_first_payment_date( $first_payment_date, $order, $product_id, $type ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1446,8 +1447,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
* to use the synchronised first payment date as the next payment date (if the first
|
||||
* payment date isn't today, meaning the first payment won't be charged today).
|
||||
*
|
||||
* @since 1.5.14
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.14
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function maybe_set_payment_date( $payment_date, $order, $product_id, $type ) {
|
||||
|
||||
@@ -1469,8 +1470,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* @param int $order_id The ID or a WC_Order item to check.
|
||||
* @return bool Returns true if the order contains a synced subscription, otherwise, false.
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function order_contains_synced_subscription( $order_id ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::subscription_contains_synced_product()' );
|
||||
@@ -1487,8 +1488,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* Deprecated because _order_contains_synced_subscription is no longer stored on the order @see self::add_subscription_sync_meta
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function add_order_meta( $order_id, $posted ) {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1504,8 +1505,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
*
|
||||
* Deprecated because editing a subscription's values is now done from the Edit Subscription screen.
|
||||
*
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function prefill_order_item_meta( $item, $item_id ) {
|
||||
|
||||
@@ -1522,13 +1523,13 @@ class WC_Subscriptions_Synchroniser {
|
||||
* @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
|
||||
* @param int $product_id The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
|
||||
* @return float The initial sign-up fee charged when the subscription product in the order was first purchased, if any.
|
||||
* @since 1.5.3
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5.3
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function get_sign_up_fee( $sign_up_fee, $order, $product_id, $non_subscription_total ) {
|
||||
_deprecated_function( __METHOD__, '2.0', __CLASS__ . '::get_synced_sign_up_fee' );
|
||||
|
||||
if ( 'shop_order' == get_post_type( $order ) && self::order_contains_synced_subscription( wcs_get_objects_property( $order, 'id' ) ) && WC_Subscriptions_Order::get_subscription_trial_length( $order ) < 1 ) {
|
||||
if ( 'shop_order' === WC_Data_Store::load( 'order' )->get_order_type( $order ) && self::order_contains_synced_subscription( wcs_get_objects_property( $order, 'id' ) ) && WC_Subscriptions_Order::get_subscription_trial_length( $order ) < 1 ) {
|
||||
$sign_up_fee = max( WC_Subscriptions_Order::get_total_initial_payment( $order ) - $non_subscription_total, 0 );
|
||||
}
|
||||
|
||||
@@ -1539,8 +1540,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Check if the cart includes a subscription that needs to be prorated.
|
||||
*
|
||||
* @return bool Returns any item in the cart that is synced and requires proration, otherwise, false.
|
||||
* @since 1.5
|
||||
* @deprecated 2.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v1.5
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
*/
|
||||
public static function cart_contains_prorated_subscription() {
|
||||
_deprecated_function( __METHOD__, '2.0' );
|
||||
@@ -1559,8 +1560,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Maybe recalculate the trial end date for synced subscription products that contain the unnecessary
|
||||
* "one day trial" period.
|
||||
*
|
||||
* @since 2.0
|
||||
* @deprecated 2.0.14
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.14
|
||||
*/
|
||||
public static function recalculate_trial_end_date( $trial_end_date, $recurring_cart, $product ) {
|
||||
_deprecated_function( __METHOD__, '2.0.14' );
|
||||
@@ -1576,8 +1577,8 @@ class WC_Subscriptions_Synchroniser {
|
||||
* Maybe recalculate the end date for synced subscription products that contain the unnecessary
|
||||
* "one day trial" period.
|
||||
*
|
||||
* @since 2.0.9
|
||||
* @deprecated 2.0.14
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.9
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.14
|
||||
*/
|
||||
public static function recalculate_end_date( $end_date, $recurring_cart, $product ) {
|
||||
_deprecated_function( __METHOD__, '2.0.14' );
|
||||
|
@@ -3,10 +3,9 @@
|
||||
* Tracker for Subscriptions usage.
|
||||
*
|
||||
* @class WC_Subscriptions_Tracker
|
||||
* @version 2.6.4
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.4
|
||||
* @package WooCommerce Subscriptions/Classes
|
||||
* @category Class
|
||||
* @author WooCommerce
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
@@ -19,7 +18,7 @@ class WC_Subscriptions_Tracker {
|
||||
public static function init() {
|
||||
// Only add data if Tracker enabled
|
||||
if ( 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) {
|
||||
add_filter( 'woocommerce_tracker_data', array( __CLASS__, 'add_subscriptions_tracking_data' ), 10, 1 );
|
||||
add_filter( 'woocommerce_tracker_data', [ __CLASS__, 'add_subscriptions_tracking_data' ], 10, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +41,7 @@ class WC_Subscriptions_Tracker {
|
||||
* @return array Subscriptions options data.
|
||||
*/
|
||||
private static function get_subscriptions_options() {
|
||||
return array(
|
||||
return [
|
||||
// Staging and live site
|
||||
'wc_subscriptions_staging' => WCS_Staging::is_duplicate_site() ? 'staging' : 'live',
|
||||
'wc_subscriptions_live_url' => esc_url( WCS_Staging::get_site_url_from_source( 'subscriptions_install' ) ),
|
||||
@@ -55,12 +54,12 @@ class WC_Subscriptions_Tracker {
|
||||
|
||||
// Renewals
|
||||
'accept_manual_renewals' => get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals' ),
|
||||
'turn_off_automatic_payments' => 'no' == get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals' ) ? 'none' : get_option( WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'none' ),
|
||||
'turn_off_automatic_payments' => 'no' === get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals' ) ? 'none' : get_option( WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'none' ),
|
||||
'enable_auto_renewal_toggle' => get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_auto_renewal_toggle' ),
|
||||
|
||||
// Early renewal
|
||||
'enable_early_renewal' => get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_early_renewal' ),
|
||||
'enable_early_renewal_via_modal' => 'no' == get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_early_renewal' ) ? 'none' : get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_early_renewal_via_modal', 'none' ),
|
||||
'enable_early_renewal_via_modal' => 'no' === get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_early_renewal' ) ? 'none' : get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_early_renewal_via_modal', 'none' ),
|
||||
|
||||
// Switching
|
||||
'allow_switching' => get_option( WC_Subscriptions_Admin::$option_prefix . '_allow_switching' ),
|
||||
@@ -71,8 +70,8 @@ class WC_Subscriptions_Tracker {
|
||||
|
||||
// Synchronization
|
||||
'sync_payments' => get_option( WC_Subscriptions_Admin::$option_prefix . '_sync_payments' ),
|
||||
'prorate_synced_payments' => $prorate_synced_payments = ( 'no' == get_option( WC_Subscriptions_Admin::$option_prefix . '_sync_payments' ) ? 'none' : get_option( WC_Subscriptions_Admin::$option_prefix . '_prorate_synced_payments', 'none' ) ),
|
||||
'days_no_fee' => 'recurring' == $prorate_synced_payments ? get_option( WC_Subscriptions_Admin::$option_prefix . '_days_no_fee', 'none' ) : 'none',
|
||||
'prorate_synced_payments' => $prorate_synced_payments = ( 'no' === get_option( WC_Subscriptions_Admin::$option_prefix . '_sync_payments' ) ? 'none' : get_option( WC_Subscriptions_Admin::$option_prefix . '_prorate_synced_payments', 'none' ) ),
|
||||
'days_no_fee' => 'recurring' === $prorate_synced_payments ? get_option( WC_Subscriptions_Admin::$option_prefix . '_days_no_fee', 'none' ) : 'none',
|
||||
|
||||
// Miscellaneous
|
||||
'max_customer_suspensions' => get_option( WC_Subscriptions_Admin::$option_prefix . '_max_customer_suspensions' ),
|
||||
@@ -80,7 +79,7 @@ class WC_Subscriptions_Tracker {
|
||||
'allow_zero_initial_order_without_payment_method' => get_option( WC_Subscriptions_Admin::$option_prefix . '_zero_initial_payment_requires_payment' ),
|
||||
'drip_downloadable_content_on_renewal' => get_option( WC_Subscriptions_Admin::$option_prefix . '_drip_downloadable_content_on_renewal' ),
|
||||
'enable_retry' => get_option( WC_Subscriptions_Admin::$option_prefix . '_enable_retry' ),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,71 +97,102 @@ class WC_Subscriptions_Tracker {
|
||||
/**
|
||||
* Gets subscription counts.
|
||||
*
|
||||
* @return array
|
||||
* @return array Subscription count by status. Keys are subscription status slugs, values are subscription counts (string).
|
||||
*/
|
||||
private static function get_subscription_counts() {
|
||||
$subscription_counts = array();
|
||||
$subscription_counts_data = wp_count_posts( 'shop_subscription' );
|
||||
$subscription_counts = [];
|
||||
$count_by_status = WC_Data_Store::load( 'subscription' )->get_subscriptions_count_by_status();
|
||||
foreach ( wcs_get_subscription_statuses() as $status_slug => $status_name ) {
|
||||
$subscription_counts[ $status_slug ] = $subscription_counts_data->{ $status_slug };
|
||||
$subscription_counts[ $status_slug ] = $count_by_status[ $status_slug ] ?? 0;
|
||||
}
|
||||
// Ensure all values are strings.
|
||||
$subscription_counts = array_map( 'strval', $subscription_counts );
|
||||
return $subscription_counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets subscription order counts and totals.
|
||||
*
|
||||
* @return array
|
||||
* @return array Subscription order counts and totals by type (initial, switch, renewal, resubscribe). Values are returned as strings.
|
||||
*/
|
||||
private static function get_subscription_orders() {
|
||||
global $wpdb;
|
||||
|
||||
$order_totals = array();
|
||||
$relation_types = array(
|
||||
$order_totals = [];
|
||||
$relation_types = [
|
||||
'switch',
|
||||
'renewal',
|
||||
'resubscribe',
|
||||
];
|
||||
|
||||
// Get the subtotal and count for each subscription type.
|
||||
foreach ( $relation_types as $relation_type ) {
|
||||
// Get orders with the given relation type.
|
||||
$relation_orders = wcs_get_orders_with_meta_query(
|
||||
[
|
||||
'type' => 'shop_order',
|
||||
'status' => [ 'wc-completed', 'wc-processing', 'wc-refunded' ],
|
||||
'limit' => -1,
|
||||
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
[
|
||||
'key' => '_subscription_' . $relation_type,
|
||||
'compare' => 'EXISTS',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
foreach ( $relation_types as $relation_type ) {
|
||||
// Sum the totals and count the orders.
|
||||
$count = count( $relation_orders );
|
||||
$total = array_reduce(
|
||||
$relation_orders,
|
||||
function( $total, $order ) {
|
||||
return $total + $order->get_total();
|
||||
},
|
||||
0
|
||||
);
|
||||
|
||||
$total_and_count = $wpdb->get_row( sprintf(
|
||||
"SELECT
|
||||
SUM( order_total.meta_value ) AS 'gross_total', COUNT( orders.ID ) as 'count'
|
||||
FROM {$wpdb->prefix}posts AS orders
|
||||
LEFT JOIN {$wpdb->prefix}postmeta AS order_relation ON order_relation.post_id = orders.ID
|
||||
LEFT JOIN {$wpdb->prefix}postmeta AS order_total ON order_total.post_id = orders.ID
|
||||
WHERE order_relation.meta_key = '_subscription_%s'
|
||||
AND orders.post_status in ( 'wc-completed', 'wc-processing', 'wc-refunded' )
|
||||
AND order_total.meta_key = '_order_total'
|
||||
GROUP BY order_total.meta_key
|
||||
", $relation_type
|
||||
), ARRAY_A );
|
||||
|
||||
$order_totals[ $relation_type . '_gross' ] = is_null( $total_and_count ) ? 0 : $total_and_count['gross_total'];
|
||||
$order_totals[ $relation_type . '_count' ] = is_null( $total_and_count ) ? 0 : $total_and_count['count'];
|
||||
$order_totals[ $relation_type . '_gross' ] = $total;
|
||||
$order_totals[ $relation_type . '_count' ] = $count;
|
||||
}
|
||||
|
||||
// Finally get the initial revenue and count
|
||||
$total_and_count = $wpdb->get_row(
|
||||
"SELECT
|
||||
SUM( order_total.meta_value ) AS 'gross_total', COUNT( * ) as 'count'
|
||||
FROM {$wpdb->prefix}posts AS orders
|
||||
LEFT JOIN {$wpdb->prefix}posts AS subscriptions ON subscriptions.post_parent = orders.ID
|
||||
LEFT JOIN {$wpdb->prefix}postmeta AS order_total ON order_total.post_id = orders.ID
|
||||
WHERE orders.post_status in ( 'wc-completed', 'wc-processing', 'wc-refunded' )
|
||||
AND subscriptions.post_type = 'shop_subscription'
|
||||
AND orders.post_type = 'shop_order'
|
||||
AND order_total.meta_key = '_order_total'
|
||||
GROUP BY order_total.meta_key
|
||||
", ARRAY_A );
|
||||
// Finally, get the initial revenue and count.
|
||||
// Get the orders for all initial subscription orders (no switch, renewal or resubscribe meta key).
|
||||
$initial_subscription_orders = wcs_get_orders_with_meta_query(
|
||||
[
|
||||
'type' => 'shop_order',
|
||||
'status' => [ 'wc-completed', 'wc-processing', 'wc-refunded' ],
|
||||
'limit' => -1,
|
||||
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
[
|
||||
'key' => '_subscription_switch',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
[
|
||||
'key' => '_subscription_renewal',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
[
|
||||
'key' => '_subscription_resubscribe',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$initial_order_total = is_null( $total_and_count ) ? 0 : $total_and_count['gross_total'];
|
||||
$initial_order_count = is_null( $total_and_count ) ? 0 : $total_and_count['count'];
|
||||
// Sum the totals and count the orders.
|
||||
$initial_order_count = count( $initial_subscription_orders );
|
||||
$initial_order_total = array_reduce(
|
||||
$initial_subscription_orders,
|
||||
function( $total, $order ) {
|
||||
return $total + $order->get_total();
|
||||
},
|
||||
0
|
||||
);
|
||||
|
||||
// Don't double count resubscribe revenue and count
|
||||
$order_totals['initial_gross'] = $initial_order_total - $order_totals['resubscribe_gross'];
|
||||
$order_totals['initial_count'] = $initial_order_count - $order_totals['resubscribe_count'];
|
||||
$order_totals['initial_gross'] = $initial_order_total;
|
||||
$order_totals['initial_count'] = $initial_order_count;
|
||||
|
||||
// Ensure all values are strings.
|
||||
$order_totals = array_map( 'strval', $order_totals );
|
||||
|
||||
return $order_totals;
|
||||
}
|
||||
@@ -170,28 +200,32 @@ class WC_Subscriptions_Tracker {
|
||||
/**
|
||||
* Gets first and last subscription created dates.
|
||||
*
|
||||
* @return array
|
||||
* @return array 'first' and 'last' created subscription dates as a string in the date format 'Y-m-d H:i:s' or '-'.
|
||||
*/
|
||||
private static function get_subscription_dates() {
|
||||
global $wpdb;
|
||||
|
||||
$min_max = $wpdb->get_row(
|
||||
"
|
||||
SELECT
|
||||
MIN( post_date_gmt ) as 'first', MAX( post_date_gmt ) as 'last'
|
||||
FROM {$wpdb->prefix}posts
|
||||
WHERE post_type = 'shop_subscription'
|
||||
AND post_status NOT IN ( 'trash', 'auto-draft' )
|
||||
",
|
||||
ARRAY_A
|
||||
// Ignore subscriptions with status 'trash'.
|
||||
$first = wcs_get_subscriptions(
|
||||
[
|
||||
'subscriptions_per_page' => 1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
'subscription_status' => [ 'active', 'on-hold', 'pending', 'cancelled', 'expired' ],
|
||||
]
|
||||
);
|
||||
$last = wcs_get_subscriptions(
|
||||
[
|
||||
'subscriptions_per_page' => 1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'subscription_status' => [ 'active', 'on-hold', 'pending', 'cancelled', 'expired' ],
|
||||
]
|
||||
);
|
||||
|
||||
if ( is_null( $min_max ) ) {
|
||||
$min_max = array(
|
||||
'first' => '-',
|
||||
'last' => '-',
|
||||
);
|
||||
}
|
||||
// Return each date in 'Y-m-d H:i:s' format or '-' if no subscriptions found.
|
||||
$min_max = [
|
||||
'first' => count( $first ) ? array_shift( $first )->get_date( 'date_created' ) : '-',
|
||||
'last' => count( $last ) ? array_shift( $last )->get_date( 'date_created' ) : '-',
|
||||
];
|
||||
|
||||
return $min_max;
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* Scheduler for subscription events that uses the Action Scheduler
|
||||
*
|
||||
* @class WCS_Action_Scheduler
|
||||
* @version 2.0.0
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.0.0
|
||||
* @package WooCommerce Subscriptions/Classes
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
@@ -15,7 +15,7 @@ class WCS_Action_Scheduler extends WCS_Scheduler {
|
||||
*
|
||||
* This variable has been deprecated and will be removed completely in the future. You should use WCS_Action_Scheduler::get_scheduled_action_hook() and WCS_Action_Scheduler::get_date_types_to_schedule() instead.
|
||||
*
|
||||
* @deprecated 2.6.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
|
||||
* @var array An array of $action_hook => $date_type values
|
||||
*/
|
||||
protected $action_hooks = array(
|
||||
|
@@ -5,7 +5,7 @@ use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface;
|
||||
* Class for integrating with WooCommerce Blocks
|
||||
*
|
||||
* @package WooCommerce Subscriptions
|
||||
* @since 3.1.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.1.0
|
||||
*/
|
||||
class WCS_Blocks_Integration implements IntegrationInterface {
|
||||
/**
|
||||
@@ -95,6 +95,6 @@ class WCS_Blocks_Integration implements IntegrationInterface {
|
||||
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( $file ) ) {
|
||||
return filemtime( $file );
|
||||
}
|
||||
return \WC_Subscriptions_Core_Plugin::instance()->get_plugin_version();
|
||||
return \WC_Subscriptions_Core_Plugin::instance()->get_library_version();
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@
|
||||
* Subscription Cached Data Manager Class
|
||||
*
|
||||
* @class WCS_Cached_Data_Manager
|
||||
* @version 2.3.0
|
||||
* @since 2.1.2
|
||||
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.2
|
||||
* @package WooCommerce Subscriptions/Classes
|
||||
* @category Class
|
||||
* @author Prospress
|
||||
@@ -73,16 +73,14 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager {
|
||||
public function purge_delete( $post_id, $post = null ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.3.0' );
|
||||
|
||||
$post_type = get_post_type( $post_id );
|
||||
|
||||
if ( 'shop_order' === $post_type ) {
|
||||
if ( 'shop_order' === WC_Data_Store::load( 'order' )->get_order_type( $post_id ) ) {
|
||||
wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Related order caching is now handled by %1$s.', 'woocommerce-subscriptions' ), 'WCS_Related_Order_Store' ) ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
|
||||
if ( is_callable( array( WCS_Related_Order_Store::instance(), 'delete_related_order_id_from_caches' ) ) ) {
|
||||
WCS_Related_Order_Store::instance()->delete_related_order_id_from_caches( $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'shop_subscription' === $post_type ) {
|
||||
if ( 'shop_subscription' === WC_Data_Store::load( 'subscription' )->get_order_type( $post_id ) ) {
|
||||
wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Customer subscription caching is now handled by %1$s.', 'woocommerce-subscriptions' ), 'WCS_Customer_Store_Cached_CPT' ) ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
|
||||
|
||||
// Purge wcs_do_subscriptions_exist cache, but only on the before_delete_post hook.
|
||||
@@ -110,7 +108,7 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager {
|
||||
wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Customer subscription caching is now handled by %1$s and %2$s.', 'woocommerce-subscriptions' ), 'WCS_Customer_Store_Cached_CPT', 'WCS_Post_Meta_Cache_Manager' ) ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
|
||||
|
||||
// Ensure we're handling a meta key we actually care about.
|
||||
if ( '_customer_user' !== $meta_key || 'shop_subscription' !== get_post_type( $object_id ) ) {
|
||||
if ( '_customer_user' !== $meta_key || 'shop_subscription' !== WC_Data_Store::load( 'subscription' )->get_order_type( $object_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,7 +119,7 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager {
|
||||
* Wrapper function to clear the cache that relates to related orders
|
||||
*
|
||||
* @param null $subscription_id
|
||||
* @deprecated 2.3.0
|
||||
* @deprecated 1.0.0 - Migrated from WooCommerce Subscriptions v2.3.0
|
||||
*/
|
||||
protected function clear_related_order_cache( $subscription_id ) {
|
||||
wcs_deprecated_function( __METHOD__, '2.3.0', __( 'new related order methods in WCS_Related_Order_Store', 'woocommerce-subscriptions' ) );
|
||||
@@ -198,7 +196,7 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager {
|
||||
/**
|
||||
* Check once each week if the log file has exceeded the limits.
|
||||
*
|
||||
* @since 2.2.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.9
|
||||
*/
|
||||
public function initialize_cron_check_size() {
|
||||
|
||||
@@ -215,7 +213,7 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager {
|
||||
* Add a weekly schedule for clearing up the cache
|
||||
*
|
||||
* @param $scheduled array
|
||||
* @since 2.2.9
|
||||
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.2.9
|
||||
*/
|
||||
function add_weekly_cron_schedule( $schedules ) {
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user