rder->get_shipping_methods();
foreach ( $order_shipping_methods as $shipping_id => $shipping_method ) {
if ( isset( $shipping_method['item_meta'] )
&& isset( $shipping_method['item_meta']['_fs_method'] )
) {
$fs_method = $shipping_method['item_meta']['_fs_method'];
if ( ! empty( $fs_method['method_integration'] ) ) {
$order_meta = $order->get_meta( '_flexible_shipping_integration', false );
if ( ! in_array( $fs_method['method_integration'], $order_meta, true ) ) {
$order->add_meta_data( '_flexible_shipping_integration', $fs_method['method_integration'] );
}
}
}
}
$mutex->releaseLock();
}
}
/**
* Set appropriate default FS method if no method chosen.
*
* @param string $default Default shipping method in frontend.
* @param WC_Shipping_Rate[] $available_methods Available methods in frontend.
* Function is assigned to woocommerce_default_shipment_method filter.
* In this parameter we expecting array of WC_Shipping_Rate objects.
* But third party plugins can change this parameter type or set it to
* null.
* @param string|bool|null $chosen_method If false or null then no method is chosen.
*
* @return string
*/
public function woocommerce_default_shipment_method( $default, $available_methods, $chosen_method ) {
if ( ! is_array( $available_methods ) ) {
return $default;
}
if ( null === $chosen_method || false === $chosen_method ) {
foreach ( $available_methods as $available_method ) {
$method_meta = $available_method->get_meta_data();
if ( $method_meta && isset( $method_meta[ WPDesk_Flexible_Shipping::META_DEFAULT ] ) && 'yes' === $method_meta[ WPDesk_Flexible_Shipping::META_DEFAULT ] ) {
$candidate_id = $available_method->get_id();
if ( array_key_exists( $candidate_id, $available_methods ) ) {
return $candidate_id;
}
}
}
}
return $default;
}
/**
* @param string $suffix .
*/
private function enqueue_rules_scripts( $suffix ) {
wp_register_script(
'fs_rules_settings',
trailingslashit( $this->get_plugin_assets_url() ) . 'js/rules-settings.js',
[ 'wp-i18n' ],
$this->scripts_version
);
wp_enqueue_script( 'fs_rules_settings' );
wp_enqueue_style(
'fs_rules_settings',
trailingslashit( $this->get_plugin_assets_url() ) . 'css/rules-settings.css',
[],
$this->scripts_version
);
wp_set_script_translations( 'fs_rules_settings', 'flexible-shipping', $this->plugin_path . '/lang/' );
}
/**
* Admin enqueue scripts.
*/
public function admin_enqueue_scripts() {
if ( $this->should_enqueue_admin_scripts() ) {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script(
'fs_admin',
trailingslashit( $this->get_plugin_assets_url() ) . 'js/admin' . $suffix . '.js',
[ 'jquery' ],
$this->scripts_version
);
$notice_url = get_locale() == 'pl_PL' ? 'https://octol.io/fs-rate-not-good-pl' : 'https://octol.io/fs-rate-not-good';
wp_localize_script(
'fs_admin',
'fs_admin',
[
'ajax_url' => admin_url( 'admin-ajax.php' ),
'notice_not_good_enought' => sprintf(
// Translators: link.
__( 'How can We make Flexible Shipping better for you? %1$sJust write to us.%2$s', 'flexible-shipping' ),
'',
''
),
]
);
wp_enqueue_script( 'fs_admin' );
$current_screen = get_current_screen();
wp_register_script(
'wpdesk_contextual_info',
trailingslashit( $this->get_plugin_assets_url() ) . 'js/contextual-info' . $suffix . '.js',
[ 'jquery' ],
$this->scripts_version
);
wp_enqueue_script( 'wpdesk_contextual_info' );
if ( ! empty( $current_screen ) && 'shop_order' === $current_screen->id ) {
wp_enqueue_media();
}
wp_enqueue_style(
'fs_admin',
trailingslashit( $this->get_plugin_assets_url() ) . 'css/admin.css',
[],
$this->scripts_version
);
wp_enqueue_style(
'fs_font',
trailingslashit( $this->get_plugin_assets_url() ) . 'css/font' . $suffix . '.css',
[],
$this->scripts_version
);
$this->enqueue_rules_scripts( $suffix );
do_action( 'flexible-shipping/admin/enqueue_scripts', $this, $suffix );
}
}
/**
* Should enqueue admin scripts?
*/
private function should_enqueue_admin_scripts() {
$current_screen = get_current_screen();
if ( ! $current_screen ) {
return false;
}
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
if (
'woocommerce_page_wc-orders' === $current_screen->id
|| in_array( $current_screen->post_type, [ 'shop_order', 'shop_subscription', ], true )
|| $wc_screen_id . '_page_wc-settings' === $current_screen->id
|| 'woocommerce_page_wc-settings' === $current_screen->id ) {
return true;
}
return false;
}
/**
* Enqueue Wordpress scripts.
*/
public function wp_enqueue_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
}
/**
* Links filter.
*
* @param array $links .
*
* @return array
*/
public function links_filter( $links ) {
$docs_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-docs-pl' : 'https://octol.io/fs-docs';
$support_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-support-pl' : 'https://octol.io/fs-support';
$settings_url = admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=' . WPDesk_Flexible_Shipping_Settings::METHOD_ID );
$plugin_links = [
'' . __(
'Settings',
'flexible-shipping'
) . '',
'' . __( 'Docs', 'flexible-shipping' ) . '',
'' . __( 'Support', 'flexible-shipping' ) . '',
];
$pro_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-upgrade-pl' : 'https://octol.io/fs-upgrade';
if ( ! wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) ) {
$plugin_links[] = '' . __(
'Buy PRO',
'flexible-shipping'
) . '';
}
return array_merge( $plugin_links, $links );
}
/**
* .
* @param string $method_id .
* @param array $shipping_method .
*
* @return string
*/
public function flexible_shipping_method_rate_id( $method_id, array $shipping_method ) {
if ( isset( $shipping_method['id_for_shipping'] ) && '' !== $shipping_method['id_for_shipping'] ) {
$method_id = $shipping_method['id_for_shipping'];
}
return $method_id;
}
}