Automattic\WooCommerce\Internal\Admin
ShippingLabelBanner::add_print_shipping_label_script()
Adds JS to order page to render shipping banner.
Method of the class: ShippingLabelBanner{}
No Hooks.
Return
null
. Nothing (null).
Usage
$ShippingLabelBanner = new ShippingLabelBanner(); $ShippingLabelBanner->add_print_shipping_label_script( $hook );
- $hook(string) (required)
- current page hook.
ShippingLabelBanner::add_print_shipping_label_script() ShippingLabelBanner::add print shipping label script code WC 9.3.3
public function add_print_shipping_label_script( $hook ) { WCAdminAssets::register_style( 'print-shipping-label-banner', 'style', array( 'wp-components' ) ); WCAdminAssets::register_script( 'wp-admin-scripts', 'print-shipping-label-banner', true ); $wcst_version = null; $wcshipping_installed_version = null; $order = wc_get_order(); if ( class_exists( '\WC_Connect_Loader' ) ) { $wcst_version = \WC_Connect_Loader::get_wcs_version(); } $wc_shipping_plugin_file = WP_PLUGIN_DIR . '/woocommerce-shipping/woocommerce-shipping.php'; if ( file_exists( $wc_shipping_plugin_file ) ) { $plugin_data = get_plugin_data( $wc_shipping_plugin_file ); $wcshipping_installed_version = $plugin_data['Version']; } $payload = array( // If WCS&T is not installed, it's considered compatible. 'is_wcst_compatible' => $wcst_version ? (int) version_compare( $wcst_version, self::MIN_COMPATIBLE_WCST_VERSION, '>=' ) : 1, 'order_id' => $order ? $order->get_id() : null, // The banner is shown if the plugin is installed but not active, so we need to check if the installed version is compatible. 'is_incompatible_wcshipping_installed' => $wcshipping_installed_version ? (int) version_compare( $wcshipping_installed_version, self::MIN_COMPATIBLE_WCSHIPPING_VERSION, '<' ) : 0, ); wp_localize_script( 'wc-admin-print-shipping-label-banner', 'wcShippingCoreData', $payload ); }