first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
<?php
/**
* Contextual info.
*
* @package Contextual Info
*/
/**
* Can add contextual info script to admin footer.
*/
class Flexible_Shipping_Contextual_Info implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
/**
* .
*
* @var string
*/
private $html_elements_ids;
/**
* .
*
* @var string
*/
private $info_id;
/**
* .
*
* @var string[]
*/
private $phrases_in;
/**
* .
*
* @var string
*/
private $info_html;
/**
* @var string[]
*/
private $phrases_not_in;
/**
* Flexible_Shipping_Contextual_Info constructor.
*
* @param string $html_elements_ids Comma separated HTML element IDs to add contextual info.
* @param string $info_id Info element ID.
* @param array $phrases_in Phrases to display contextual info.
* @param string $info_html HTML code to display as info.
* @param array $phrases_not_in Phrases to not display contextual info.
*/
public function __construct(
$html_elements_ids,
$info_id,
array $phrases_in,
$info_html,
array $phrases_not_in = array()
) {
$this->html_elements_ids = $html_elements_ids;
$this->info_id = $info_id;
$this->phrases_in = $phrases_in;
$this->info_html = $info_html;
$this->phrases_not_in = $phrases_not_in;
}
/**
* Hooks.
*/
public function hooks() {
add_action( 'admin_footer', array( $this, 'add_contextual_info_script' ) );
}
/**
* Add contextual info script.
*/
public function add_contextual_info_script() {
$current_screen = get_current_screen();
if ( 'shop_order' === $current_screen->post_type || 'woocommerce_page_wc-settings' === $current_screen->id ) {
$html_elements_ids = '#' . implode( ',#', explode( ',', $this->html_elements_ids ) );
$info_id = $this->info_id;
$phrases_in = $this->phrases_in;
$info_html = $this->info_html;
$phrases_not_in = $this->phrases_not_in;
include __DIR__ . '/views/contextual-info-script.php';
}
}
}

View File

