first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

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://wpde.sk/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,65 @@
<?php
namespace WPDesk\FS\Rate;
class FirstRateNotice extends RateNotice
{
const SETTINGS_VARIANT_ID = 'notice_1';
/**
* 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://wpde.sk/fs-rate-1' ) . '">',
'</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. May I ask you to give it a 5-star rating on WordPress?', 'flexible-shipping' );
$message .= '<br/>';
$message .= implode( ' | ', $this->action_links() );
return $message;
}
}

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,53 @@
<?php
namespace WPDesk\FS\Rate;
/**
* Counts orders with FS shipping method.
*/
class Flexible_Shipping_Order_Counter implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
const ORDER_STATUS_COMPLETED = 'completed';
const FS_ORDER_COUNTER = 'flexible_shipping_rate_notice_counter';
const FS_METHOD = 'flexible_shipping';
/**
* Hooks.
*/
public function hooks() {
add_action( 'woocommerce_order_status_changed', array( $this, 'count_order_for_fs_methods' ), 10, 4 );
}
/**
* Count order.
*
* @param WC_Order $order .
*/
private function count_order( $order ) {
update_option( self::FS_ORDER_COUNTER, intval( get_option( self::FS_ORDER_COUNTER, '0' ) ) + 1 );
$order->update_meta_data( self::FS_ORDER_COUNTER, 1 );
$order->save();
}
/**
* Count orders for FS methods.
*
* @param int $order_id Order ID.
* @param string $status_from Status from.
* @param string $status_to Status to.
* @param WC_Order $order Order.
*/
public function count_order_for_fs_methods( $order_id, $status_from, $status_to, $order ) {
if ( self::ORDER_STATUS_COMPLETED === $status_to ) {
$shipping_methods = $order->get_shipping_methods();
foreach ( $shipping_methods as $shipping_method ) {
if ( self::FS_METHOD === $shipping_method->get_method_id() ) {
if ( '' === $order->get_meta( self::FS_ORDER_COUNTER ) ) {
$this->count_order( $order );
}
}
}
}
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace WPDesk\FS\Rate;
class RateNoticeCreator {
const SETTINGS_RATE_NOTICE_VARIANT_ID = 'flexible_shipping_rate_notice_variant_id';
/**
* Create rate variant
*
* @param string $notice_id Variant ID.
*
* @return RateNoticeInterface;
*/
public function create( $variant ) {
switch( $variant ) {
case FirstRateNotice::SETTINGS_VARIANT_ID: return new FirstRateNotice(); break;
case SecondRateNotice::SETTINGS_VARIANT_ID: return new SecondRateNotice(); break;
case ThirdRateNotice::SETTINGS_VARIANT_ID: return new ThirdRateNotice(); break;
default: return new FirstRateNotice();
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace WPDesk\FS\Rate;
class SecondRateNotice extends RateNotice
{
const SETTINGS_VARIANT_ID = 'notice_2';
/**
* 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://wpde.sk/fs-rate-2' ) . '">',
'</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? ~ Peter', 'flexible-shipping' );
$message .= '<br/>';
$message .= implode( ' | ', $this->action_links() );
return $message;
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace WPDesk\FS\Rate;
class ThirdRateNotice extends RateNotice
{
const CLOSE_TEMPORARY_NOTICE = 'close-temporary-notice-number';
const SETTINGS_VARIANT_ID = 'notice_3';
/**
* 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://wpde.sk/fs-rate-3' ) . '">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sNope, maybe later%2$s', 'flexible-shipping' ),
'<a data-type="number" 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() {
$total_orders = intval( get_option( Flexible_Shipping_Order_Counter::FS_ORDER_COUNTER, '0' ) );
if ( $total_orders >= 100 ) {
return true;
}
return false;
}
/**
* Get rate message
*
* @return string
*/
protected function get_message() {
$message = __( 'Awesome, you just crossed the 100 orders on Flexible Shipping method. Could you please do me a BIG favor and give it a 5-star rating on WordPress? ~ Peter', 'flexible-shipping' );
$message .= '<br/>';
$message .= implode( ' | ', $this->action_links() );
return $message;
}
}