emails
1 year ago
class-experimental-abtest.php
1 year ago
connect-existing-pages.php
4 months ago
core-functions.php
3 years ago
feature-config.php
4 weeks ago
page-controller-functions.php
4 years ago
wc-admin-update-functions.php
4 months ago
core-functions.php
73 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Core Functions |
| 4 | * |
| 5 | * Holds core functions for wc-admin. |
| 6 | * |
| 7 | * @package WooCommerce\Admin\Functions |
| 8 | */ |
| 9 | |
| 10 | use Automattic\WooCommerce\Internal\Admin\Settings; |
| 11 | |
| 12 | /** |
| 13 | * Format a number using the decimal and thousands separator settings in WooCommerce. |
| 14 | * |
| 15 | * @param mixed $number Number to be formatted. |
| 16 | * @return string |
| 17 | */ |
| 18 | function wc_admin_number_format( $number ) { |
| 19 | $currency_settings = Settings::get_currency_settings(); |
| 20 | return number_format( |
| 21 | $number, |
| 22 | 0, |
| 23 | $currency_settings['decimalSeparator'], |
| 24 | $currency_settings['thousandSeparator'] |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Retrieves a URL to relative path inside WooCommerce admin with |
| 30 | * the provided query parameters. |
| 31 | * |
| 32 | * @param string $path Relative path of the desired page. |
| 33 | * @param array $query Query parameters to append to the path. |
| 34 | * |
| 35 | * @return string Fully qualified URL pointing to the desired path. |
| 36 | */ |
| 37 | function wc_admin_url( $path = null, $query = array() ) { |
| 38 | if ( ! empty( $query ) ) { |
| 39 | $query_string = http_build_query( $query ); |
| 40 | $path = $path ? '&path=' . $path . '&' . $query_string : ''; |
| 41 | } |
| 42 | |
| 43 | return admin_url( 'admin.php?page=wc-admin' . $path, dirname( __FILE__ ) ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Record an event using Tracks. |
| 48 | * |
| 49 | * @internal WooCommerce core only includes Tracks in admin, not the REST API, so we need to include it. |
| 50 | * @param string $event_name Event name for tracks. |
| 51 | * @param array $properties Properties to pass along with event. |
| 52 | */ |
| 53 | function wc_admin_record_tracks_event( $event_name, $properties = array() ) { |
| 54 | // WC post types must be registered first for WC_Tracks to work. |
| 55 | if ( ! post_type_exists( 'product' ) ) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if ( ! class_exists( 'WC_Tracks' ) ) { |
| 60 | if ( ! defined( 'WC_ABSPATH' ) || ! file_exists( WC_ABSPATH . 'includes/tracks/class-wc-tracks.php' ) ) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks.php'; |
| 65 | include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-event.php'; |
| 66 | include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-client.php'; |
| 67 | include_once WC_ABSPATH . 'includes/tracks/class-wc-tracks-footer-pixel.php'; |
| 68 | include_once WC_ABSPATH . 'includes/tracks/class-wc-site-tracking.php'; |
| 69 | } |
| 70 | |
| 71 | WC_Tracks::record_event( $event_name, $properties ); |
| 72 | } |
| 73 |