@@ -0,0 +1,851 @@
<?php
/**
* Plugin.
*
* @package Flexible Shippign
*/
use FSVendor\Octolize\BetterDocs\Beacon\BeaconOptions;
use FSVendor\Octolize\ShippingExtensions\ShippingExtensions;
use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayAndConditions;
use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayGetParameterValue;
use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayOrConditions;
use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayShippingMethodInstanceSettings;
use FSVendor\Octolize\Tracker\TrackerInitializer;
use FSVendor\WPDesk\FS\Compatibility\PluginCompatibility;
use FSVendor\WPDesk\FS\Shipment\ShipmentFunctionality;
use FSVendor\WPDesk\FS\TableRate\Logger\Assets;
use FSVendor\WPDesk\Logger\WPDeskLoggerFactory;
use FSVendor\WPDesk\Mutex\WordpressPostMutex;
use FSVendor\WPDesk\Notice\AjaxHandler;
use FSVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
use FSVendor\WPDesk\PluginBuilder\Plugin\Activateable;
use FSVendor\WPDesk\PluginBuilder\Plugin\HookableCollection;
use FSVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
use FSVendor\WPDesk\PluginBuilder\Plugin\TemplateLoad;
use FSVendor\WPDesk\RepositoryRating\DisplayStrategy\ShippingMethodDisplayDecision;
use FSVendor\WPDesk\RepositoryRating\RepositoryRatingPetitionText;
use FSVendor\WPDesk\RepositoryRating\TextPetitionDisplayer;
use FSVendor\WPDesk\Session\SessionFactory;
use FSVendor\WPDesk\View\Resolver\ChainResolver;
use FSVendor\WPDesk\View\Resolver\DirResolver;
use FSVendor\WPDesk\View\Resolver\WPThemeResolver;
use FSVendor\WPDesk\WooCommerce\CurrencySwitchers\FilterConvertersFactory;
use FSVendor\WPDesk\WooCommerce\CurrencySwitchers\ShippingIntegrations;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use WPDesk\FS\Helpers\FlexibleShippingMethodsChecker;
use WPDesk\FS\Helpers\WooSettingsPageChecker;
use WPDesk\FS\Integration\ExternalPluginAccess;
use WPDesk\FS\Onboarding\TableRate\Onboarding;
use WPDesk\FS\Onboarding\TableRate\FinishOption;
use WPDesk\FS\Onboarding\TableRate\OptionAjaxUpdater;
use WPDesk\FS\Onboarding\TableRate\PopupData;
use WPDesk\FS\Plugin\PluginActivation;
use WPDesk\FS\ProVersion\ProVersionUpdateReminder;
use WPDesk\FS\TableRate\Beacon\Beacon;
use WPDesk\FS\TableRate\Beacon\BeaconClickedAjax;
use WPDesk\FS\TableRate\Beacon\BeaconDeactivationTracker;
use WPDesk\FS\TableRate\Beacon\BeaconDisplayStrategy;
use WPDesk\FS\TableRate\Debug\MultipleShippingZonesMatchedSameTerritoryNotice;
use WPDesk\FS\TableRate\Debug\MultipleShippingZonesMatchedSameTerritoryTracker;
use WPDesk\FS\TableRate\Debug\NoShippingMethodsNotice;
use WPDesk\FS\TableRate\Debug\DebugTracker;
use WPDesk\FS\TableRate\FreeShipping\FreeShippingNotice;
use WPDesk\FS\TableRate\FreeShipping\FreeShippingNoticeGenerator;
use WPDesk\FS\TableRate\FreeShipping\FreeShippingNoticeRenderer;
use WPDesk\FS\TableRate\FreeShipping\NoticeTextSettings;
use WPDesk\FS\TableRate\FreeShipping\ProgressBarSettings;
use WPDesk\FS\TableRate\ImporterExporter\Exporter;
use WPDesk\FS\TableRate\ImporterExporter\ExporterData;
use WPDesk\FS\TableRate\ImporterExporter\ImporterData;
use WPDesk\FS\TableRate\MultiCurrency;
use WPDesk\FS\TableRate\Order\ItemMeta;
use WPDesk\FS\TableRate\Rule\PreconfiguredScenarios;
use WPDesk\FS\ProFeatures;
use WPDesk\FS\TableRate\Rule\TrackerData;
use WPDesk\FS\TableRate\RulesSettingsField;
use WPDesk\FS\TableRate\ShippingMethod\BlockEditing\BlockEditing;
use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertAction;
use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertNotice;
use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertTracker;
use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateAction;
use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateNotice;
use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateScript;
use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateTracker;
use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicatorChecker;
use WPDesk\FS\TableRate\ShippingMethod\Management\ShippingMethodManagement;
use WPDesk\FS\TableRate\ShippingMethod\MethodTitle;
use WPDesk\FS\TableRate\ShippingMethod\MethodDescription;
use WPDesk\FS\TableRate\ShippingMethodSingle;
use WPDesk\FS\TableRate\Tax\Tracker;
use WPDesk\FS\TableRate\UserFeedback;
use WPDesk\FS\TableRate\ContextualInfo;
use WPDesk\FS\Shipment;
/**
* Class Flexible_Shipping_Plugin
*/
class Flexible_Shipping_Plugin extends AbstractPlugin implements HookableCollection, Activateable {
use HookableParent;
use TemplateLoad;
/*
* Plugin file
*/
const PLUGIN_FILE = 'flexible-shipping/flexible-shipping.php';
const PRIORITY_BEFORE_SHARED_HELPER = -35;
const PRIORITY_LAST = 999999;
const PRIORITY_AFTER_DEFAULT = 20;
const FS_FREE_SHIPPING_NOTICE_NAME = 'fs_free_shipping_notice';
/**
* Scripts version.
*
* @var string
*/
private $scripts_version = '2';
/**
* Admin notices.
*
* @var WPDesk_Flexible_Shipping_Admin_Notices
*/
public $admin_notices;
/**
* Default settings tab.
*
* @var string
*/
private $default_settings_tab = 'connect';
/**
* Renderer.
*
* @var FSVendor\WPDesk\View\Renderer\Renderer;
*/
private $renderer;
/**
* Is order processed on checkout?
*
* @var bool
*/
private $is_order_processed_on_checkout = false;
/**
* Logger.
*
* @var LoggerInterface
*/
private $logger;
/**
* Flexible_Invoices_Reports_Plugin constructor.
*
* @param FSVendor\WPDesk_Plugin_Info $plugin_info Plugin info.
*/
public function __construct( FSVendor\WPDesk_Plugin_Info $plugin_info ) {
$this->scripts_version = FLEXIBLE_SHIPPING_VERSION . '.' . $this->scripts_version;
$this->plugin_info = $plugin_info;
parent::__construct( $this->plugin_info );
$this->init_logger();
$this->init_logger_on_shipment();
}
/**
* Init logger on WPDesk_Flexible_Shipping_Shipment class.
*/
private function init_logger_on_shipment() {
// WPDesk_Flexible_Shipping_Shipment::set_fs_logger( $this->logger );
}
/**
* Init logger on WPDesk_Flexible_Shipping class.
*
* @internal
*/
public function init_logger_on_shipping_method() {
WPDesk_Flexible_Shipping::set_fs_logger( $this->logger );
ShippingMethodSingle::set_fs_logger( $this->logger );
}
/**
* Initialize $this->logger
*
* @return LoggerInterface
*/
private function init_logger() {
$logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings();
if ( $logger_settings->is_enabled() ) {
add_filter( 'wpdesk_is_wp_log_capture_permitted', '__return_false' );
return $this->logger = ( new WPDeskLoggerFactory() )->createWPDeskLogger( $logger_settings->get_logger_channel_name() );
}
return $this->logger = new NullLogger();
}
/**
* Load dependencies.
*/
private function load_dependencies() {
global $wpdb;
require_once __DIR__ . '/../inc/functions.php';
$session_factory = new SessionFactory();
$this->add_hookable( new ShipmentFunctionality( $this->logger, trailingslashit( $this->get_plugin_assets_url() ) . '../vendor_prefixed/wpdesk/wp-wpdesk-fs-shipment/assets/', $this->scripts_version ) );
$this->add_hookable( new Shipment\FilterOrders() );
$this->add_hookable( new Shipment\ModifyStatuses() );
$this->add_hookable( new Shipment\DispatchLabelFile() );
$this->add_hookable( new Shipment\BulkAction( $session_factory ) );
$this->add_hookable( new Shipment\AdminNotices( $session_factory ) );
$this->add_hookable( new Shipment\ModifyOrderTable( $session_factory ) );
new WPDesk_Flexible_Shipping_Multilingual( $this );
$this->admin_notices = new WPDesk_Flexible_Shipping_Admin_Notices( $this );
$this->add_hookable( new WPDesk\FS\Rate\WPDesk_Flexible_Shipping_Rate_Notice() );
$this->add_hookable(
new TextPetitionDisplayer(
'woocommerce_after_settings_shipping',
new ShippingMethodDisplayDecision( new \WC_Shipping_Zones(), ShippingMethodSingle::SHIPPING_METHOD_ID ),
new RepositoryRatingPetitionText(
'Octolize',
$this->plugin_info->get_plugin_name(),
'https://octol.io/fs-rate',
'center'
)
)
);
$this->add_hookable( new WPDesk_Flexible_Shipping_Shorcode_Unit_Weight() );
$this->add_hookable( new WPDesk_Flexible_Shipping_Shorcode_Unit_Dimension() );
$this->add_hookable( new AjaxHandler( trailingslashit( $this->get_plugin()->get_plugin_url() ) . 'vendor_prefixed/wpdesk/wp-notice/assets' ) );
$this->add_hookable( new WPDesk_Flexible_Shipping_Method_Created_Tracker_Deactivation_Data() );
$this->add_hookable( new WPDesk_Flexible_Shipping_Logger_Downloader( new WPDeskLoggerFactory() ) );
$this->add_hookable( new ShippingIntegrations( 'flexible_shipping' ) );
$this->add_hookable( new WPDesk_Flexible_Shipping_Order_Item_Meta() );
$this->add_hookable( new Assets( trailingslashit( $this->get_plugin_url() ) . 'vendor_prefixed/wpdesk/wp-wpdesk-fs-table-rate/assets', $this->scripts_version ) );
$this->add_hookable( new NoShippingMethodsNotice(
current_user_can( 'manage_woocommerce' ) && 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' )
) );
$this->add_hookable( new DebugTracker() );
$this->add_hookable( new PluginCompatibility() );
$this->add_hookable( new UserFeedback() );
//Onboarding
$setting_page_checker = new WooSettingsPageChecker();
$fs_methods_checker = new FlexibleShippingMethodsChecker();
$finish_option = new FinishOption();
$this->add_hookable( new OptionAjaxUpdater( $finish_option ) );
$this->add_hookable( new Onboarding(
$finish_option,
$this->scripts_version,
trailingslashit( $this->get_plugin_assets_url() ),
$setting_page_checker,
$fs_methods_checker,
( new PopupData() )->get_popups()
)
);
$this->add_hookable( new \WPDesk\FS\Onboarding\TableRate\Tracker( $finish_option ) );
$this->add_hookable( new ShippingExtensions( $this->plugin_info ) );
$this->add_hookable( new MethodTitle() );
$this->add_hookable( new MethodDescription( $this->renderer ) );
$this->add_hookable( new Exporter() );
$this->add_hookable( new ImporterData() );
$this->add_hookable( new ExporterData() );
$shipping_method_management = new ShippingMethodManagement( $wpdb );
// Converter.
$this->add_hookable( new ConvertAction( $shipping_method_management ) );
$this->add_hookable( new ConvertNotice() );
$this->add_hookable( new ConvertTracker() );
// Duplicate FS Method.
$duplicator_checker = new DuplicatorChecker( $shipping_method_management );
$this->add_hookable( new DuplicateAction( $duplicator_checker, $shipping_method_management ) );
$this->add_hookable( new DuplicateNotice() );
$this->add_hookable( new DuplicateTracker() );
$this->add_hookable( new DuplicateScript(
trailingslashit( $this->get_plugin_assets_url() ),
$this->scripts_version
)
);
// Block Settings.
$this->add_hookable( new BlockEditing() );
$this->add_hookable( new ItemMeta() );
$this->add_hookable( new PreconfiguredScenarios\Tracker\AjaxTracker() );
$this->add_hookable( new PreconfiguredScenarios\Tracker\Tracker() );
// Pro Features.
$tracking_data = new ProFeatures\Tracker\TrackingData();
$this->add_hookable( new ProFeatures\Tracker\AjaxTracker( $tracking_data ) );
$this->add_hookable( new ProFeatures\Tracker\Tracker( $tracking_data ) );
$this->add_hookable( new PluginActivation() );
$this->add_hookable( new MultipleShippingZonesMatchedSameTerritoryTracker() );
$this->add_hookable( new Tracker() );
$this->add_hookable( new ProVersionUpdateReminder( 'pl_PL' === get_locale() ) );
}
/**
* Init beacon.
*/
public function init_beacon() {
if ( 'pl_PL' !== get_locale() ) {
$strategy = new BeaconDisplayStrategy();
$beacon = new Beacon(
$strategy,
trailingslashit( $this->get_plugin_url() ) . 'vendor_prefixed/octolize/wp-betterdocs-beacon/assets/'
);
$beacon->hooks();
$beacon_clicked_ajax = new BeaconClickedAjax( $strategy, $this->get_plugin_assets_url(), $this->scripts_version );
$beacon_clicked_ajax->hooks();
( new BeaconDeactivationTracker() )->hooks();
}
}
/**
* Init contextual info on Flexible Shipping settings fields.
*
* @internal
*/
public function init_contextual_info() {
$base_location = wc_get_base_location();
$base_country = $base_location['country'];
$contextual_info_creator = new ContextualInfo\Creator( $base_country );
$contextual_info_creator->create_contextual_info();
$contextual_info_creator->hooks();
}
/**
* Init base variables for plugin
*/
public function init_base_variables() {
$this->plugin_url = $this->plugin_info->get_plugin_url();
$this->plugin_path = $this->plugin_info->get_plugin_dir();
$this->template_path = $this->plugin_info->get_text_domain();
$this->plugin_namespace = $this->plugin_info->get_text_domain();
$this->template_path = $this->plugin_info->get_text_domain();
$this->default_settings_tab = 'main';
$this->settings_url = admin_url( 'admin.php?page=flexible-shipping-settings' );
$this->docs_url = get_locale() === 'pl_PL' ? 'https://octol.io/fs-docs-pl' : 'https://octol.io/fs-docs';
}
/**
* Set renderer.
*/
private function init_renderer() {
$resolver = new ChainResolver();
$resolver->appendResolver( new WPThemeResolver( $this->get_template_path() ) );
$resolver->appendResolver( new DirResolver( trailingslashit( $this->plugin_path ) . 'templates' ) );
$this->renderer = new FSVendor\WPDesk\View\Renderer\SimplePhpRenderer( $resolver );
}
/**
* Init.
*/
public function init() {
$this->init_base_variables();
$this->init_renderer();
$this->load_dependencies();
$this->init_tracker();
$this->hooks();
$this->init_assets_url_on_rules_settings_field();
}
/**
* register_activation_hook handler.
*
* @internal
*/
public function activate() {
( new PluginActivation() )->add_activation_option_if_not_present();
}
/**
* Hooks.
*/
public function hooks() {
parent::hooks();
add_filter( 'woocommerce_shipping_methods', [
$this,
'woocommerce_shipping_methods_filter',
], self::PRIORITY_AFTER_DEFAULT );
add_filter(
'flexible_shipping_method_rate_id',
[
$this,
'flexible_shipping_method_rate_id',
],
9999999,
2
);
add_filter(
'woocommerce_shipping_chosen_method',
[
$this,
'woocommerce_default_shipment_method',
],
10,
3
);
add_action(
'woocommerce_checkout_create_order',
[
$this,
'add_flexible_shipping_order_meta_on_checkout',
]
);
add_filter( 'option_woocommerce_cod_settings', [ $this, 'option_woocommerce_cod_settings' ] );
add_action( 'woocommerce_init', [ $this, 'init_free_shipping_notice' ] );
add_action( 'woocommerce_init', [ $this, 'init_logger_on_shipping_method' ] );
add_action( 'woocommerce_init', [ $this, 'init_contextual_info' ] );
add_action( 'woocommerce_init', [ $this, 'init_beacon' ] );
add_action( 'woocommerce_init', [ $this, 'init_shipping_zones_notice' ] );
add_action( 'woocommerce_init', [ $this, 'init_multicurrency' ] );
add_action( 'woocommerce_init', [ $this, 'init_external_plugin_access' ] );
$this->hooks_on_hookable_objects();
}
/**
* .
*/
public function init_multicurrency() {
$prefix = 'flexible-shipping';
( new FilterConvertersFactory( $prefix ) )->hooks();
( new MultiCurrency( $this->logger, $prefix ) )->hooks();
}
/**
* .
*/
public function init_external_plugin_access() {
do_action( 'flexible-shipping/core/initialized', new ExternalPluginAccess( $this->plugin_info->get_version(), $this->logger ) );
}
/**
* .
* @internal
*/
public function init_shipping_zones_notice() {
( new MultipleShippingZonesMatchedSameTerritoryNotice( WC()->countries, new WC_Shipping_Zones() ) )->hooks();
}
/**
*
*/
private function init_assets_url_on_rules_settings_field() {
RulesSettingsField::set_assets_url( untrailingslashit( $this->get_plugin_assets_url() ) );
}
/**
* Init free shipping notice.
*
* @internal
*/
public function init_free_shipping_notice() {
$cart = WC()->cart;
$session = WC()->session;
if ( $cart instanceof WC_Cart && $session instanceof WC_Session ) {
( new FreeShippingNoticeGenerator( $cart, $session, self::FS_FREE_SHIPPING_NOTICE_NAME ) )->hooks();
( new FreeShippingNotice( $cart, $session, self::FS_FREE_SHIPPING_NOTICE_NAME ) )->hooks();
( new \WPDesk\FS\TableRate\FreeShipping\Assets( $this->get_plugin_assets_url(), $this->scripts_version ) )->hooks();
( new FreeShippingNoticeRenderer( $this->renderer ) )->hooks();
}
( new NoticeTextSettings() )->hooks();
( new ProgressBarSettings() )->hooks();
( new \WPDesk\FS\TableRate\FreeShipping\Tracker() )->hooks();
}
/**
* Init tracker.
*/
private function init_tracker() {
$this->add_hookable(
TrackerInitializer::create_from_plugin_info( $this->plugin_info, $this->prepare_shoud_display_for_flexible_shipping() )
);
$this->add_hookable( new WPDesk_Flexible_Shipping_Tracker() );
$this->add_hookable( new TrackerData() );
}
/**
* @return ShouldDisplayOrConditions
*/
private function prepare_shoud_display_for_flexible_shipping() {
$should_display = new ShouldDisplayOrConditions();
$should_display->add_should_diaplay_condition( new ShouldDisplayShippingMethodInstanceSettings( ShippingMethodSingle::SHIPPING_METHOD_ID ) );
$should_display_and_conditions = new ShouldDisplayAndConditions();
$should_display_and_conditions->add_should_diaplay_condition(
new ShouldDisplayGetParameterValue( 'page', 'wc-settings' )
);
$should_display_and_conditions->add_should_diaplay_condition(
new ShouldDisplayGetParameterValue( 'tab', 'shipping' )
);
$should_display_and_conditions->add_should_diaplay_condition(
new ShouldDisplayGetParameterValue( 'section', WPDesk_Flexible_Shipping_Settings::METHOD_ID )
);
$should_display->add_should_diaplay_condition( $should_display_and_conditions );
return $should_display;
}
/**
* Woocommerce shipping methods filter.
*
* @param array $methods .
*
* @return array
*/
public function woocommerce_shipping_methods_filter( $methods ) {
$methods[ ShippingMethodSingle::SHIPPING_METHOD_ID ] = ShippingMethodSingle::class;
$methods[ WPDesk_Flexible_Shipping::METHOD_ID ] = WPDesk_Flexible_Shipping::class;
if ( $this->can_register_fs_info() ) {
$methods[ WPDesk_Flexible_Shipping_Settings::METHOD_ID ] = WPDesk_Flexible_Shipping_Settings::class;
}
return $methods;
}
/**
* @return bool
*/
private function can_register_fs_info() {
if ( ! is_admin() ) {
return false;
}
return ! $this->is_adding_order_page() && ! $this->is_editing_order_page();
}
/**
* @return bool
*/
private function is_editing_order_page() {
$post = filter_input( INPUT_GET, 'post' );
$action = filter_input( INPUT_GET, 'action' );
return 'edit' === $action && $post;
}
/**
* @return bool
*/
private function is_adding_order_page() {
$action = filter_input( INPUT_POST, 'action' );
return wp_doing_ajax() && 'woocommerce_add_order_shipping' === $action;
}
/**
* Option woocommerce cod settings filter.
*
* @param array $value .
*
* @return array
*/
public function option_woocommerce_cod_settings( $value ) {
if ( is_checkout() ) {
if (
! empty( $value )
&& is_array( $value )
&& 'yes' === $value['enabled']
&& ! empty( $value['enable_for_methods'] )
&& is_array( $value['enable_for_methods'] )
) {
foreach ( $value['enable_for_methods'] as $method ) {
if ( 'flexible_shipping' === $method ) {
$all_fs_methods = flexible_shipping_get_all_shipping_methods();
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
$flexible_shipping = $all_shipping_methods['flexible_shipping'];
$flexible_shipping_rates = $flexible_shipping->get_all_rates();
foreach ( $flexible_shipping_rates as $flexible_shipping_rate ) {
$value['enable_for_methods'][] = $flexible_shipping_rate['id_for_shipping'];
}
break;
}
}
}
}
return $value;
}
/**
* Add flexible shipping order meta on checkout.
*
* @param WC_Order $order Order.
*/
public function add_flexible_shipping_order_meta_on_checkout( $order ) {
if ( ! $this->is_order_processed_on_checkout ) {
$mutex = WordpressPostMutex::fromOrder( $order );
$mutex->acquireLock();
$this->is_order_processed_on_checkout = true;
$order_shipping_methods = $order->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' ),
'<a class="button close-fs-rate-notice" target="_blank" href="' . esc_url( $notice_url ) . '">',
'</a>'
),
]
);
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&section=' . WPDesk_Flexible_Shipping_Settings::METHOD_ID );
$plugin_links = [
'<a href="' . $settings_url . '">' . __(
'Settings',
'flexible-shipping'
) . '</a>',
'<a target="_blank" href="' . $docs_link . '">' . __( 'Docs', 'flexible-shipping' ) . '</a>',
'<a target="_blank" href="' . $support_link . '">' . __( 'Support', 'flexible-shipping' ) . '</a>',
];
$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[] = '<a href="' . $pro_link . '" target="_blank" style="color:#d64e07;font-weight:bold;">' . __(
'Buy PRO',
'flexible-shipping'
) . '</a>';
}
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;
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace WPDesk\FS\Rate;
abstract class RateNotice implements RateNoticeInterface {
const NOTICE_NAME = 'flexible_shipping_rate_plugin';
const CLOSE_TEMPORARY_NOTICE = 'close-temporary-notice-date';
/**
* Get message
*
* @return mixed
*/
abstract protected function get_message();
/**
* Action links
*
* @return array
*/
protected function action_links() {
$actions[] = sprintf(
__( '%1$sOk, you deserved it%2$s', 'flexible-shipping' ),
'<a target="_blank" href="' . esc_url( 'https://octol.io/fs-rate' ) . '">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sNope, maybe later%2$s', 'flexible-shipping' ),
'<a data-type="date" class="fs-close-temporary-notice notice-dismiss-link" data-source="' . self::CLOSE_TEMPORARY_NOTICE . '" href="#">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sI already did%2$s', 'flexible-shipping' ),
'<a class="close-rate-notice notice-dismiss-link" data-source="already-did" href="#">',
'</a>'
);
return $actions;
}
/**
* Should show message
*
* @return bool
*/
public function should_show_message() {
return true;
}
/**
* Show admin notice
*
* @return string|void
*/
public function show_message() {
new \FSVendor\WPDesk\Notice\PermanentDismissibleNotice(
$this->get_message(),
self::NOTICE_NAME,
\FSVendor\WPDesk\Notice\Notice::NOTICE_TYPE_INFO,
10,
array(
'class' => self::NOTICE_NAME,
'id' => self::NOTICE_NAME,
)
);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Admin notices.
*
* @package Flexible Shipping
*/
/**
* Can display notices in admin.
*/
class WPDesk_Flexible_Shipping_Admin_Notices {
const SETTINGS_CHECKED_OPTION_VALUE_SHOW_MESSAGE = '1';
const SETTINGS_CHECKED_OPTION_VALUE_DO_NOT_SHOW_MESSAGE = '2';
const BASED_ON_VALUE = 'value';
/**
* @var Flexible_Shipping_Plugin
*/
private $plugin;
/**
* WPDesk_Flexible_Shipping_Admin_Notices constructor.
*
* @param Flexible_Shipping_Plugin $plugin .
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
* Hooks.
*/
private function hooks() {
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_activepayments' ) );
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_enadawca' ) );
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_pwr' ) );
}
/**
* @param WC_Shipping_Method $shipping_method .
*
* @return bool
*/
private function has_value_based_rule( $shipping_method ) {
$methods = get_option( 'flexible_shipping_methods_' . $shipping_method->instance_id, array() );
if ( is_array( $methods ) ) {
foreach ( $methods as $method_settings ) {
if ( isset( $method_settings['method_rules'] ) && is_array( $method_settings['method_rules'] ) ) {
foreach ( $method_settings['method_rules'] as $rule ) {
if ( isset( $rule['based_on'] ) && self::BASED_ON_VALUE === $rule['based_on'] ) {
return true;
}
}
}
}
}
return false;
}
/**
* @return bool
*/
public function is_in_zones() {
if ( isset( $_GET['page'] ) && 'wc-settings' === sanitize_key( $_GET['page'] )
&& isset( $_GET['tab'] ) && 'shipping' === sanitize_key( $_GET['tab'] )
&& ( ! isset( $_GET['section'] ) || '' === $_GET['section'] )
) {
return true;
}
return false;
}
/**
* Active payments notice.
*/
public function admin_notices_plugin_activepayments() {
if ( is_plugin_active( 'woocommerce-active-payments/activepayments.php' ) ) {
$plugin_activepayments = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-active-payments/activepayments.php' );
$version_compare = version_compare( $plugin_activepayments['Version'], '2.7' );
if ( $version_compare < 0 ) {
$class = 'notice notice-error';
$message = __( 'Flexible Shipping requires at least version 2.7 of Active Payments plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/**
* Enadawca notice.
*/
public function admin_notices_plugin_enadawca() {
if ( is_plugin_active( 'woocommerce-enadawca/woocommerce-enadawca.php' ) ) {
$plugin_enadawca = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-enadawca/woocommerce-enadawca.php' );
$version_compare = version_compare( $plugin_enadawca['Version'], '1.2' );
if ( $version_compare < 0 ) {
$class = 'notice notice-error';
$message = __( 'Flexible Shipping requires at least version 1.2 of eNadawca plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/**
* Paczka w Ruchu notice.
*/
public function admin_notices_plugin_pwr() {
if ( is_plugin_active( 'woocommerce-paczka-w-ruchu/woocommerce-paczka-w-ruchu.php' ) ) {
$plugin_pwr = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-paczka-w-ruchu/woocommerce-paczka-w-ruchu.php' );
$version_compare = version_compare( $plugin_pwr['Version'], '1.1' );
if ( $version_compare < 0 ) {
$class = 'notice notice-error';
$message = __( 'Flexible Shipping requires at least version 1.1 of Orlen Paczka plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/**
* @param string $class .
* @param string $message .
*/
private function print_notice( $class, $message ) {
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); // phpcs:ignore
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace WPDesk\FS\Rate;
interface RateNoticeInterface {
/**
* Show message
*
* @return string
*/
public function show_message();
/**
* Should show message
*
* @return bool
*/
public function should_show_message();
}

View File

@@ -0,0 +1,63 @@
<?php
namespace WPDesk\FS\Rate;
class RateNoticeImplementation extends RateNotice
{
/**
* Action links
*
* @return array
*/
protected function action_links() {
$actions[] = sprintf(
__( '%1$sOk, you deserved it%2$s', 'flexible-shipping' ),
'<a target="_blank" href="' . esc_url( 'https://octol.io/fs-rate' ) . '">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sNope, maybe later%2$s', 'flexible-shipping' ),
'<a data-type="date" class="fs-close-temporary-notice notice-dismiss-link" data-source="' . self::CLOSE_TEMPORARY_NOTICE . '" href="#">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sI already did%2$s', 'flexible-shipping' ),
'<a class="close-rate-notice notice-dismiss-link" data-source="already-did" href="#">',
'</a>'
);
return $actions;
}
/**
* Should show message
*
* @return bool
*/
public function should_show_message() {
$notice_date_dissmis = get_option( WPDesk_Flexible_Shipping_Rate_Notice::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime( 'NOW + 2 weeks' ) ) );
$notice_date = strtotime( $notice_date_dissmis );
$current_date = strtotime( 'NOW' );
$difference = $current_date - $notice_date;
$days = (int) floor( $difference / ( 60 * 60 * 24 ) );
if ( $days > 0 ) {
return true;
}
return false;
}
/**
* Get rate message
*
* @return string
*/
protected function get_message() {
$message = __( 'Awesome, you\'ve been using Flexible Shipping for more than 2 weeks. Could you please do me a BIG favor and give it a 5-star rating on WordPress? ~Octolize Team', 'flexible-shipping' );
$message .= '<br/>';
$message .= implode( ' | ', $this->action_links() );
return $message;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace WPDesk\FS\Rate;
/**
* Display rate notice.
*/
class WPDesk_Flexible_Shipping_Rate_Notice implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
const CLOSE_TEMPORARY_NOTICE_DATE = 'close-temporary-notice-date';
const CLOSE_ALREADY_DID = 'already-did';
const SETTINGS_OPTION_DISMISSED_COUNT = 'flexible_shipping_rate_dismissed_count';
const SETTINGS_RATE_NOTICE_VARIANT_ID = 'flexible_shipping_rate_notice_variant_id';
const SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS = 'flexible_shipping_rate_notice_date_dismiss';
/**
* Hooks.
*/
public function hooks() {
add_action( 'admin_notices', array( $this, 'add_admin_notice_action' ) );
add_action( 'wpdesk_notice_dismissed_notice', array( $this, 'reset_rate_variant_action' ), 10, 2 );
add_action( 'wp_ajax_flexible_shipping_rate_notice', array( $this, 'wp_ajax_flexible_shipping_rate_notice' ) );
add_action( 'wp_ajax_flexible_shipping_close_rate_notice', array( $this, 'wp_ajax_flexible_shipping_close_rate_notice' ) );
}
/**
* Reset rate variant
*
* @param string $notice_name Notice name.
* @param string $source Sorcue.
*/
public function reset_rate_variant_action( $notice_name, $source ) {
if ( 'flexible_shipping_rate_plugin' !== $notice_name ) {
return false;
}
$dismissed_count = (int) get_option( self::SETTINGS_OPTION_DISMISSED_COUNT, 0 );
if ( ( empty( $source ) || self::CLOSE_TEMPORARY_NOTICE_DATE === $source ) ) {
update_option( self::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime( 'NOW + 2 weeks' ) ) );
delete_option( \FSVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $notice_name );
update_option( self::SETTINGS_OPTION_DISMISSED_COUNT, 1 );
} elseif ( self::CLOSE_ALREADY_DID === $source ) {
update_option( \FSVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $notice_name, 1 );
}
if ( $dismissed_count > 0 ) {
update_option( \FSVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $notice_name, 1 );
}
}
/**
* Should display notice.
*
* @return bool
*/
private function should_display_notice() {
$current_screen = get_current_screen();
$display_on_screens = [ 'shop_order', 'edit-shop_order', 'woocommerce_page_wc-settings' ];
if ( ! empty( $current_screen ) && in_array( $current_screen->id, $display_on_screens, true ) ) {
return true;
}
return false;
}
/**
* Generate rate notice variant ID.
*
* @return string
*/
private function generate_rate_notice_variant_id()
{
return 'notice_2';
}
/**
* Set defaults for notice.
*/
private function set_notice_defaults() {
add_option( self::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime('NOW + 2 weeks') ) );
}
/**
* Add admin notice.
*/
public function add_admin_notice_action()
{
if ( $this->should_display_notice() ) {
$instance = new RateNoticeImplementation();
$this->set_notice_defaults();
if( $instance->should_show_message() ) {
$instance->show_message();
}
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_UK_States
*/
class WPDesk_Flexible_Shipping_Shorcode_Unit_Dimension implements \FSVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant {
use \FSVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
/**
* Hooks.
*/
public function hooks() {
add_shortcode( 'unit_dimension', [ $this, 'shortcode_unit_dimension' ] );
}
/**
* Shortcode Unit Dimension
*
* @return string
*/
public function shortcode_unit_dimension() {
return '[' . get_option( 'woocommerce_dimension_unit', '' ) . ']';
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_UK_States
*/
class WPDesk_Flexible_Shipping_Shorcode_Unit_Weight implements \FSVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant {
use \FSVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
/**
* Hooks.
*/
public function hooks() {
add_shortcode( 'unit_weight', [ $this, 'shortcode_unit_weight' ] );
}
/**
* Shortcode Unit Weight.
*
* @return string
*/
public function shortcode_unit_weight() {
return '[' . get_option( 'woocommerce_weight_unit', '' ) . ']';
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Multilingual
*
* @package Flexible Shipping
*/
use WPDesk\FS\TableRate\FreeShipping\NoticeTextSettings;
/**
* Handles multilingual.
*/
class WPDesk_Flexible_Shipping_Multilingual {
/**
* @var Flexible_Shipping_Plugin
*/
private $plugin;
/**
* WPDesk_Flexible_Shipping_Multilingual constructor.
*
* @param Flexible_Shipping_Plugin $plugin .
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
* .
*/
private function hooks() {
add_action( 'woocommerce_init', [ $this, 'init_polylang' ] );
add_action( 'admin_init', [ $this, 'init_wpml' ] );
}
/**
* .
*/
public function init_polylang() {
if ( function_exists( 'pll_register_string' ) ) {
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
$flexible_shipping = $all_shipping_methods['flexible_shipping'];
$flexible_shipping_rates = $flexible_shipping->get_all_rates();
foreach ( $flexible_shipping_rates as $flexible_shipping_rate ) {
if ( isset( $flexible_shipping_rate['method_title'] ) ) {
pll_register_string( $flexible_shipping_rate['method_title'], $flexible_shipping_rate['method_title'], __( 'Flexible Shipping', 'flexible-shipping' ) );
}
if ( isset( $flexible_shipping_rate['method_description'] ) ) {
pll_register_string( $flexible_shipping_rate['method_description'], $flexible_shipping_rate['method_description'], __( 'Flexible Shipping', 'flexible-shipping' ) );
}
if ( isset( $flexible_shipping_rate['method_free_shipping_label'] ) ) {
pll_register_string( $flexible_shipping_rate['method_free_shipping_label'], $flexible_shipping_rate['method_free_shipping_label'], __( 'Flexible Shipping', 'flexible-shipping' ) );
}
if ( isset( $flexible_shipping_rate[ NoticeTextSettings::FIELD_NAME ] ) ) {
pll_register_string( $flexible_shipping_rate[ NoticeTextSettings::FIELD_NAME ], $flexible_shipping_rate[ NoticeTextSettings::FIELD_NAME ], __( 'Flexible Shipping', 'flexible-shipping' ) );
}
}
}
}
/**
* .
*/
public function init_wpml() {
if ( function_exists( 'icl_register_string' ) ) {
$icl_language_code = defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : get_bloginfo( 'language' );
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
$flexible_shipping = $all_shipping_methods['flexible_shipping'];
$flexible_shipping_rates = $flexible_shipping->get_all_rates();
foreach ( $flexible_shipping_rates as $flexible_shipping_rate ) {
if ( isset( $flexible_shipping_rate['method_title'] ) ) {
icl_register_string( 'flexible-shipping', $flexible_shipping_rate['method_title'], $flexible_shipping_rate['method_title'], false, $icl_language_code );
}
if ( isset( $flexible_shipping_rate['method_description'] ) ) {
icl_register_string( 'flexible-shipping', $flexible_shipping_rate['method_description'], $flexible_shipping_rate['method_description'], false, $icl_language_code );
}
if ( isset( $flexible_shipping_rate['method_free_shipping_label'] ) ) {
icl_register_string( 'flexible-shipping', $flexible_shipping_rate['method_free_shipping_label'], $flexible_shipping_rate['method_free_shipping_label'], false, $icl_language_code );
}
if ( isset( $flexible_shipping_rate[ NoticeTextSettings::FIELD_NAME ] ) ) {
icl_register_string( 'flexible-shipping', $flexible_shipping_rate[ NoticeTextSettings::FIELD_NAME ], $flexible_shipping_rate[ NoticeTextSettings::FIELD_NAME ], false, $icl_language_code );
}
}
}
}
}

View File

@@ -0,0 +1,191 @@
<?php
/**
* WPDesk_Flexible_Shipping_Settings
*
* @package Flexible Shipping
*/
use FSVendor\WPDesk\Beacon\Beacon\WooCommerceSettingsFieldsModifier;
use WPDesk\FS\Info\FSIE;
use WPDesk\FS\Info\FSPro;
use WPDesk\FS\Info\FSWalkthrough;
use WPDesk\FS\Info\FSWalkthroughPL;
use WPDesk\FS\Info\Metabox;
use WPDesk\FS\Info\Video;
use WPDesk\FS\Info\WooCommerceABC;
use WPDesk\FS\Info\WooCommerceABCPL;
/**
* Mainly read only info about FS + debug mode.
*/
class WPDesk_Flexible_Shipping_Settings extends WC_Shipping_Method {
const METHOD_ID = 'flexible_shipping_info';
const WOOCOMMERCE_PAGE_WC_SETTINGS = 'wc-settings';
const WOOCOMMERCE_SETTINGS_SHIPPING_URL = 'admin.php?page=wc-settings&tab=shipping';
/**
* Logger settings.
*
* @var WPDesk_Flexible_Shipping_Logger_Settings
*/
private $logger_settings;
/**
* WPDesk_Flexible_Shipping_Connect constructor.
*
* @param int $instance_id Instance id.
*/
public function __construct( $instance_id = 0 ) {
parent::__construct( $instance_id );
$this->id = self::METHOD_ID;
$this->enabled = 'no';
$this->method_title = __( 'Flexible Shipping Info', 'flexible-shipping' );
$this->supports = [
'settings',
];
$this->logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings( $this );
$this->init_form_fields();
add_action( 'woocommerce_update_options_shipping_' . $this->id, [ $this, 'process_admin_options' ] );
}
/**
* Update debug mode.
*/
private function update_debug_mode() {
$this->logger_settings->update_option_from_saas_settings( $this );
}
/**
* Process admin options.
*/
public function process_admin_options() {
parent::process_admin_options();
$this->update_debug_mode();
$url = admin_url( self::WOOCOMMERCE_SETTINGS_SHIPPING_URL );
$url = add_query_arg( 'section', $this->id, $url );
wp_safe_redirect( $url );
exit;
}
/**
* In settings screen?
*
* @return bool
*/
public function is_in_settings() {
if ( is_admin() && isset( $_GET['page'] ) && isset( $_GET['section'] ) ) {
$page = sanitize_key( $_GET['page'] );
$section = sanitize_key( $_GET['section'] );
if ( self::WOOCOMMERCE_PAGE_WC_SETTINGS === $page && self::METHOD_ID === $section ) {
return true;
}
}
return false;
}
/**
* Initialise Settings Form Fields.
*/
public function init_form_fields() {
$this->form_fields = [
'flexible_shipping' => [
'type' => 'flexible_shipping',
],
];
$this->form_fields[] = [
'type' => 'title',
'title' => __( 'Advanced settings', 'flexible-shipping' ),
];
$this->form_fields = $this->logger_settings->add_fields_to_settings( $this->form_fields );
$this->form_fields = $this->add_beacon_search_data_to_fields( $this->form_fields );
}
/**
* Add beacon search data to fields.
*
* @param array $form_fields .
*
* @return array
*/
private function add_beacon_search_data_to_fields( array $form_fields ) {
$modifier = new WooCommerceSettingsFieldsModifier();
return $modifier->append_beacon_search_data_to_fields( $form_fields );
}
/**
* Generate FC connect box
*
* @param string $key Key.
* @param array $data Data.
*
* @return string
*/
public function generate_flexible_shipping_html( $key, $data ) {
$metaboxes = $this->get_metaboxes();
if ( ! $metaboxes ) {
return '';
}
ob_start();
include 'views/html-shipping-settings-info-description.php';
$notice_content = ob_get_contents();
ob_end_clean();
return $notice_content;
}
/**
* @return Metabox[]
*/
public function get_metaboxes() {
$metaboxes = [];
if ( 'pl_PL' === get_user_locale() ) {
$metaboxes[] = new WooCommerceABCPL();
$metaboxes[] = new FSWalkthroughPL();
} else {
$metaboxes[] = new WooCommerceABC();
$metaboxes[] = new FSWalkthrough();
}
if ( ! wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) ) {
$metaboxes[] = new FSPro();
} else {
$metaboxes[] = new FSIE();
}
$metaboxes[] = new Video();
/**
* Can modify metaboxes on FS Info Page.
*
* @param Metabox[] $metaboxes Metaboxes.
*
* @since 4.1.3
*/
$metaboxes = apply_filters( 'flexible-shipping/page/info/metaboxes', $metaboxes );
$metaboxes = array_filter(
$metaboxes,
function ( $metabox ) {
return $metabox instanceof Metabox;
}
);
return $metaboxes;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_SaaS_Settings
*/
class WPDesk_Flexible_Shipping_Logger_Downloader implements \FSVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant {
use \FSVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
const GET_PARAMETER = 'fs-get-log';
/**
* Logger factory.
*
* @var \FSVendor\WPDesk\Logger\WPDeskLoggerFactory
*/
private $logger_factory;
/**
* WPDesk_Flexible_Shipping_SaaS_Logger_Downloader constructor.
*
* @param \FSVendor\WPDesk\Logger\WPDeskLoggerFactory $logger_factory Logger factory.
*/
public function __construct( \FSVendor\WPDesk\Logger\WPDeskLoggerFactory $logger_factory = null ) {
$this->logger_factory = $logger_factory;
}
/**
* Hooks.
*/
public function hooks() {
add_action( 'admin_init', [ $this, 'handle_log_file_download' ] );
}
/**
* Get download URL.
*
* @return string
*/
public function get_download_url() {
return admin_url( 'admin.php?' . self::GET_PARAMETER . '=1' );
}
/**
* Handle log file download.
*/
public function handle_log_file_download() {
if ( isset( $_GET[ self::GET_PARAMETER ] ) ) {
if ( current_user_can( 'manage_options' ) ) {
$logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings();
$file_name = $this->logger_factory->getFileName( $logger_settings->get_logger_channel_name() );
if ( file_exists( $file_name ) ) {
header( 'Content-Type: text/plain' );
header( 'Content-Disposition: attachment; filename="fs-debug.log"' );
readfile( $file_name );
} else {
wp_die( __( 'File not exists!', 'flexible-shipping' ) );
}
} else {
wp_die( __( 'Insufficient privileges!', 'flexible-shipping' ) );
}
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Logger_Factory
*
* @deprecated
*/
class WPDesk_Flexible_Shipping_Logger_Factory {
const NULL_LOG_NAME = 'null-log';
/**
* Logger.
*
* @var \Psr\Log\LoggerInterface
*/
private static $logger;
/**
* Create logger.
*
* @return \Psr\Log\LoggerInterface
*/
public static function create_logger() {
if ( null === self::$logger ) {
$logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings();
if ( $logger_settings->is_enabled() ) {
self::$logger = new WPDesk_Flexible_Shipping_WooCommerce_Context_Logger(
@\FSVendor\WPDesk\Logger\LoggerFacade::get_logger( $logger_settings->get_logger_channel_name() ),
$logger_settings->get_logging_context()
);
} else {
self::$logger = new \Monolog\Logger( self::NULL_LOG_NAME );
}
}
return self::$logger;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_SaaS_Settings
*/
class WPDesk_Flexible_Shipping_Logger_Settings {
const LOGGER_CHANNEL_NAME = 'fs';
const DEBUG_LOG_OPTION = 'debug_log';
const OPTION_NAME = 'fs_logger_enabled';
const OPTION_VALUE_DISABLED = '0';
const OPTION_VALUE_ENABLED = '1';
/**
* Enabled.
*
* @var bool
*/
private $enabled = false;
/**
* SaaS settings.
*
* @var WPDesk_Flexible_Shipping_Settings
*/
private $saas_settings;
/**
* WPDesk_Flexible_Shipping_SaaS_Logger_Settings constructor.
*
* @param WPDesk_Flexible_Shipping_Settings $saas_settings SaaS settings.
*/
public function __construct( WPDesk_Flexible_Shipping_Settings $saas_settings = null ) {
$option_value = get_option( self::OPTION_NAME, self::OPTION_VALUE_DISABLED );
$this->enabled = self::OPTION_VALUE_ENABLED === $option_value;
$this->saas_settings = $saas_settings;
}
/**
* Get logger channel name.
*
* @return string
*/
public function get_logger_channel_name() {
return self::LOGGER_CHANNEL_NAME;
}
/**
* Is enabled.
*
* @return bool
*/
public function is_enabled() {
return $this->enabled;
}
/**
* Update option from saas settings.
*/
public function update_option_from_saas_settings() {
$saas_settings_value = $this->saas_settings->get_option( self::DEBUG_LOG_OPTION );
if ( ! empty( $saas_settings_value ) && 'yes' === $saas_settings_value ) {
$option_value = self::OPTION_VALUE_ENABLED;
} else {
$option_value = self::OPTION_VALUE_DISABLED;
}
update_option( self::OPTION_NAME, $option_value );
$this->enabled = self::OPTION_VALUE_ENABLED === $option_value;
}
/**
* Add fields to settings.
*
* @param array $settings Settings.
*
* @return array
*/
public function add_fields_to_settings( array $settings ) {
$settings[ self::DEBUG_LOG_OPTION ] = array(
'type' => 'checkbox',
'label' => __( 'Enable Debug Mode', 'flexible-shipping' ),
'title' => __( 'Debug mode', 'flexible-shipping' ),
);
if ( 'yes' === $this->saas_settings->get_option( self::DEBUG_LOG_OPTION ) ) {
$downloader = new WPDesk_Flexible_Shipping_Logger_Downloader();
$settings[ self::DEBUG_LOG_OPTION ]['description'] = sprintf(
// Translators: URL.
__( '%1$sDownload debug.log file%2$s', 'flexible-shipping' ),
sprintf( '<a href="%1$s" target="_blank">', $downloader->get_download_url() ),
'</a>'
);
}
return $settings;
}
}

View File

@@ -0,0 +1,56 @@
<?php
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
/**
* Class WPDesk_Flexible_Shipping_WooCommerce_Context_Logger
*/
class WPDesk_Flexible_Shipping_WooCommerce_Context_Logger implements LoggerInterface {
use LoggerTrait;
/**
* Logger.
*
* @var LoggerInterface
*/
private $logger;
/**
* Default context.
*
* @var array
*/
private $default_context;
/**
* WPDesk_Flexible_Shipping_Context_Logger constructor.
*
* @param LoggerInterface $logger Logger.
* @param string $source WooCommerce source context.
* @param array $context Default context for logger.
*/
public function __construct( LoggerInterface $logger, $source, array $context = [] ) {
$this->logger = $logger;
$context['source'] = $source;
$this->default_context = $context;
}
/**
* Logs with an arbitrary level.
*
* @param string $level Level.
* @param string $message Message.
* @param array $context Context.
*
* @return void
*/
public function log( $level, $message, array $context = array() ) {
$context = array_merge( $this->default_context, $context );
$this->logger->log( $level, $message, $context );
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Order item meta.
*
* @package Flexible Shipping.
*/
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Manages hidden order item meta.
*/
class WPDesk_Flexible_Shipping_Order_Item_Meta implements Hookable {
/**
* Hooks.
*/
public function hooks() {
add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'add_hidden_order_itemmeta' ) );
}
/**
* @param array $hidden_order_itemmeta .
*
* @return array
*/
public function add_hidden_order_itemmeta( $hidden_order_itemmeta ) {
$hidden_order_itemmeta[] = WPDesk_Flexible_Shipping::META_DEFAULT;
return $hidden_order_itemmeta;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Settings for flexible shipment
*
* @package FlexibleShipping
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$docs_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-docs-pl' : 'https://octol.io/fs-docs';
$settings = array(
array(
'title' => __( 'Flexible Shipping', 'flexible-shipping' ),
'type' => 'title',
// Translators: link.
'description' => sprintf( __( 'See how to %1$sconfigure Flexible Shipping%2$s.', 'flexible-shipping' ), '<a href="' . $docs_link . '" target="_blank">', '</a>' ),
),
'enabled' => array(
'title' => __( 'Enable/Disable', 'flexible-shipping' ),
'type' => 'checkbox',
'label' => __( 'Enable Flexible Shipping', 'flexible-shipping' ),
'default' => 'no',
),
'title' => array(
'title' => __( 'Shipping title', 'flexible-shipping' ),
'type' => 'text',
'description' => __( 'Visible only to admin in WooCommerce settings.', 'flexible-shipping' ),
'default' => __( 'Flexible Shipping', 'flexible-shipping' ),
'desc_tip' => true,
),
'tax_status' => array(
'title' => __( 'Tax Status', 'flexible-shipping' ),
'type' => 'select',
'default' => 'taxable',
'desc_tip' => __( 'If you select to apply the tax, the plugin will use the tax rates defined in the WooCommerce settings at <strong>WooCommerce → Settings → Tax</strong>.', 'flexible-shipping' ),
'options' => array(
'taxable' => __( 'Taxable', 'flexible-shipping' ),
'none' => _x( 'None', 'Tax status', 'flexible-shipping' ),
),
),
'title_shipping_methods' => array(
'title' => __( 'Shipping Methods', 'flexible-shipping' ),
'type' => 'title_shipping_methods',
'description' => '',
),
'shipping_methods' => array(
'title' => __( 'Shipping Methods', 'flexible-shipping' ),
'type' => 'shipping_methods',
'desc_tip' => true,
),
);
if ( version_compare( WC()->version, '2.6' ) >= 0 && $this->get_option( 'enabled', 'yes' ) == 'yes' ) {
unset( $settings['enabled'] );
}
return $settings;

View File

@@ -0,0 +1,665 @@
<?php
use FSVendor\WPDesk\Beacon\Beacon\WooCommerceSettingsFieldsModifier;
use FSVendor\WPDesk\FS\TableRate\Logger\NoticeLogger;
use FSVendor\WPDesk\FS\TableRate\Logger\ShippingMethodLogger;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings;
use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettingsFactory;
use Psr\Log\LoggerInterface;
use WPDesk\FS\TableRate\Rates\FlexibleShippingRates;
use WPDesk\FS\TableRate\RulesSettingsField;
use WPDesk\FS\TableRate\ShippingMethod\CommonMethodSettings;
use WPDesk\FS\TableRate\ShippingMethod\RateCalculatorFactory;
use WPDesk\FS\TableRate\ShippingMethod\SettingsDisplayPreparer;
use WPDesk\FS\TableRate\ShippingMethod\SettingsProcessor;
class WPDesk_Flexible_Shipping extends WC_Shipping_Method {
const METHOD_ID = 'flexible_shipping';
const FIELD_METHOD_FREE_SHIPPING = 'method_free_shipping';
const META_DEFAULT = '_default';
const WEIGHT_ROUNDING_PRECISION = 6;
const SETTING_METHOD_RULES = 'method_rules';
const SETTING_METHOD_FREE_SHIPPING_NOTICE = 'method_free_shipping_cart_notice';
/**
* Logger provided by Flexible Shipping plugin.
*
* @var LoggerInterface
*/
protected static $fs_logger;
/**
* Message added.
*
* @var bool
*/
private $message_added = false;
/**
* @var string
*
* See Active Payments - must be public
*/
public $shipping_methods_option;
/**
* @var string
*/
private $shipping_method_order_option;
/**
* @var string
*/
private $section_name;
/**
* Constructor for your shipment class
*
* @access public
* @return void
*/
public function __construct( $instance_id = 0 ) {
$this->instance_id = absint( $instance_id );
$this->id = self::METHOD_ID;
$this->shipping_methods_option = 'flexible_shipping_methods_' . $this->instance_id;
$this->shipping_method_order_option = 'flexible_shipping_method_order_' . $this->instance_id;
$this->section_name = 'flexible_shipping';
$this->method_title = __( 'Flexible Shipping Group', 'flexible-shipping' );
$this->method_description = __( 'A group of Flexible Shipping methods - useful to organize numerous shipping methods.', 'flexible-shipping' );
$this->supports = array(
'instance-settings',
);
if ( $this->is_allowed_support_shipping_zones() ) {
$this->supports[] = 'shipping-zones';
}
$this->instance_form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'flexible-shipping' ),
'type' => 'checkbox',
'label' => __( 'Enable this shipment method', 'flexible-shipping' ),
'default' => 'yes',
),
'title' => array(
'title' => __( 'Shipping Title', 'flexible-shipping' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'flexible-shipping' ),
'default' => __( 'Flexible Shipping', 'flexible-shipping' ),
'desc_tip' => true
)
);
if ( version_compare( WC()->version, '2.6' ) < 0 && $this->get_option( 'enabled', 'yes' ) == 'no' ) {
$this->enabled = $this->get_option( 'enabled' );
}
$this->title = $this->get_option( 'title' );
$this->init();
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* Set logger. This logger is set by Flexible Shipping plugin.
*
* @param LoggerInterface $fs_logger .
*/
public static function set_fs_logger( LoggerInterface $fs_logger ) {
static::$fs_logger = $fs_logger;
}
/**
* @param MethodSettings $shipping_method_settings
*
* @return \WPDesk\FS\TableRate\Logger\ShippingMethodLogger
*/
private function prepare_shipping_method_calculation_logger( $shipping_method_settings ) {
$method_debug_mode = $shipping_method_settings->get_debug_mode();
$shipping_method_title = $shipping_method_settings->get_title();
$shipping_method_url = admin_url(
'admin.php?page=wc-settings&tab=shipping&instance_id=' . sanitize_key( $this->instance_id ) . '&action=edit&method_id=' . sanitize_key( $shipping_method_settings->get_id() )
);
if ( null !== static::$fs_logger ) {
$fs_logger = static::$fs_logger;
} else {
$fs_logger = NullLogger();
}
return new ShippingMethodLogger(
$fs_logger,
new NoticeLogger(
$shipping_method_title,
$shipping_method_url,
'yes' === $method_debug_mode && current_user_can( 'manage_woocommerce' )
)
);
}
/**
* Init your settings
*
* @access public
* @return void
*/
function init() {
$this->instance_form_fields = include( 'settings/flexible-shipping.php' );
// Load the settings API
$this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
$this->init_settings(); // This is part of the settings API. Loads settings you previously init.
// Define user set variables
$this->title = $this->get_option( 'title' );
$this->tax_status = $this->get_option( 'tax_status' );
$this->availability = $this->get_option( 'availability' );
$this->type = $this->get_option( 'type', 'class' );
}
/**
* Initialise Settings Form Fields
*/
public function init_form_fields() {
$this->form_fields = include( 'settings/flexible-shipping.php' );
$this->form_fields = $this->add_beacon_search_data_to_fields( $this->form_fields );
}
public function generate_title_shipping_methods_html( $key, $data ) {
$field = $this->get_field_key( $key );
$defaults = array(
'title' => '',
'class' => ''
);
$data = wp_parse_args( $data, $defaults );
ob_start();
?>
</table>
<?php
$shipping_method_id = self::METHOD_ID;
include __DIR__ . '/views/html-ads.php';
?>
<h3 class="wc-settings-sub-title <?php echo esc_attr( $data['class'] ); ?>" id="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?>
<?php if ( $this->is_allowed_editing() ): ?>
<a href="<?php echo esc_url( remove_query_arg( 'added', add_query_arg( 'action', 'new' ) ) ); ?>"
class="add-new-h2"><?php echo __( 'Add New', 'flexible-shipping' ); ?></a></h3>
<?php endif; ?>
<?php if ( ! empty( $data['description'] ) ) : ?>
<p><?php echo wp_kses_post( $data['description'] ); ?></p>
<?php endif; ?>
</div><table class="form-table">
<?php
return ob_get_clean();
}
/**
* @param unknown $key
*
* @return string
*
* Dodane w WooCommerce 2.4
* Dodane w celu zachowania kompatybilności z WooCommerce 2.3
* Przetestowane na WooCommerce 2.3.9
*/
public function get_field_key( $key ) {
return $this->plugin_id . $this->id . '_' . $key;
}
public function generate_shipping_methods_html( $key, $data ) {
$shipping_methods = $this->get_shipping_methods();
$shipping_method_order = $this->get_shipping_method_order();
ob_start();
include __DIR__ . '/views/html-shipping-method-settings.php';
return ob_get_clean();
}
public function get_shipping_methods( $enabled = false ) {
$shipping_methods = $this->get_option_shipping_methods();
$shipping_method_order = get_option( $this->shipping_method_order_option, array() );
$ret = array();
if ( is_array( $shipping_method_order ) ) {
foreach ( $shipping_method_order as $method_id ) {
if ( isset( $shipping_methods[$method_id] ) ) {$ret[$method_id] = $shipping_methods[$method_id];}
}
}
foreach ( $shipping_methods as $shipping_method ) {
if ( !isset( $ret[$shipping_method['id']] ) ) {$ret[$shipping_method['id']] = $shipping_method;}
}
if ( $enabled ) {
foreach ( $ret as $key => $shipping_method ) {
if ( isset( $shipping_method['method_enabled'] ) && 'yes' != $shipping_method['method_enabled'] ) {unset($ret[$key]);}
}
}
return $ret;
}
private function get_shipping_method_order() {
$shipping_methods = $this->get_option_shipping_methods();
$shipping_method_order = get_option( $this->shipping_method_order_option, array() );
$ret = array();
if ( is_array( $shipping_method_order ) ) {
foreach ( $shipping_method_order as $method_id ) {
if ( isset( $shipping_methods[$method_id] ) ) {$ret[$method_id] = $method_id;}
}
}
foreach ( $shipping_methods as $shipping_method ) {
if ( !isset( $ret[$shipping_method['id']] ) ) {$ret[$shipping_method['id']] = $shipping_method['id'];}
}
return $ret;
}
/**
* Generates method rules field.
*
* @param string $key .
* @param array $data .
*
* @return string
*/
/**
* Renders shipping rules settings.
*
* @param string $key .
* @param array $data .
*
* @return false|string
*/
public function generate_shipping_rules_html( $key, $data ) {
$rules_settings = new RulesSettingsField( $key, self::SETTING_METHOD_RULES, $data['title'], $data );
return $rules_settings->render();
}
public function shipping_method_title_used( $title, $shipping_methods ) {
foreach ( $shipping_methods as $shipping_method ) {
if ( $title == $shipping_method['method_title'] ) {
return true;
}
}
return false;
}
public function shipping_method_next_id( $shipping_methods ) {
$next_id = 0;
foreach ( $shipping_methods as $shipping_method ) {
if ( intval($shipping_method['id'] ) > $next_id ) {
$next_id = intval($shipping_method['id'] );
}
}
$next_id++;
return $next_id;
}
public function process_admin_options() {
$action = false;
if ( isset( $_POST['method_action'] ) ) {
$action = sanitize_key( $_POST['method_action'] );
}
if ( isset( $_POST['import_action'] ) && $_POST['import_action'] == '1' ) {
$this->process_import_action();
} elseif ( $action === 'new' || $action === 'edit' ) {
$save_rules = new SettingsProcessor(
$this->id, $this->instance_id, $this->shipping_methods_option, $this->shipping_method_order_option
);
try {
$shipping_method_settings = $save_rules->process_and_save_settings( $action, $_POST );
if ( $action === 'new' ) {
$this->redirect_new_method( $shipping_method_settings['id'] );
}
} catch ( Exception $e ) {
$this->add_error( $e->getMessage() );
}
} else {
parent::process_admin_options();
if ( isset( $_POST['method_order'] ) ) {
$this->process_order_method();
}
}
}
/**
* @param string $method_id .
*/
private function redirect_new_method( $method_id ) {
$redirect = add_query_arg( array('added' => $method_id, 'action' => false, 'method_id' => false ));
$redirect .= '#method_' . $method_id;
$redirect = add_query_arg( array('added' => $method_id, 'action' => 'edit', 'method_id' => $method_id ));
wpdesk_redirect( $redirect );
}
private function process_order_method() {
$method_order = $_POST['method_order'];
$method_order_security_alert = false;
foreach ( $method_order as $method_order_key => $method_id ) {
if ( strval( $method_order_key ) !== strval( sanitize_key( $method_order_key ) ) || strval( $method_id ) !== strval( sanitize_key( $method_id ) ) ) {
$method_order_security_alert = true;
}
}
if ( $method_order_security_alert ) {
WC_Admin_Settings::add_error( __( 'Flexible Shipping: security check error. Shipping method order not saved!', 'flexible-shipping' ) );
WC_Admin_Settings::show_messages();
} else {
update_option( $this->shipping_method_order_option, $method_order );
}
}
private function process_import_action() {
$shipping_methods = $this->get_option_shipping_methods();
if ( ! is_array( $shipping_methods ) ) {
$shipping_methods = array();
}
try {
$importer = ( new \WPDesk\FS\TableRate\ImporterExporter\Importer\ImporterFactory( $_FILES['import_file'], $this, $shipping_methods ) )->get_importer();
$importer->import();
$imported_shipping_methods = $importer->get_shipping_methods();
update_option( $this->shipping_methods_option, $imported_shipping_methods );
} catch ( Exception $e ) {
WC_Admin_Settings::add_error( $e->getMessage() );
}
WC_Admin_Settings::show_messages();
}
public function admin_options() {
$action = false;
if ( isset( $_GET['action'] ) )
{
$action = sanitize_key( $_GET['action'] );
}
$settings_div_class = in_array( $action, array( 'new', 'edit' ), true ) ? '' : 'fs-settings-div';
?>
<div class="<?php echo esc_html( $settings_div_class ) ; ?>"><table class="form-table">
<?php
if ( $action == 'new' || $action == 'edit' ) {
$shipping_methods = $this->get_option_shipping_methods();
$shipping_method = array(
'method_title' => '',
'method_description' => '',
'method_enabled' => 'no',
'method_shipping_zone' => '',
'method_calculation_method' => 'sum',
self::FIELD_METHOD_FREE_SHIPPING => '',
'method_free_shipping_label'=> '',
'method_visibility' => 'no',
'method_default' => 'no',
'method_integration' => '',
);
$method_id = '';
if ( $action == 'edit' ) {
$method_id = sanitize_key( $_GET['method_id'] );
$shipping_method = $shipping_methods[$method_id];
$method_id_for_shipping = $this->id . '_' . $this->instance_id . '_' . sanitize_title( $shipping_method['method_title'] );
$method_id_for_shipping = apply_filters( 'flexible_shipping_method_rate_id', $method_id_for_shipping, $shipping_method );
}
else {
$method_id_for_shipping = '';
}
?>
<input type="hidden" name="method_action" value="<?php echo $action; ?>" />
<input type="hidden" name="method_id" value="<?php echo $method_id; ?>" />
<input type="hidden" name="method_id_for_shipping" value="<?php echo $method_id_for_shipping; ?>" />
<?php if ( $action == 'new' ) : ?>
<h2><?php _e('New Shipping Method', 'flexible-shipping' ); ?></h2>
<?php endif; ?>
<?php if ( $action == 'edit' ) : ?>
<h2><?php _e('Edit Shipping Method', 'flexible-shipping' ); ?></h2>
<?php endif; ?>
<?php
if ( isset( $_GET['added'] ) ) {
$method_id = sanitize_key( $_GET['added'] );
$shipping_methods = $this->get_option_shipping_methods();
if ( isset( $shipping_methods[$method_id] ) )
{
if ( ! $this->message_added ) {
$shipping_method = $shipping_methods[$method_id];
WC_Admin_Settings::add_message( sprintf(__( 'Shipping method %s added.', 'flexible-shipping' ), $shipping_method['method_title'] ) );
$this->message_added = true;
}
}
WC_Admin_Settings::show_messages();
}
$shipping_method['woocommerce_method_instance_id'] = $this->instance_id;
$this->get_shipping_method_form($shipping_method);
$this->generate_settings_html();
}
else if ( $action == 'delete' ) {
$methods_id = '';
if ( isset( $_GET['methods_id'] ) ) {
$methods_id = explode( ',' , sanitize_text_field( $_GET['methods_id'] ) );
}
$shipping_methods = $this->get_option_shipping_methods();
$shipping_method_order = get_option( $this->shipping_method_order_option, array() );
foreach ( $methods_id as $method_id ) {
if ( isset( $shipping_methods[$method_id] ) ) {
$shipping_method = $shipping_methods[$method_id];
unset( $shipping_methods[$method_id] );
if ( isset( $shipping_method_order[$method_id] ) ) {
unset( $shipping_method_order[$method_id] );
}
update_option( $this->shipping_methods_option, $shipping_methods );
update_option( $this->shipping_method_order_option, $shipping_method_order );
WC_Admin_Settings::add_message( sprintf(__('Shipping method %s deleted.', 'flexible-shipping' ), $shipping_method['method_title'] ) );
}
else {
WC_Admin_Settings::add_error( __( 'Shipping method not found.', 'flexible-shipping' ) );
}
}
WC_Admin_Settings::show_messages();
$this->generate_settings_html();
}
else {
if ( isset( $_GET['added'] ) ) {
$method_id = sanitize_key( $_GET['added'] );
$shipping_methods = $this->get_option_shipping_methods();
if ( isset( $shipping_methods[$method_id] ) )
{
if ( ! $this->message_added ) {
$shipping_method = $shipping_methods[$method_id];
WC_Admin_Settings::add_message( sprintf(__( 'Shipping method %s added.', 'flexible-shipping' ), $shipping_method['method_title'] ) );
$this->message_added = true;
}
}
WC_Admin_Settings::show_messages();
}
if ( isset( $_GET['updated'] ) ) {
$method_id = sanitize_key( $_GET['updated'] );
$shipping_methods = $this->get_option_shipping_methods();
if ( isset( $shipping_methods[$method_id] ) )
{
$shipping_method = $shipping_methods[$method_id];
WC_Admin_Settings::add_message( sprintf(__( 'Shipping method %s updated.', 'flexible-shipping' ), $shipping_method['method_title'] ) );
}
WC_Admin_Settings::show_messages();
}
// General Settings
$this->generate_settings_html();
}
?>
</table>
<?php include __DIR__ . '/views/html-shipping-method-scripts.php'; ?>
<?php do_action( 'flexible_shipping_method_script', self::METHOD_ID, $this->instance_id ); ?>
<?php
}
private function get_shipping_method_form( $shipping_method ) {
$this->form_fields = ( new CommonMethodSettings() )->get_settings_fields( $shipping_method, true );
$this->form_fields = ( new SettingsDisplayPreparer() )->prepare_settings_for_display( $this->form_fields );
}
private function package_weight( $items ) {
$weight = 0;
foreach( $items as $item ) {
$weight += $item['data']->weight * $item['quantity'];
}
return $weight;
}
private function woocommerce_product_weight( $weight ) {
if ( $weight === '' ) {
return 0;
}
return $weight;
}
private function package_item_count( $items ) {
$item_count = 0;
foreach( $items as $item ) {
$item_count += $item['quantity'];
}
return $item_count;
}
private function cart_item_count() {
$item_count = 0;
$cart = WC()->cart;
foreach( $cart->cart_contents as $item ) {
$item_count += $item['quantity'];
}
return $item_count;
}
/**
* @param array $package
*/
public function calculate_shipping( $package = array() ) {
$shipping_methods = $this->get_shipping_methods( true );
$rate_calculator = RateCalculatorFactory::create_for_shipping_method( $this, $package );
foreach ( $shipping_methods as $shipping_method_settings ) {
$method_settings = MethodSettingsFactory::create_from_array_and_tax_status( $shipping_method_settings, $this->tax_status );
$logger = $this->prepare_shipping_method_calculation_logger( $method_settings );
$rate_calculator->set_logger( $logger );
$calculated_rate = $rate_calculator->calculate_rate( $method_settings, $this->prepare_rate_id( $method_settings->get_raw_settings() ), is_user_logged_in() );
if ( ! empty( $calculated_rate ) ) {
$this->add_rate( $calculated_rate );
$logger->debug( __( 'Shipping cost added.', 'flexible-shipping' ), $logger->get_results_context() );
}
$logger->show_notice_if_enabled();
}
}
/**
* @param string $suffix
*
* @return string
*/
public function prepare_rate_id( $shipping_method_settings ) {
$id = $this->id . '_' . $this->instance_id . '_' . sanitize_title( $shipping_method_settings['method_title'] );
$id = apply_filters( 'flexible_shipping_method_rate_id', $id, $shipping_method_settings );
return $id;
}
public function set_as_converted() {
$shipping_method_key = $this->get_instance_option_key();
$shipping_method_options = $this->get_instance_options();
$shipping_method_options['converted'] = 'yes';
update_option( $shipping_method_key, $shipping_method_options );
}
/**
* @return bool
*/
public function is_converted() {
$shipping_method_options = $this->get_instance_options();
return isset( $shipping_method_options['converted'] ) ? $shipping_method_options['converted'] === 'yes' : false;
}
/**
* @return array
*/
private function get_instance_options() {
$options = get_option( $this->get_instance_option_key(), array() );
if ( ! is_array( $options ) ) {
$options = array();
}
return $options;
}
/**
* @return bool
*/
private function prices_include_tax() {
return (bool) apply_filters( 'flexible_shipping_prices_include_tax', WC()->cart->display_prices_including_tax() );
}
/**
* @return array
*/
public function get_all_rates() {
return FlexibleShippingRates::get_flexible_shipping_rates();
}
/**
* Add beacon search data to fields.
*
* @param array $form_fields .
*
* @return array
*/
private function add_beacon_search_data_to_fields( array $form_fields ) {
$modifier = new WooCommerceSettingsFieldsModifier();
return $modifier->append_beacon_search_data_to_fields( $form_fields );
}
/**
* @return array
*/
private function get_option_shipping_methods() {
$shipping_methods = get_option( $this->shipping_methods_option, array() );
if ( ! is_array( $shipping_methods ) ) {
$shipping_methods = array();
}
return $shipping_methods;
}
/**
* @return bool
*/
private function is_allowed_support_shipping_zones() {
return ! is_admin() || (bool) apply_filters( 'flexible-shipping/group-method/supports/shipping-zones', false );
}
/**
* @return bool
*/
private function is_allowed_editing() {
return (bool) apply_filters( 'flexible-shipping/group-method/supports/edit', false );
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* @package Flexible Shipping
*
* @var string $shipping_method_id .
*/
?>
<div class="fs-flexible-shipping-sidebar fs-flexible-shipping-sidebar-pro <?php echo esc_attr( isset( $shipping_method_id ) ? $shipping_method_id : '' ); ?>" style="height: auto;">
<div class="wpdesk-metabox">
<div class="wpdesk-stuffbox">
<h3 class="title"><?php esc_html_e( 'Get Flexible Shipping PRO!', 'flexible-shipping' ); ?></h3>
<?php
$fs_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-box-upgrade-pl' : 'https://octol.io/fs-box-upgrade';
?>
<div class="inside">
<div class="main">
<ul>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Shipping Classes support', 'flexible-shipping' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Product count based costs', 'flexible-shipping' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Stopping, Cancelling a rule', 'flexible-shipping' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Additional calculation methods', 'flexible-shipping' ); ?>
</li>
</ul>
<a class="button button-primary" href="<?php echo esc_url( $fs_link ); ?>"
target="_blank"><?php esc_html_e( 'Upgrade now to PRO version &rarr;', 'flexible-shipping' ); ?></a>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,37 @@
<?php
/**
* @package Flexible Shipping
*
* @var string $shipping_method_id .
*/
$fsie_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-info-addons-pl' : 'https://octol.io/addons-box-fs';
?>
<div class="fs-flexible-shipping-sidebar fs-flexible-shipping-sidebar-fsie <?php echo esc_attr( isset( $shipping_method_id ) ? $shipping_method_id : '' ); ?>"
style="height: auto;">
<div class="wpdesk-metabox">
<div class="wpdesk-stuffbox">
<h3 class="title"><?php esc_html_e( 'Extend the Flexible Shipping capabilities with functional add-ons', 'flexible-shipping' ); ?></h3>
<div class="inside">
<div class="main">
<ul>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Calculate the shipping cost based on your custom locations or the WooCommerce defaults', 'flexible-shipping' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Define shipping cost for each Vendor / Product Author in your marketplace', 'flexible-shipping' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span> <?php esc_html_e( 'Move, replace, update or backup multiple shipping methods with Import / Export feature', 'flexible-shipping' ); ?>
</li>
</ul>
<a class="button button-primary" href="<?php echo esc_url( $fsie_link ); ?>"
target="_blank"><?php esc_html_e( 'Buy Flexible Shipping Add-ons &rarr;', 'flexible-shipping' ); ?></a>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,21 @@
<?php
/**
* @package Flexible Shipping
*
* @var string $shipping_method_id .
*/
$show_fs_pro_ads = ! wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' );
if ( $show_fs_pro_ads ) {
include 'ads/html-ads-fs-pro.php';
}
$show_fs_ie_ads = wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) && ! wpdesk_is_plugin_active( 'flexible-shipping-import-export/flexible-shipping-import-export.php' );
if ( $show_fs_ie_ads ) {
include 'ads/html-ads-fsie.php';
}
?>
<div class="clear"></div>

View File

@@ -0,0 +1,6 @@
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<div class="flexible_shipping_message">
<span class="<?php echo $messages[$post->ID]['status']; ?>">
<?php echo $messages[$post->ID]['message']; ?>
</span>
</div>

View File

@@ -0,0 +1,45 @@
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<span class="<?php echo esc_attr( $data['class'] ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>">
<table class="flexible_shipping_services wc_shipping widefat wp-list-table" cellspacing="0">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th class="service_code"><?php _e( 'Code', 'flexible-shipping' ); ?></th>
<th class="service_name"><?php _e( 'Name', 'flexible-shipping' ); ?></th>
<th class="select">
<?php _e( 'Enabled', 'flexible-shipping' ); ?><?php /* <input type="checkbox" class="tips checkbox-select-all-services" value="1" data-tip="<?php _e( 'Enable all', 'flexible-shipping' ); ?>" /> */ ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ( $services as $service_code => $service ) : ?>
<tr>
<td class="sort"></td>
<td class="service_code"><?php echo $service_code; ?></td>
<td class="service_name">
<input name="<?php echo esc_attr( $field_key ); ?>[<?php echo $service_code ?>][name]" type="text" value="<?php echo esc_attr( $service['name'] ); ?>" class="woocommerce_flexible_shipping_service_name"/>
</td>
<td width="1%" class="select" nowrap>
<input name="<?php echo esc_attr( $field_key ); ?>[<?php echo $service_code ?>][enabled]" type="checkbox" class="checkbox-select-service" value="<?php echo esc_attr( $service_code ); ?>" <?php echo $service['enabled'] ? 'checked' : ''; ;?> />
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th colspan="4"><span class="description"><?php _e( 'Drag and drop the services to control their display order. Confirm by clicking Save changes button below.', 'flexible-shipping' ); ?></span></th>
</tr>
</tfoot>
</table>
</span>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>

View File

@@ -0,0 +1,15 @@
<style type="text/css" media="screen">
#adminmenu #toplevel_page_flexible-shipping-menu a div.wp-menu-image::before {
font-family: WooCommerce !important;
content: '\e019';
}
.toplevel_page_flexible-shipping-menu #wpdesk_tracker_notice {
margin: 10px 20px 0 2px;
}
.fs-connect__inner-container {
background-color: #FFF;
margin-bottom: 20px;
}
</style>

View File

@@ -0,0 +1,36 @@
<?php
/**
* @package Flexible Shipping
*
* Shipping method scripts.
*/
?>
<script type="text/javascript">
var url = document.location.href;
url = fs_removeParam( 'action', url );
url = fs_removeParam( 'methods_id', url );
url = fs_removeParam( 'added', url );
url = fs_trimChar( url, '?' );
if ( url.includes( 'method_id=' ) ) {
url = url + "&action=edit";
}
jQuery( '#mainform' ).attr( 'action', url );
</script>
<?php if ( isset( $_GET['action'] ) && isset( $_GET['instance_id'] ) ) : ?>
<script type="text/javascript">
<?php
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', sanitize_key( $_GET['instance_id'] ) );
$shipping_method_woo = WC_Shipping_Zones::get_shipping_method( sanitize_key( $_GET['instance_id'] ) );
$content = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping' ) . '">' . __( 'Shipping Zones', 'flexible-shipping' ) . '</a> &gt ';
$content .= '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=' . absint( $zone->get_id() ) ) . '">' . esc_html( $zone->get_zone_name() ) . '</a> &gt ';
$content .= '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping&instance_id=' . sanitize_key( $_GET['instance_id'] ) ) . '">' . esc_html( $shipping_method_woo->get_title() ) . '</a>';
$content .= ' &gt <span class="flexible-shipping-method-title"></span>';
?>
jQuery('#mainform h2').first().replaceWith( '<h2>' + '<?php echo $content; // phpcs:ignore ?>' + '</h2>' );
jQuery('.flexible-shipping-method-title').text(jQuery('#woocommerce_flexible_shipping_method_title').val());
jQuery('#woocommerce_flexible_shipping_method_title').on('keyup',function(){
jQuery('.flexible-shipping-method-title').text(jQuery('#woocommerce_flexible_shipping_method_title').val());
});
</script>
<?php endif; ?>

View File

@@ -0,0 +1,230 @@
<?php if ( ! defined( 'ABSPATH' ) ) {
exit;
} ?>
<tr valign="top">
<td class="forminp" style="padding-left:0;padding-right:0;">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<table class="flexible_shipping_methods wc_shipping widefat wp-list-table" cellspacing="0">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th class="title"><?php esc_html_e( 'Title', 'flexible-shipping' ); ?></th>
<th class="status"><?php esc_html_e( 'Enabled', 'flexible-shipping' ); ?></th>
<th class="visibility"><?php esc_html_e( 'Visibility', 'flexible-shipping' ); ?></th>
<th class="default"><?php esc_html_e( 'Default', 'flexible-shipping' ); ?></th>
<th class="integration"><?php esc_html_e( 'Integration', 'flexible-shipping' ); ?></th>
<th class="select check-column"><input type="checkbox" class="tips checkbox-select-all"
value="1"
data-tip="<?php esc_attr_e( 'Select all', 'flexible-shipping' ); ?>"/>
</th>
</tr>
</thead>
<tbody>
<?php if ( isset( $shipping_method_order ) && is_array( $shipping_method_order ) ) : ?>
<?php foreach ( $shipping_method_order as $shipping_method_id ) : ?>
<?php $shipping_method = $shipping_methods[ $shipping_method_id ]; ?>
<?php $tr_class = ''; ?>
<?php
if ( isset( $_GET['added'] ) && sanitize_key( $_GET['added'] ) == $shipping_method_id ) {
$tr_class = 'highlight';
}
if ( isset( $_GET['updated'] ) && sanitize_key( $_GET['updated'] ) == $shipping_method_id ) {
$tr_class = 'highlight';
}
?>
<tr id="method_<?php echo esc_attr( $shipping_method_id ); ?>" class="<?php echo esc_attr( $tr_class ); ?>">
<td width="1%" class="sort">
<input type="hidden"
name="method_order[<?php echo esc_attr( $shipping_method['id'] ); ?>]"
value="<?php echo esc_attr( $shipping_method['id'] ); ?>"/>
</td>
<td class="title">
<a data-qa-id="shipping-method-<?php echo esc_attr( $shipping_method['method_title'] ); ?>"
href="<?php echo esc_url( add_query_arg( 'method_id', $shipping_method_id, add_query_arg( 'action', 'edit' ) ) ); ?>">
<strong><?php echo esc_html( $shipping_method['method_title'] ); ?></strong>
</a>
<?php if ( isset( $shipping_method['method_description'] ) && $shipping_method['method_description'] != '' ) : ?>
(<?php echo esc_html( $shipping_method['method_description'] ); ?>)
<?php endif; ?>
</td>
<td width="1%" class="status">
<?php if ( isset( $shipping_method['method_enabled'] ) && 'yes' === $shipping_method['method_enabled'] ) : ?>
<span class="status-enabled tips"
data-tip="<?php esc_attr_e( 'yes', 'flexible-shipping' ); ?>"><?php esc_html_e( 'yes', 'flexible-shipping' ); ?></span>
<?php else : ?>
<span class="na">-</span>
<?php endif; ?>
</td>
<td width="1%" class="default visibility">
<?php if ( isset( $shipping_method['method_visibility'] ) && 'yes' === $shipping_method['method_visibility'] ) : ?>
<span class="status-enabled tips"
data-tip="<?php esc_attr_e( 'Show only for logged in users', 'flexible-shipping' ); ?>"><?php esc_html_e( 'yes', 'flexible-shipping' ); ?></span>
<?php else : ?>
<span class="na tips"
data-tip="<?php esc_attr_e( 'Show for all users', 'flexible-shipping' ); ?>">-</span>
<?php endif; ?>
</td>
<td width="1%" class="default">
<?php if ( 'yes' === $shipping_method['method_default'] ) : ?>
<span class="status-enabled tips"
data-tip="<?php esc_attr_e( 'yes', 'flexible-shipping' ); ?>"><?php esc_html_e( 'yes', 'flexible-shipping' ); ?></span>
<?php else : ?>
<span class="na">-</span>
<?php endif; ?>
</td>
<?php echo wp_kses_post( apply_filters( 'flexible_shipping_method_integration_col', '<td width="1%" class="integration default">-</td>', $shipping_method ) ); ?>
<td width="1%" class="select check-column" nowrap>
<input type="checkbox" class="tips checkbox-select"
value="<?php echo esc_attr( $shipping_method['id'] ); ?>"
data-tip="<?php echo esc_html( $shipping_method['method_title'] ); ?>"/>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<th>&nbsp;</th>
<th colspan="8"><span
class="description"><?php esc_html_e( 'Drag and drop the above shipment methods to control their display order. Confirm by clicking Save changes button below.', 'flexible-shipping' ); ?></span>
</th>
</tr>
<tr>
<th>&nbsp;</th>
<th colspan="8">
<button id="flexible_shipping_remove_selected" class="button"
disabled><?php esc_html_e( 'Remove selected', 'flexible-shipping' ); ?></button>
<div class="flexilble_shipping_export_import">
<input id="flexible_shipping_import_file" type="file" name="import_file"
style="display:none;" accept=".csv,.json"/>
<input id="flexible_shipping_import_action" type="hidden" name="import_action"
value="0"/>
<button id="flexible_shipping_import_cancel" class="button"
style="display:none;"><?php esc_html_e( 'Cancel import', 'flexible-shipping' ); ?></button>
<input id="flexible_shipping_do_import" style="display:none;"
class="button button-primary"
data-instance-id="<?php echo esc_attr( isset( $_GET['instance_id'] ) ? sanitize_key( $_GET['instance_id'] ) : '1' ); ?>"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'flexible_shipping' ) ); ?>" type="submit"
value="<?php esc_attr_e( 'Import', 'flexible-shipping' ); ?>"/>
<button id="flexible_shipping_import" class="button"
data-instance-id="<?php isset( $_GET['instance_id'] ) ? sanitize_key( $_GET['instance_id'] ) : '1'; ?>"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'flexible_shipping' ) ); ?>"><?php esc_html_e( 'Import', 'flexible-shipping' ); ?></button>
<?php do_action( 'flexible_shipping_actions_row' ); ?>
</div>
<div style="clear:both;"></div>
</th>
</tr>
</tfoot>
</table>
<?php echo wp_kses_post( $this->get_description_html( $data ) ); ?>
</fieldset>
</td>
</tr>
<script type="text/javascript">
<?php
if ( version_compare( WC()->version, '2.6.0', '>=' ) ) :
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', sanitize_key( $_GET['instance_id'] ) );
$shipping_method_woo = WC_Shipping_Zones::get_shipping_method( sanitize_key( $_GET['instance_id'] ) );
$content = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping' ) . '">' . __( 'Shipping Zones', 'flexible-shipping' ) . '</a> > ';
$content .= '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=' . absint( $zone->get_id() ) ) . '">' . esc_html( $zone->get_zone_name() ) . '</a> >';
$content .= esc_html( $shipping_method_woo->get_title() );
?>
jQuery('#mainform h2').first().replaceWith('<h2>' + '<?php echo wp_kses_post( $content ); ?>' + '</h2>');
<?php
global $wp;
$current_url = 'admin.php?page=wc-settings&tab=shipping&instance_id=' . sanitize_key( $_GET['instance_id'] );
?>
jQuery('#mainform').attr('action', '<?php echo esc_url( $current_url ); ?>');
<?php
endif;
?>
jQuery("input.checkbox-select-all").click(function () {
if (jQuery(this).is(':checked')) {
jQuery('input.checkbox-select').prop('checked', true);
} else {
jQuery('input.checkbox-select').prop('checked', false);
}
})
/**
* Enable Bulk Action Buttons when at least one Shipping Method is selected
*
*/
jQuery('.flexible_shipping_methods input[type="checkbox"]').click(function () {
jQuery('#flexible_shipping_export_selected, #flexible_shipping_remove_selected').attr('disabled', !jQuery('.flexible_shipping_methods td input[type="checkbox"]').is(':checked'));
});
jQuery('#flexible_shipping_remove_selected').click(function () {
var empty_url = '<?php echo add_query_arg( 'methods_id', '', add_query_arg( 'action', 'delete', admin_url( 'admin.php?page=wc-settings&tab=shipping&instance_id=' . sanitize_key( $_GET['instance_id'] ) ) ) ); // phpcs:ignore ?>';
var url = empty_url;
var first = true;
jQuery('input.checkbox-select').each(function () {
if (jQuery(this).is(':checked')) {
if (!first) {
url = url + ',';
} else {
url = url + '=';
}
url = url + jQuery(this).val();
first = false;
}
})
if (first) {
alert('<?php esc_attr_e( 'Please select shipment methods to remove', 'flexible-shipping' ); ?>');
return false;
}
if (url !== empty_url) {
jQuery('#flexible_shipping_remove_selected').prop('disabled', true);
jQuery('.woocommerce-save-button').prop('disabled', true);
window.location.href = url;
}
return false;
})
jQuery('#flexible_shipping_import').click(function () {
jQuery(this).hide();
jQuery('#flexible_shipping_do_import').show();
jQuery('#flexible_shipping_import_file').show();
jQuery('#flexible_shipping_import_cancel').show();
jQuery('input[name=save]').prop('disabled', true);
return false;
})
jQuery('#flexible_shipping_import_cancel').click(function () {
jQuery(this).hide();
jQuery('#flexible_shipping_do_import').hide();
jQuery('#flexible_shipping_import_file').hide();
jQuery('#flexible_shipping_import_cancel').hide();
jQuery('#flexible_shipping_import').show();
jQuery('input[name=save]').prop('disabled', false);
return false;
})
jQuery('#flexible_shipping_do_import').click(function () {
if (jQuery('#flexible_shipping_import_file').val() == '') {
alert('<?php esc_attr_e( 'Select file to import', 'flexible-shipping' ); ?>');
return false;
}
jQuery('#flexible_shipping_import_action').val('1');
jQuery('input[name=save]').prop('disabled', false);
jQuery('.woocommerce-save-button').click();
return false;
})
<?php
if ( isset( $_POST['import_action'] ) && sanitize_key( $_POST['import_action'] ) == '1' ) { // phpcs:ignore
?>
jQuery('.updated.inline:lt(1)').hide();
jQuery('.updated.inline:lt(2)').hide();
<?php
}
?>
</script>
<?php

View File

@@ -0,0 +1,76 @@
<?php
/**
* @var $integration_checkbox bool
* @var $show_fs_connect bool
*/
$pl = get_locale() === 'pl_PL';
$youtube_url = 'https://www.youtube.com/embed/qsFvYoiNDgU';
$general_settings_url = $pl ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/?utm_source=flexible-shipping-info&utm_medium=link&utm_campaign=flexible-shipping-resources-box&utm_content=general-settings#Ustawienia_glowne' : 'https://docs.flexibleshipping.com/article/25-general-settings/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=general-settings&utm_content=fs-configuration-flexibleshippingtablerate';
$adding_a_shipping_method_url = $pl ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/?utm_source=flexible-shipping-info&utm_medium=link&utm_campaign=flexible-shipping-resources-box&utm_content=adding-a-shipping-method#Metody_wysylki' : 'https://docs.flexibleshipping.com/article/29-shipping-methods/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=adding-a-shipping-method&utm_content=fs-configuration-flexibleshippingtablerate';
$currency_support_url = $pl ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/?utm_source=flexible-shipping-info&utm_medium=link&utm_campaign=flexible-shipping-resources-box&utm_content=currency-support#Waluty' : 'https://docs.flexibleshipping.com/article/30-currency-support/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=currency-support&utm_content=fs-configuration-flexibleshippingtablerate';
$weight_based_shipping_url = $pl ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/?utm_source=flexible-shipping-info&utm_medium=link&utm_campaign=flexible-shipping-resources-box&utm_content=weight-based-shipping#Koszt_na_wage' : 'https://docs.flexibleshipping.com/article/32-weight-based-shipping-woocommerce/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=weight-based-shipping&utm_content=fs-configuration-flexibleshippingtablerate';
$shipping_insurance_url = $pl ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/?utm_source=flexible-shipping-info&utm_medium=link&utm_campaign=flexible-shipping-resources-box&utm_content=shipping-insurance#Ubezpieczenie_przesylki' : 'https://docs.flexibleshipping.com/article/34-shipping-insurance/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=shipping-insurance&utm_content=fs-configuration-flexibleshippingtablerate';
$conditional_cash_on_delivery_url = $pl ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/?utm_source=flexible-shipping-info&utm_medium=link&utm_campaign=flexible-shipping-resources-box&utm_content=conditional-cash-on-delivery#Przesylka_za_pobraniem' : 'https://docs.flexibleshipping.com/article/35-conditional-cash-on-delivery/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=contitional-cash-on-delivery&utm_content=fs-configuration-flexibleshippingtablerate';
?>
</table>
<div class="fs-page-wrap">
<div class="fs-box">
<h3 class="wc-settings-sub-title"><?php _e( 'How to use Flexible Shipping?', 'flexible-shipping' ); ?></h3>
<ol>
<li>
<?php
echo sprintf(
__( 'To add first Flexible Shipping method go to %sShipping zones%s and add Flexible Shipping to a shipping zone.', 'flexible-shipping' ),
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping&section' ) . '">',
'</a>'
);
?>
</li>
<li><?php _e( 'You can start the configuration by clicking the Flexible Shipping link in the Shipping methods table.', 'flexible-shipping' ); ?></li>
</ol>
<h4><?php _e( 'Quick Video Overview', 'flexible-shipping' ); ?></h4>
<div class="flexible-shipping-video">
<iframe width="688" height="387" src="<?php echo $youtube_url?>?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
<h4><?php _e( 'More resources', 'flexible-shipping' ); ?></h4>
<ul>
<li><a href="<?php echo $general_settings_url; ?>"><?php _e( 'General Settings', 'flexible-shipping' ); ?></a></li>
<li><a href="<?php echo $adding_a_shipping_method_url; ?>"><?php _e( 'Adding a shipping method', 'flexible-shipping' ); ?></a></li>
<li><a href="<?php echo $currency_support_url; ?>"><?php _e( 'Currency Support', 'flexible-shipping' ); ?></a></li>
<li><a href="<?php echo $weight_based_shipping_url; ?>"><?php _e( 'Weight Based Shipping', 'flexible-shipping' ); ?></a></li>
<li><a href="<?php echo $shipping_insurance_url; ?>"><?php _e( 'Shipping Insurance', 'flexible-shipping' ); ?></a></li>
<li><a href="<?php echo $conditional_cash_on_delivery_url; ?>"><?php _e( 'Conditional Cash on Delivery', 'flexible-shipping' ); ?></a></li>
</ul>
<?php if ( $show_fs_connect ) : ?>
<h3 class="wc-settings-sub-title fs-connect-box-header"><?php _e( 'Integrations', 'flexible-shipping' ); ?></h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="enable-fs-connect-box"><?php _e( 'FS Connect', 'flexible-shipping' ); ?></label>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'FS Connect', 'flexible-shipping' ); ?></span></legend>
<label for="enable-fs-connect-box">
<input class="enable-fs-connect-box" <?php checked( $integration_checkbox, 1 ); ?> type="checkbox" name="fsconnect_box" id="enable-fs-connect-box" style="" value="1"> <?php _e( 'Enable integration with Flexible Shipping Connect', 'flexible-shipping' ); ?>
</label>
</fieldset>
</td>
</tr>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
<table>

View File

@@ -0,0 +1,32 @@
<?php
/**
* @var Metabox[] $metaboxes .
*
* @package Flexible Shipping
*/
use WPDesk\FS\Info\Metabox;
?>
</table>
<div class="fs-info-wrapper">
<?php foreach ( $metaboxes as $metabox ) : ?>
<div id="<?php echo esc_attr( $metabox->get_id() ); ?>"
class="<?php echo esc_attr( $metabox->get_classes() ); ?>">
<?php if ( $metabox->has_title() ) : ?>
<h3><?php echo esc_html( $metabox->get_title() ); ?></h3>
<?php endif; ?>
<?php if ( $metabox->has_body() ) : ?>
<div class="content"><?php echo $metabox->get_body(); // phpcs:ignore ?></div>
<?php endif; ?>
<?php if ( $metabox->has_footer() ) : ?>
<div class="footer"><?php echo wp_kses_post( $metabox->get_footer() ); ?></div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<table>

View File

@@ -0,0 +1,130 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Method_Created_Tracker_Deactivation_Data
*
* @package Flexible Shipping.
*/
use WPDesk\FS\TableRate\ShippingMethodSingle;
/**
* Class by which we can push created methods data to the deactivation filter
*/
class WPDesk_Flexible_Shipping_Method_Created_Tracker_Deactivation_Data implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
const OPTION_FS_METHOD_CREATED_TRACKER = 'fs_method_created_tracker';
const TRACK_USERS_AFTER_THIS_DATE = '2019-04-11 01:00:00';
const NO_ACTION_WITH_FS = 0;
const FLEXIBLE_SHIPPING_METHOD_ADDED_TO_ZONE = 1;
const FLEXIBLE_SHIPPING_METHOD_ADDED_TO_FS = 2;
const FLEXIBLE_SHIPPING_SINGLE_ADDED_TO_ZONE = 3;
const FLEXIBLE_SHIPPING_FS_INFO_VIEWED = 4;
/**
* Fires hooks
*/
public function hooks() {
add_filter( 'wpdesk_tracker_deactivation_data', array( $this, 'append_variant_id_to_data' ) );
add_action( 'woocommerce_shipping_zone_method_added', array( $this, 'maybe_update_option_on_zone_method_added' ), 10, 3 );
add_filter( 'flexible_shipping_process_admin_options', array( $this, 'maybe_update_option_on_fs_method_saved' ) );
add_action( 'admin_footer', array( $this, 'update_option_when_in_fs_info' ) );
}
/**
* .
*/
public function update_option_when_in_fs_info() {
if ( ! $this->is_old_installation() && isset( $_GET['page'] ) && isset( $_GET['tab'] ) && isset( $_GET['section'] )
&& 'wc-settings' === $_GET['page'] && 'shipping' === $_GET['tab'] && 'flexible_shipping_info' === $_GET['section']
) {
$option_value = intval( get_option( self::OPTION_FS_METHOD_CREATED_TRACKER, '0' ) );
if ( self::NO_ACTION_WITH_FS === $option_value ) {
update_option( self::OPTION_FS_METHOD_CREATED_TRACKER, self::FLEXIBLE_SHIPPING_FS_INFO_VIEWED );
}
}
}
/**
* Maybe update option on FS method saved.
*
* @param array $shipping_method Shipping method.
*
* @return array
*/
public function maybe_update_option_on_fs_method_saved( array $shipping_method ) {
if ( ! $this->is_old_installation() ) {
$option_value = intval( get_option( self::OPTION_FS_METHOD_CREATED_TRACKER, '0' ) );
if ( self::FLEXIBLE_SHIPPING_METHOD_ADDED_TO_FS !== $option_value ) {
update_option( self::OPTION_FS_METHOD_CREATED_TRACKER, self::FLEXIBLE_SHIPPING_METHOD_ADDED_TO_FS );
}
}
return $shipping_method;
}
/**
* Maybe update option on zone method added action.
*
* @param int $instance_id Instance ID.
* @param string $type Type.
* @param int $zone_id Zone ID.
*/
public function maybe_update_option_on_zone_method_added( $instance_id, $type, $zone_id ) {
if ( WPDesk_Flexible_Shipping::METHOD_ID === $type ) {
if ( ! $this->is_old_installation() ) {
$option_value = intval( get_option( self::OPTION_FS_METHOD_CREATED_TRACKER, '0' ) );
if ( self::NO_ACTION_WITH_FS === $option_value || self::FLEXIBLE_SHIPPING_FS_INFO_VIEWED === $option_value ) {
update_option( self::OPTION_FS_METHOD_CREATED_TRACKER, self::FLEXIBLE_SHIPPING_METHOD_ADDED_TO_ZONE );
}
}
}
if ( ShippingMethodSingle::SHIPPING_METHOD_ID === $type ) {
if ( ! $this->is_old_installation() ) {
update_option( self::OPTION_FS_METHOD_CREATED_TRACKER, self::FLEXIBLE_SHIPPING_SINGLE_ADDED_TO_ZONE );
}
}
}
/**
* If this a old user? If so then FS should work like always.
*
* @return bool
*/
private function is_old_installation() {
return strtotime( self::TRACK_USERS_AFTER_THIS_DATE ) > $this->activation_date_according_to_wpdesk_helper();
}
/**
* Activation date according to wpdesk helper.
*
* @return int timestamp
*/
private function activation_date_according_to_wpdesk_helper() {
$option_name = 'plugin_activation_flexible-shipping/flexible-shipping.php';
$activation_date = get_option( $option_name, current_time( 'mysql' ) );
if ( ! $activation_date ) {
return time();
}
return strtotime( $activation_date );
}
/**
* Set fs_method_created option value to data array
*
* @param array $data Data.
*
* @return array
*/
public function append_variant_id_to_data( array $data ) {
if ( ! $this->is_old_installation() ) {
if ( WPDesk_Flexible_Shipping_Tracker::is_plugin_flexible_shipping_in_data( $data ) ) {
$data['fs_method_created'] = intval( get_option( self::OPTION_FS_METHOD_CREATED_TRACKER, '0' ) );
}
}
return $data;
}
}

View File

@@ -0,0 +1,179 @@
<?php
/**
* Tracker.
*
* @package Flexible Shipping.
*/
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use WPDesk\FS\TableRate\ShippingMethodSingle;
use WPDesk\FS\TableRate\SingleRuleSettings;
/**
* Handle Tracker actions and filters.
*/
class WPDesk_Flexible_Shipping_Tracker implements Hookable {
const PLUGIN_ACTION_LINKS_FILTER_NAME = 'plugin_action_links_flexible-shipping/flexible-shipping.php';
const FLEXIBLE_SHIPPING_PLUGIN_FILE = 'flexible-shipping/flexible-shipping.php';
const FLEXIBLE_SHIPPING_PLUGIN_SLUG = 'flexible-shipping';
const FLEXIBLE_SHIPPING_PLUGIN_TITLE = 'Flexible Shipping';
const TRACKER_DATA_FILTER_PRIORITY = 11;
/**
* Is plugin flexible shipping in data.
*
* @param array $data Data.
* @return bool
*/
public static function is_plugin_flexible_shipping_in_data( $data ) {
return is_array( $data ) && isset( $data['plugin'] ) && self::FLEXIBLE_SHIPPING_PLUGIN_FILE === $data['plugin'];
}
/**
* Hooks.
*/
public function hooks() {
add_filter( 'wpdesk_tracker_data', [ $this, 'wpdesk_tracker_data_flexible_shipping' ], self::TRACKER_DATA_FILTER_PRIORITY );
}
/**
* Append data.
*
* @param array $data Data.
*
* @return array
*/
public function wpdesk_tracker_data_flexible_shipping( $data ) {
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
$flexible_shipping = $all_shipping_methods['flexible_shipping'];
$flexible_shipping_rates = $flexible_shipping->get_all_rates();
$data['flexible_shipping'] = [];
$data['flexible_shipping']['total_shipping_methods'] = 0;
$data['flexible_shipping']['group_shipping_methods'] = 0;
$data['flexible_shipping']['single_shipping_methods'] = 0;
$data['flexible_shipping']['avg_rules'] = 0;
$data['flexible_shipping']['max_rules'] = 0;
$data['flexible_shipping']['integrations'] = [];
$data['flexible_shipping']['free_shipping_requires'] = [];
$data['flexible_shipping']['calculation_methods'] = [];
$data['flexible_shipping']['based_on'] = [];
$data['flexible_shipping']['shipping_class_option'] = [];
$data['flexible_shipping']['method_description_count'] = 0;
$data['flexible_shipping']['free_shipping_label_count'] = 0;
$data['flexible_shipping']['free_shipping_cart_notice_count'] = 0;
$data['flexible_shipping']['max_cost_count'] = 0;
$data['flexible_shipping']['visibility_count'] = 0;
$data['flexible_shipping']['default_count'] = 0;
$data['flexible_shipping']['additional_cost_count'] = 0;
$data['flexible_shipping']['min_count'] = 0;
$data['flexible_shipping']['max_count'] = 0;
$data['flexible_shipping']['cost_per_order_count'] = 0;
$data['flexible_shipping']['stop_count'] = 0;
$data['flexible_shipping']['cancel_count'] = 0;
foreach ( $flexible_shipping_rates as $rate_id => $flexible_shipping_rate ) {
if ( ! isset( $flexible_shipping_rate['method_rules'] ) ) {
$flexible_shipping_rate['method_rules'] = [];
}
$data['flexible_shipping']['total_shipping_methods'] ++;
if ( ShippingMethodSingle::SHIPPING_METHOD_ID === $flexible_shipping_rate['method_id'] ) {
$data['flexible_shipping']['single_shipping_methods']++;
}
if ( WPDesk_Flexible_Shipping::METHOD_ID === $flexible_shipping_rate['method_id'] ) {
$data['flexible_shipping']['group_shipping_methods']++;
}
$data['flexible_shipping']['avg_rules'] += count( $flexible_shipping_rate['method_rules'] );
if ( count( $flexible_shipping_rate['method_rules'] ) > $data['flexible_shipping']['max_rules'] ) {
$data['flexible_shipping']['max_rules'] = count( $flexible_shipping_rate['method_rules'] );
}
if ( empty( $flexible_shipping_rate['method_integration'] ) ) {
$flexible_shipping_rate['method_integration'] = 'none';
}
if ( empty( $data['flexible_shipping']['integrations'][ $flexible_shipping_rate['method_integration'] ] ) ) {
$data['flexible_shipping']['integrations'][ $flexible_shipping_rate['method_integration'] ] = 0;
}
$data['flexible_shipping']['integrations'][ $flexible_shipping_rate['method_integration'] ] ++;
if ( ! empty( $flexible_shipping_rate['method_free_shipping_requires'] ) ) {
if ( empty( $data['flexible_shipping']['free_shipping_requires'][ $flexible_shipping_rate['method_free_shipping_requires'] ] ) ) {
$data['flexible_shipping']['free_shipping_requires'][ $flexible_shipping_rate['method_free_shipping_requires'] ] = 0;
}
$data['flexible_shipping']['free_shipping_requires'][ $flexible_shipping_rate['method_free_shipping_requires'] ] ++;
}
if ( empty( $data['flexible_shipping']['calculation_methods'][ $flexible_shipping_rate['method_calculation_method'] ] ) ) {
$data['flexible_shipping']['calculation_methods'][ $flexible_shipping_rate['method_calculation_method'] ] = 0;
}
$data['flexible_shipping']['calculation_methods'][ $flexible_shipping_rate['method_calculation_method'] ] ++;
if ( ! empty( $flexible_shipping_rate['method_description'] ) ) {
$data['flexible_shipping']['method_description_count'] ++;
}
if ( ! empty( $flexible_shipping_rate['method_free_shipping_label'] ) ) {
$data['flexible_shipping']['free_shipping_label_count'] ++;
}
if ( ! empty( $flexible_shipping_rate[ WPDesk_Flexible_Shipping::SETTING_METHOD_FREE_SHIPPING_NOTICE ] )
&& 'yes' === $flexible_shipping_rate[ WPDesk_Flexible_Shipping::SETTING_METHOD_FREE_SHIPPING_NOTICE ]
) {
$data['flexible_shipping']['free_shipping_cart_notice_count'] ++;
}
if ( ! empty( $flexible_shipping_rate['method_max_cost'] ) ) {
$data['flexible_shipping']['max_cost_count'] ++;
}
if ( ! empty( $flexible_shipping_rate['method_visibility'] ) && 'no' !== $flexible_shipping_rate['method_visibility'] ) {
$data['flexible_shipping']['visibility_count'] ++;
}
if ( ! empty( $flexible_shipping_rate['method_default'] ) && 'no' !== $flexible_shipping_rate['method_default'] ) {
$data['flexible_shipping']['default_count'] ++;
}
$data['flexible_shipping'] = apply_filters( 'flexible-shipping/tracker/method-settings', $data['flexible_shipping'], $flexible_shipping_rate );
foreach ( $flexible_shipping_rate['method_rules'] as $method_rule ) {
$rule_settings = new SingleRuleSettings( $method_rule );
$data['flexible_shipping'] = apply_filters( 'flexible-shipping/tracker/method-rule-data', $data['flexible_shipping'], $rule_settings->get_normalized_settings() );
}
}
if ( 0 !== (int) $data['flexible_shipping']['total_shipping_methods'] ) {
$data['flexible_shipping']['avg_rules'] = (float) $data['flexible_shipping']['avg_rules'] / (float) $data['flexible_shipping']['total_shipping_methods'];
}
return $data;
}
}
if ( ! function_exists( 'wpdesk_tracker_enabled' ) ) {
/**
* Disable tracker on localhost.
*
* @return bool
*/
function wpdesk_tracker_enabled() {
$tracker_enabled = true;
if ( ! empty( $_SERVER['SERVER_ADDR'] ) && '127.0.0.1' === $_SERVER['SERVER_ADDR'] ) {
$tracker_enabled = false;
}
return apply_filters( 'wpdesk_tracker_enabled', $tracker_enabled );
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Display contextual info script.
*
* @package Contextual Info.
*
* @var $html_elements_ids string
* @var $info_id string
* @var $phrases_in string[]
* @var $info_html string
* @var $phrases_not_in string[]
*/
?>
<script type="text/javascript">
jQuery( document ).ready(
function () {
jQuery( "<?php echo esc_attr( $html_elements_ids ); ?>" ).contextualInfo(
{
'id': '<?php echo esc_attr( $info_id ); ?>',
'phrases_in': <?php echo json_encode( $phrases_in ); // phpcs:ignore ?>,
'info_html': <?php echo json_encode( $info_html ); // phpcs:ignore ?>,
'phrases_not_in': <?php echo json_encode( $phrases_not_in ); // phpcs:ignore ?>,
'is_limited_width': <?php echo wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) && wpdesk_is_plugin_active( 'flexible-shipping-import-export/flexible-shipping-import-export.php' ) ? 'false' : 'true'; ?>
}
);
}
);
</script>

View File

@@ -0,0 +1,120 @@
<?php
/**
* Deactivation thickbox.
*
* @var $plugin_title string
* @var $plugin_file string
* @var $plugin_slug string
* @var $thickbox_id string
* @var $ajax_action string
* @var $ajax_nonce string
*
* @package Flexible Shipping
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="<?php echo esc_attr( $thickbox_id ); ?>" style="display:none;">
<h2>
<?php
echo esc_html(
sprintf(
// Translators: plugin name.
__( 'You are deactivating %s plugin.', 'flexible-shipping' ),
$plugin_title
)
);
?>
</h2>
<div class="wpdesk_tracker_deactivate <?php echo esc_attr( $thickbox_id ); ?>">
<div class="body">
<div class="panel" data-panel-id="confirm"><p></p></div>
<div class="panel active" data-panel-id="reasons">
<h4>
<strong><?php echo esc_html( __( 'If you have a moment, please let us know why you are deactivating the plugin (anonymous feedback):', 'flexible-shipping' ) ); ?></strong>
</h4>
<ul class="reasons-list">
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="plugin_stopped_working">
</span>
<span><?php echo esc_html( __( 'The plugin suddenly stopped working', 'flexible-shipping' ) ); ?></span>
</label>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="broke_my_site">
</span>
<span><?php echo esc_html( __( 'The plugin broke my site', 'flexible-shipping' ) ); ?></span>
</label>
</li>
<li class="reason has-input">
<label>
<span>
<input type="radio" name="selected-reason" value="dont_like_rules_table" data-show="dont-like-rules-table">
</span>
<span><?php echo esc_html( __( 'I don\'t like the new version of the rules table', 'flexible-shipping' ) ); ?></span>
</label>
<div class="dont-like-rules-table" class="reason-input" style="display: none">
<input type="text" class="additional-info" name="dont_like_rules_table_info" placeholder="<?php echo esc_html( __( 'Please let us know how we can improve it', 'flexible-shipping' ) ); ?>">
</div>
</li>
<li class="reason has-input">
<label>
<span>
<input type="radio" name="selected-reason" value="found_better_plugin" data-show="found-better-plugin">
</span>
<span><?php echo esc_html( __( 'I have found a better plugin', 'flexible-shipping' ) ); ?></span>
</label>
<div class="found-better-plugin" class="reason-input" style="display: none">
<input type="text" class="additional-info" name="better_plugin_name" placeholder="<?php echo esc_html( __( 'What\'s the plugin\'s name?', 'flexible-shipping' ) ); ?>">
</div>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="plugin_for_short_period">
</span>
<span><?php echo esc_html( __( 'I only needed the plugin for a short period', 'flexible-shipping' ) ); ?></span>
</label>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="no_longer_need">
</span>
<span><?php echo esc_html( __( 'I no longer need the plugin', 'flexible-shipping' ) ); ?></span>
</label>
</li>
<li class="reason">
<label>
<span>
<input type="radio" name="selected-reason" value="temporary_deactivation">
</span>
<span><?php echo esc_html( __( 'It\'s a temporary deactivation. I\'m just debugging an issue.', 'flexible-shipping' ) ); ?></span>
</label>
</li>
<li class="reason has-input">
<label>
<span>
<input type="radio" name="selected-reason" value="other" data-show="other">
</span>
<span><?php echo esc_html( __( 'Other', 'flexible-shipping' ) ); ?></span>
</label>
<div class="other" class="reason-input" style="display: none">
<input type="text" name="other" class="additional-info" placeholder="<?php echo esc_html( __( 'Please let us know how we can improve our plugin', 'flexible-shipping' ) ); ?>">
</div>
</li>
</ul>
</div>
</div>
<div class="footer">
<a href="#" class="button button-secondary button-close tracker-button-close"><?php echo esc_html( __( 'Cancel', 'flexible-shipping' ) ); ?></a>
<a href="#" class="button button-primary button-deactivate allow-deactivate"><?php echo esc_html( __( 'Skip &amp; Deactivate', 'flexible-shipping' ) ); ?></a>
</div>
</div>
</div>

View File

@@ -0,0 +1,74 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Shipment_Ajax' ) ) {
class WPDesk_Flexible_Shipping_Shipment_Ajax {
private $plugin = null;
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
public function hooks() {
add_action( 'wp_ajax_flexible_shipping', array( $this, 'wp_ajax_flexible_shipping' ) );
}
public function wp_ajax_flexible_shipping() {
$json = array('status' => 'fail');
$json['message'] = __( 'Unknown error!', 'flexible-shipping' );
if ( empty( $_REQUEST['nonce'] ) || !wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'flexible_shipping_shipment_nonce' ) ) {
$json['status'] = 'fail';
$json['message'] = __( 'Nonce verification error! Invalid request.', 'flexible-shipping' );
}
else if ( empty( $_REQUEST['shipment_id'] ) ) {
$json['status'] = 'fail';
$json['message'] = __( 'No shipment id!', 'flexible-shipping' );
}
else if ( empty( $_REQUEST['data'] ) || !is_array( $_REQUEST['data'] ) ) {
$json['status'] = 'fail';
$json['message'] = __( 'No data!', 'flexible-shipping' );
}
else {
$shipment = fs_get_shipment( intval( $_REQUEST['shipment_id'] ) );
$action = sanitize_key( $_REQUEST['fs_action'] );
$data = $_REQUEST['data'];
try {
$ajax_request = $shipment->ajax_request( $action, $data );
if ( is_array( $ajax_request ) ) {
$json['content'] = $ajax_request['content'];
$json['message'] = '';
if ( isset( $ajax_request['message'] ) ) {
$json['message'] = $ajax_request['message'];
}
}
else {
$json['content'] = $ajax_request;
$json['message'] = '';
if ( $action == 'save' ) {
$json['message'] = __( 'Saved', 'flexible-shipping' );
}
if ( $action == 'send' ) {
$json['message'] = __( 'Created', 'flexible-shipping' );
}
}
$json['status'] = 'success';
if ( ! empty( $ajax_request['status'] ) ) {
$json['status'] = $ajax_request['status'];
}
}
catch ( Exception $e ) {
$json['status'] = 'fail';
$json['message'] = $e->getMessage();
}
}
echo json_encode($json);
die;
}
}
}