mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
fix gitignore & add assets registration functionality.
This commit is contained in:
parent
afc2d31852
commit
3a2d72aa5c
2 changed files with 101 additions and 1 deletions
2
modules/ppcp-order-tracking/.gitignore
vendored
2
modules/ppcp-order-tracking/.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
assets
|
/assets
|
||||||
|
|
100
modules/ppcp-order-tracking/src/Assets/OrderEditPageAssets.php
Normal file
100
modules/ppcp-order-tracking/src/Assets/OrderEditPageAssets.php
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Register and configure assets for order edit page.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\OrderTracking\Assets
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\OrderTracking\Assets;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OrderEditPageAssets
|
||||||
|
*/
|
||||||
|
class OrderEditPageAssets {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL to the module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebhooksStatusPageAssets constructor.
|
||||||
|
*
|
||||||
|
* @param string $module_url The URL to the module.
|
||||||
|
* @param string $version The assets version.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the scripts and styles.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register(): void {
|
||||||
|
wp_register_style(
|
||||||
|
'ppcp-webhooks-order-edit-page-style',
|
||||||
|
untrailingslashit( $this->module_url ) . '/assets/css/order-edit-page.css',
|
||||||
|
array(),
|
||||||
|
$this->version
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-tracking',
|
||||||
|
untrailingslashit( $this->module_url ) . '/assets/js/order-edit-page.js',
|
||||||
|
array( 'jquery' ),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_localize_script(
|
||||||
|
'ppcp-tracking',
|
||||||
|
'PayPalCommerceGatewayOrderTrackingInfo',
|
||||||
|
$this->get_script_data()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data for the script.
|
||||||
|
*
|
||||||
|
* @return array a map of script data.
|
||||||
|
*/
|
||||||
|
public function get_script_data(): array {
|
||||||
|
return array(
|
||||||
|
'ajax' => array(
|
||||||
|
'tracking_info' => array(
|
||||||
|
'endpoint' => \WC_AJAX::get_endpoint( OrderTrackingEndpoint::ENDPOINT ),
|
||||||
|
'nonce' => wp_create_nonce( OrderTrackingEndpoint::nonce() ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues the necessary scripts.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function enqueue(): void {
|
||||||
|
wp_enqueue_style( 'ppcp-webhooks-order-edit-page-style' );
|
||||||
|
wp_enqueue_script( 'ppcp-tracking' );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue