WC_Gateway_Paypal::enqueue_scripts
Enqueue scripts.
Method of the class: WC_Gateway_Paypal{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Gateway_Paypal = new WC_Gateway_Paypal(); $WC_Gateway_Paypal->enqueue_scripts();
WC_Gateway_Paypal::enqueue_scripts() WC Gateway Paypal::enqueue scripts code WC 10.7.0
public function enqueue_scripts() {
if ( 'no' === $this->enabled ) {
return;
}
$version = Constants::get_constant( 'WC_VERSION' );
$is_page_supported = is_checkout() || is_cart() || is_product();
$buttons = new PayPalButtons( $this );
$options = $buttons->get_common_options();
if ( empty( $options['client-id'] ) || ! $is_page_supported ) {
return;
}
$sdk_host = $this->testmode ? 'https://www.sandbox.paypal.com/sdk/js' : 'https://www.paypal.com/sdk/js';
// Add PayPal JS SDK script.
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_register_script( 'paypal-standard-sdk', add_query_arg( $options, $sdk_host ), array(), null, false );
wp_enqueue_script( 'paypal-standard-sdk' );
wp_register_script( 'wc-paypal-frontend', WC()->plugin_url() . '/client/legacy/js/gateways/paypal.js', array( 'jquery', 'wp-api-fetch' ), $version, true );
wp_localize_script(
'wc-paypal-frontend',
'paypal_standard',
array(
'gateway_id' => $this->id,
'is_product_page' => is_product(),
'app_switch_request_origin' => $buttons->get_current_page_for_app_switch(),
'wc_store_api_nonce' => wp_create_nonce( 'wc_store_api' ),
'create_order_nonce' => wp_create_nonce( 'wc_gateway_paypal_standard_create_order' ),
'cancel_payment_nonce' => wp_create_nonce( 'wc_gateway_paypal_standard_cancel_payment' ),
'generic_error_message' => __( 'An unknown error occurred', 'woocommerce' ),
)
);
wp_enqueue_script( 'wc-paypal-frontend' );
}