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,6 @@
[![pipeline status](https://gitlab.com/wpdesk/flexible-shipping/badges/master/pipeline.svg)](https://gitlab.com/wpdesk/flexible-shipping/commits/master)
Integration: [![coverage report](https://gitlab.com/wpdesk/flexible-shipping/badges/master/coverage.svg?job=integration+test+lastest+coverage)](https://gitlab.com/wpdesk/flexible-shipping/commits/master)
Unit [![coverage report](https://gitlab.com/wpdesk/flexible-shipping/badges/master/coverage.svg?job=unit+test+lastest+coverage)](https://gitlab.com/wpdesk/flexible-shipping/commits/master)
Flexible Shipping Plugin
========================

View File

@@ -0,0 +1,734 @@
/* Shipping Methods Table */
table.flexible_shipping_methods th.select,
table.flexible_shipping_methods td.select {
text-align: center;
width: 40px;
margin-top: -7px;
margin-left: -6px;
padding: 2px;
}
table.flexible_shipping_methods .checkbox-select-all {
margin: 0 12px 0 8px;
}
table.flexible_shipping_methods th.integration,
table.flexible_shipping_methods td.integration {
text-align: center;
width: 130px;
}
table.flexible_shipping_methods tr.highlight td {
background-color: #e4f2fd;
}
table.flexible_shipping_methods.wc_shipping th {
font-weight: 400;
width: auto;
}
table.flexible_shipping_methods td.ui-sortable-handle:before, table.flexible_shipping_services td.ui-sortable-handle:before {
content: '\f333';
font-family: Dashicons;
text-align: center;
line-height: 1;
color: #999;
display: block;
width: 17px;
float: left;
height: 100%;
line-height: 24px;
}
/* Rules Table */
table.flexible_shipping_method_rules th, table.flexible_shipping_method_rules th {
padding: 5px 10px 5px 0px;
}
table.flexible_shipping_method_rules td p,
table.flexible_shipping_method_rules td p input,
table.flexible_shipping_method_rules td p select {
margin: 0;
width: 100%;
box-shadow: none;
padding: 0px!important;
}
table.flexible_shipping_method_rules td p input[type=text] {
text-align: right;
padding: 0px 5px 0px 5px!important;
width: 100%!important;
}
table.flexible_shipping_method_rules td p select {
margin: 0;
width: 100%!important;
box-shadow: none;
line-height: 28px;
height: 37px;
vertical-align: middle;;
}
table.flexible_shipping_method_rules td p input[type=checkbox] {
margin: 0;
width: auto;
}
table.flexible_shipping_method_rules th,
table.flexible_shipping_method_rules td {
text-align: center;
}
table.flexible_shipping_method_rules th.shipping_class,
table.flexible_shipping_method_rules td.shipping_class {
text-align: center;
width: 200px;
}
table.flexible_shipping_method_rules td.shipping_class span {
border:none;
}
table.flexible_shipping_method_rules th.stop,
table.flexible_shipping_method_rules td.stop {
text-align: center;
width: 30px;
}
table.flexible_shipping_method_rules th.cancel,
table.flexible_shipping_method_rules td.cancel {
text-align: center;
width: 60px;
}
.woocommerce table.form-table .flexible_shipping_method_rules th span.woocommerce-help-tip {
float: none;
margin: 0px;
}
.woocommerce table.form-table .flexible_shipping_method_rules .select2-container {
margin: 0;
}
/* Locations Add-On */
.woocommerce table.form-table .fs-locations-table .select2-container {
max-width: none;
}
.woocommerce table.form-table .fs-locations-table th .woocommerce-help-tip {
float: none;
}
div.flexilble_shipping_export_import {
float:right;
}
table.flexible_shipping_method_rules tfoot th {
padding: 10px;
}
.fs_shipping_class {
/*width: 300px!important;*/
}
/* Ads */
.woocommerce_page_wc-settings #mainform {
position: relative;
}
.flexible-shipping-pro-box {
max-width: 280px;
min-width: 180px;
right: 0;
position: absolute;
top: 135px;
}
@media screen and (max-width: 1199px) {
.flexible-shipping-pro-box {
display: none;
}
}
/* Flexible Shipping Column - Orders List */
.column-flexible_shipping {
width: 130px;
}
.column-flexible_shipping .shipping-status {
float: left;
margin-right: 8px;
margin-top: 4px;
text-align: left;
width: 18px;
}
.column-flexible_shipping .shipping-status .created:after {
color: #d0c21f !important;
}
.column-flexible_shipping .shipping-actions a.button {
float: left;
margin: 0 4px 2px 0;
display: block;
height: 2em !important;
padding: 0 !important;
position: relative;
text-indent: -9999px;
width: 2em;
}
.column-flexible_shipping .shipping-actions a.button:after {
font-family: WooCommerce;
font-variant: normal;
font-weight: 400;
height: 100%;
left: 0;
line-height: 1.85;
margin: 0;
position: absolute;
text-align: center;
text-indent: 0;
text-transform: none;
top: 0;
width: 100%;
}
.column-flexible_shipping .shipping-actions a.button.get-label:after {
content: "\e01e";
}
.column-flexible_shipping .shipping-actions a.button.track:after {
content: "\e01b";
}
.column-flexible_shipping mark.failed:after {
color: #a00 !important;
}
.column-flexible_shipping mark.manifest:after {
color: #2ea2cc !important;
}
.flexible_shipping_shipment_message {
color: green;
}
.flexible_shipping_shipment_message_error {
color: #a00 !important;
}
.flexible_shipping_shipment_message_error span {
color: #444;
font-weight: bold;
}
/** select */
.woocommerce .wp-admin select {
height: 100%;
}
/** flexible printing integration */
.button.flexible-printing-button-print {
height: auto !important;
white-space: normal !important;;
word-wrap: break-word !important;;
}
/* Info Page */
.inspire-settings {
display: table;
width: 100%;
}
.inspire-settings .inspire-main-content,
.inspire-settings .inspire-sidebar {
display: table-cell;
height: 500px;
margin: 0;
padding: 0;
vertical-align: top;
}
.inspire-settings .inspire-main-content {
min-width: 800px;
}
.inspire-settings .inspire-sidebar {
padding-left: 30px;
width: 250px;
}
.flexible-shipping-info ol {
margin-top: 0;
}
#wpbody-content .flexible-shipping-info .metabox-holder {
padding-top: 0;
}
/* menu */
#adminmenu #toplevel_page_flexible-shipping .menu-icon-generic div.wp-menu-image::before {
font-family: WooCommerce!important;
content: '\e01d';
}
/* Flexible shipping settings */
.fs-new-service {
color: #006799;
}
/* Order shipping */
.fs-order-item-fallback {
margin-top: .5em;
color: #888;
}
/* order metabox */
.flexible_shipping_shipment_content p select {
max-width: 95%;
}
.flexible_shipping_shipment_content span.description {
display: block;
}
.fs-saas-button-cancel-created {
float: right;
color: #a00;
margin-top: 5px;
}
.fs-saas-button-cancel-created:hover {
color: #a00;
cursor: pointer;
}
.flexible_shipping_shipment_content input[type=checkbox] {
float: left;
margin-right: 5px;
margin-top: 2px !important;
opacity: 1;
border-color: #888;
}
.flexible_shipping_shipment_content input[type=checkbox]:disabled {
opacity: 0.7;
border-color: rgba( 51, 51, 51, 0.5 );
}
.flexible_shipping_shipment_content p.fs-saas-status {
}
.flexible_shipping_shipment_content p.fs-saas-status span {
font-weight: bold;
color: #444;
}
.flexible_shipping_shipment_content p.fs-saas-status-fs-new {
color: #ffba00;
}
.flexible_shipping_shipment_content p.fs-saas-status-fs-created {
color: #d0c21f;
}
.flexible_shipping_shipment_content p.fs-saas-status-fs-confirmed {
color: #444;
}
.flexible_shipping_shipment_content p.fs-saas-status-fs-failed {
color: #a00;
}
.flexible_shipping_shipment_content p.fs-saas-status-fs-manifest {
color: #2ea2cc;
}
.flexible_shipping_shipment_content p.connection-error {
font-weight: bold;
color: #a00;
}
.fs-saas-shipment span {
font-weight: bold;
}
.fs-saas-charges span {
}
.fs-saas-labels-counts span {
font-weight: bold;
}
.fs-saas-no-labels-left {
color: #a00;
}
div.flexible-shipping-shipment-attachments p {
display: inline;
}
.flexible_shipping_shipment_attachment_message {
padding-top: 10px;
color: green;
}
table.flexible_shipping_services {
max-width: 550px;
}
table.flexible_shipping_services .sort {
width: 1%;
}
table.flexible_shipping_services .service_code {
width: 30px;
}
table.flexible_shipping_services .select {
text-align: center;
width: 1%;
}
table.flexible_shipping_services .select input {
margin: 0 8px 0 8px;
}
.woocommerce table.form-table table.flexible_shipping_services td.service_name input {
width: 100%;
}
input.woocommerce_flexible_shipping_service_name {
width: 100%;
}
/* Connect Global Notice */
.updated .fs-banner__button-container {
padding: 0.75rem 0 0;
}
.notice-info.fs-connect__container {
border-left: none;
padding: 0;
box-shadow: 0 0 0 1px #dfdfdf, 0 1px 2px #dfdfdf;
}
@media screen and (max-width: 782px) {
.notice-info.fs-connect__container {
padding: 0 !important;
}
}
.fs-connect__container {
display: block;
position: relative;
box-sizing: border-box;
}
.fs-connect__inner-container > a:first-child {
z-index: 1;
}
.fs-connect__inner-container {
display: -ms-flexbox;
display: flex;
-ms-flex-direction: row;
flex-direction: row;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-ms-flex-pack: left;
justify-content: left;
}
.fs-connect__content-container {
width: 1250px;
position: relative;
padding: 2rem;
z-index: 0;
}
@media (min-width: 782px) {
.fs-connect__content-container {
padding: 2rem 2rem 4rem 2rem;
}
}
.fs-connect__content-container p {
color: #555;
font-size: 0.875rem;
}
.fs-connect__content-container h2 {
margin-top: 0;
color: #555;
line-height: 1.6;
}
.fs-connect__content-icon {
float: right;
margin: 0 1.5rem 0 2.25rem;
}
.fs-connect__content-icon svg {
fill: #0085ba;
height: 180px;
width: auto;
}
@media (max-width: 782px) {
.fs-connect__content-icon.fs-connect-illo {
float: none;
width: 100%;
text-align: center;
margin: 2.25rem 0 1.5rem;
}
}
.fs-connect__slide {
display: none;
}
.fs-connect__slide.fs__slide-is-active {
display: block;
}
@media (min-width: 782px) {
.fs-connect__content-container .fs-banner__button-container {
position: absolute;
bottom: 0.5rem;
}
}
.fs-banner__button-container .button-primary {
margin: 0 0.3125rem 0.3125rem 0;
}
.fs-connect__vertical-nav {
background-color: #f1f1f1;
}
@media (min-width: 600px) {
.fs-connect__vertical-nav {
-ms-flex-direction: column;
flex-direction: column;
-ms-flex-pack: start;
justify-content: flex-start;
}
}
@media (max-width: 600px) {
.fs-connect__vertical-nav {
display: none;
}
}
.fs-connect__vertical-nav-container {
width: 15rem;
}
.vertical-menu__feature-item-label {
display: none;
}
@media (min-width: 600px) {
.vertical-menu__feature-item {
display: -ms-flexbox;
display: flex;
-ms-flex-direction: row;
flex-direction: row;
-ms-flex-align: center;
align-items: center;
border: none;
padding: 0.5rem;
border-bottom: 1px solid #dfdfdf;
border-right: 1px solid #dfdfdf;
border-left: 3px solid #f9f9f9;
background-color: #f9f9f9;
color: #555;
cursor: pointer;
}
.vertical-menu__feature-item:last-of-type {
position: relative;
top: 1px;
}
.vertical-menu__feature-item-is-selected {
border-left: 3px solid #0085ba;
border-right: 1px solid #fff;
background-color: #fff;
color: #2e4453;
}
.vertical-menu__feature-item-is-selected.fs-feature-intro {
border-left: 3px solid #00BE28;
}
.vertical-menu__feature-item-icon {
width: 1.25rem;
height: 1.25rem;
padding: 0.25rem;
text-align: center;
}
.vertical-menu__feature-item svg {
fill: #555;
vertical-align: middle;
}
.vertical-menu__feature-item-is-selected svg {
fill: #0085ba;
}
.vertical-menu__feature-item-label {
display: block;
padding: 0.5rem;
}
}
.fs-couriers {
margin-top: 2.5em;
}
.fs-courier {
position: relative;
margin-bottom: 2.5em;
text-align: center;
}
.fs-courier img {
height: 50px;
width: auto;
}
.fs-courier-label {
background-color: #333;
border-radius: 3px;
color: #fff;
padding: 0 4px 1px;
position: absolute;
right: 0;
top: -10px;
}
@media (min-width: 1200px) {
.fs-couriers {
align-items: center;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
}
.fs-courier {
width: 20%;
}
}
/* Connect Register */
.admin_page_flexible_shipping_connect_register .notice.is-dismissible,
.admin_page_flexible_shipping_connect_register .update-nag,
.admin_page_flexible_shipping_connect_register .updated,
.admin_page_flexible_shipping_connect_register .settings-error {
display: none !important;
}
.fs-page-wrap {
margin: 0 auto;
max-width: 45rem;
}
.fs-page-wrap h1 {
font-weight: normal;
margin-bottom: .67em;
text-align: center;
}
.fs-box {
display: block;
position: relative;
margin: 0 auto 20px;
padding: 16px;
box-sizing: border-box;
background: white;
box-shadow: 0 0 0 1px #dfdfdf, 0 1px 2px #dfdfdf;
}
.fs-box:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.admin_page_flexible_shipping_connect_register .fs-box,
.fs-box.text-center {
text-align: center;
}
.admin_page_flexible_shipping_connect_register .fs-box p {
margin: 1.5em 0;
}
.fs-box input[type="email"] {
padding: 8px 10px;
}
.fs-actions {
padding-left: 40px;
}
.fs-actions button:active {
vertical-align: inherit !important;
}
.fs-actions .spinner {
float: none;
margin-top: 0;
}
.fs-cols {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.fs-inner-box {
box-sizing: border-box;
margin-top: 30px;
padding: 0 20px;
}
.fs-inner-box h4 {
font-size: 1.2em;
margin-bottom: .37em;
}
.fs-inner-box svg {
fill: #0085ba;
height: 70px;
width: auto;
}
@media (min-width: 600px) {
.fs-inner-box {
width: 33.33%;
}
}
.fs-connect-box-header {
margin-top: 3em;
}
.hide-fs-connect-integration-box {
display: none;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
@font-face {
font-family: 'flexible-shipping';
src: url('../fonts/flexible-shipping.eot?imgwjn');
src: url('../fonts/flexible-shipping.eot?imgwjn#iefix') format('embedded-opentype'),
url('../fonts/flexible-shipping.ttf?imgwjn') format('truetype'),
url('../fonts/flexible-shipping.woff?imgwjn') format('woff'),
url('../fonts/flexible-shipping.svg?imgwjn#flexible-shipping') format('svg');
font-weight: normal;
font-style: normal;
}
div.shipping-status a.icon-status {
font-family: 'flexible-shipping' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
display: inline-block;
overflow: hidden;
text-indent: -9999px;
height: 2em!important;
width: 2em;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
div.shipping-status a.icon-status:before {
font-size: 20px;
float: left;
text-align: center;
background: transparent none;
margin: 0 0 0 5px;
text-indent: 0;
}
.icon-plus-circle:before, .icon-status-new:before {
color: #ffba00;
background: transparent none;
text-indent: 0;
content: "\f055";
}
.icon-check-circle:before, .icon-status-confirmed:before {
color: #2ea2cc;
content: "\f058";
}
.icon-exclamation-circle:before, .icon-status-error:before {
color: #d0c21f;
content: "\f06a";
}
.icon-truck:before {
content: "\f0d1";
}
.icon-pause-circle:before, .icon-status-created:before {
color: #999;
content: "\f28b";
}

View File

@@ -0,0 +1 @@
@font-face{font-family:'flexible-shipping';src:url('../fonts/flexible-shipping.eot?imgwjn');src:url('../fonts/flexible-shipping.eot?imgwjn#iefix') format('embedded-opentype'),url('../fonts/flexible-shipping.ttf?imgwjn') format('truetype'),url('../fonts/flexible-shipping.woff?imgwjn') format('woff'),url('../fonts/flexible-shipping.svg?imgwjn#flexible-shipping') format('svg');font-weight:normal;font-style:normal}div.shipping-status a.icon-status{font-family:'flexible-shipping' !important;speak:none;font-style:normal;font-weight:normal;font-variant:normal;text-transform:none;line-height:1;display:inline-block;overflow:hidden;text-indent:-9999px;height:2em !important;width:2em;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}div.shipping-status a.icon-status:before{font-size:20px;float:left;text-align:center;background:transparent none;margin:0 0 0 5px;text-indent:0}.icon-plus-circle:before,.icon-status-new:before{color:#ffba00;background:transparent none;text-indent:0;content:"\f055"}.icon-check-circle:before,.icon-status-confirmed:before{color:#2ea2cc;content:"\f058"}.icon-exclamation-circle:before,.icon-status-error:before{color:#d0c21f;content:"\f06a"}.icon-truck:before{content:"\f0d1"}.icon-pause-circle:before,.icon-status-created:before{color:#999;content:"\f28b"}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Generated by IcoMoon</metadata>
<defs>
<font id="flexible-shipping" horiz-adv-x="1024">
<font-face units-per-em="1024" ascent="960" descent="-64" />
<missing-glyph horiz-adv-x="1024" />
<glyph unicode="&#x20;" horiz-adv-x="512" d="" />
<glyph unicode="&#xf055;" glyph-name="plus-circle" horiz-adv-x="878" d="M694.857 402.286v73.143c0 20-16.571 36.571-36.571 36.571h-146.286v146.286c0 20-16.571 36.571-36.571 36.571h-73.143c-20 0-36.571-16.571-36.571-36.571v-146.286h-146.286c-20 0-36.571-16.571-36.571-36.571v-73.143c0-20 16.571-36.571 36.571-36.571h146.286v-146.286c0-20 16.571-36.571 36.571-36.571h73.143c20 0 36.571 16.571 36.571 36.571v146.286h146.286c20 0 36.571 16.571 36.571 36.571zM877.714 438.857c0-242.286-196.571-438.857-438.857-438.857s-438.857 196.571-438.857 438.857 196.571 438.857 438.857 438.857 438.857-196.571 438.857-438.857z" />
<glyph unicode="&#xf058;" glyph-name="check-circle" horiz-adv-x="878" d="M733.714 531.428c0 9.714-3.429 19.429-10.286 26.286l-52 51.429c-6.857 6.857-16 10.857-25.714 10.857s-18.857-4-25.714-10.857l-233.143-232.571-129.143 129.143c-6.857 6.857-16 10.857-25.714 10.857s-18.857-4-25.714-10.857l-52-51.429c-6.857-6.857-10.286-16.571-10.286-26.286s3.429-18.857 10.286-25.714l206.857-206.857c6.857-6.857 16.571-10.857 25.714-10.857 9.714 0 19.429 4 26.286 10.857l310.286 310.286c6.857 6.857 10.286 16 10.286 25.714zM877.714 438.857c0-242.286-196.571-438.857-438.857-438.857s-438.857 196.571-438.857 438.857 196.571 438.857 438.857 438.857 438.857-196.571 438.857-438.857z" />
<glyph unicode="&#xf06a;" glyph-name="exclamation-circle" horiz-adv-x="878" d="M438.857 877.714c242.286 0 438.857-196.571 438.857-438.857s-196.571-438.857-438.857-438.857-438.857 196.571-438.857 438.857 196.571 438.857 438.857 438.857zM512 165.143v108.571c0 10.286-8 18.857-17.714 18.857h-109.714c-10.286 0-18.857-8.571-18.857-18.857v-108.571c0-10.286 8.571-18.857 18.857-18.857h109.714c9.714 0 17.714 8.571 17.714 18.857zM510.857 361.714l10.286 354.857c0 4-1.714 8-5.714 10.286-3.429 2.857-8.571 4.571-13.714 4.571h-125.714c-5.143 0-10.286-1.714-13.714-4.571-4-2.286-5.714-6.286-5.714-10.286l9.714-354.857c0-8 8.571-14.286 19.429-14.286h105.714c10.286 0 18.857 6.286 19.429 14.286z" />
<glyph unicode="&#xf0d1;" glyph-name="truck" horiz-adv-x="1061" d="M365.714 146.286c0 40-33.143 73.143-73.143 73.143s-73.143-33.143-73.143-73.143 33.143-73.143 73.143-73.143 73.143 33.143 73.143 73.143zM146.286 438.857h219.429v146.286h-90.286c-2.286 0-10.857-3.429-12.571-5.143l-111.429-111.429c-1.714-1.714-5.143-10.286-5.143-12.571v-17.143zM877.714 146.286c0 40-33.143 73.143-73.143 73.143s-73.143-33.143-73.143-73.143 33.143-73.143 73.143-73.143 73.143 33.143 73.143 73.143zM1024 768v-585.143c0-42.286-44.571-36.571-73.143-36.571 0-80.571-65.714-146.286-146.286-146.286s-146.286 65.714-146.286 146.286h-219.429c0-80.571-65.714-146.286-146.286-146.286s-146.286 65.714-146.286 146.286h-36.571c-28.571 0-73.143-5.714-73.143 36.571 0 20 16.571 36.571 36.571 36.571v182.857c0 40.571-5.714 85.714 25.714 117.143l113.143 113.143c14.286 14.286 41.714 25.714 62.286 25.714h91.429v109.714c0 20 16.571 36.571 36.571 36.571h585.143c20 0 36.571-16.571 36.571-36.571z" />
<glyph unicode="&#xf28b;" glyph-name="pause-circle" horiz-adv-x="878" d="M402.286 274.286v329.143c0 10.286-8 18.286-18.286 18.286h-146.286c-10.286 0-18.286-8-18.286-18.286v-329.143c0-10.286 8-18.286 18.286-18.286h146.286c10.286 0 18.286 8 18.286 18.286zM658.286 274.286v329.143c0 10.286-8 18.286-18.286 18.286h-146.286c-10.286 0-18.286-8-18.286-18.286v-329.143c0-10.286 8-18.286 18.286-18.286h146.286c10.286 0 18.286 8 18.286 18.286zM877.714 438.857c0-242.286-196.571-438.857-438.857-438.857s-438.857 196.571-438.857 438.857 196.571 438.857 438.857 438.857 438.857-196.571 438.857-438.857z" />
</font></defs></svg>

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@@ -0,0 +1,257 @@
function fs_select2() {
let elements = jQuery( '.fs_select2' );
if ( elements.length ) {
if (jQuery.fn.selectWoo) {
elements.selectWoo();
} else {
elements.select2();
}
}
}
jQuery(document).ready(function(){
if ( jQuery('#flexible_shipping_labels_url').length ) {
window.location.href = jQuery('#flexible_shipping_labels_url').attr('href');
}
if ( jQuery('a.shipping_manifest_download').length == 1 ) {
window.location.href = jQuery('a.shipping_manifest_download').attr('href');
}
if ( typeof window.history.pushState == 'function' ) {
var url = document.location.href;
var url2 = document.location.href;
url = fs_removeParam('bulk_flexible_shipping_labels', url);
url = fs_removeParam('bulk_flexible_shipping_send', url);
url = fs_removeParam('bulk_flexible_shipping_manifests', url);
url = fs_removeParam('bulk_flexible_shipping_no_labels_created', url);
url = fs_trimChar(url,'?');
if ( url != url2 ) {
window.history.pushState({}, "", url);
}
}
/* Connect Global Notice */
var nav = jQuery( '.fs-connect__vertical-nav-container' ),
contentContainer = jQuery( '.fs-connect__content-container' );
nextFeatureButtons = jQuery( '.fs-banner__button-container .next-feature' ),
nav.on( 'click', '.vertical-menu__feature-item:not( .vertical-menu__feature-item-is-selected )', function() {
transitionSlideToIndex( jQuery( this ).index() );
} );
nextFeatureButtons.on( 'click', function( e ) {
e.preventDefault();
var slideIndex = jQuery( this )
.closest( '.fs-connect__slide' )
.index();
transitionSlideToIndex( slideIndex + 1 );
} );
function transitionSlideToIndex( index ) {
// Remove classes from previously selected menu item and content
nav
.find( '.vertical-menu__feature-item-is-selected' )
.removeClass( 'vertical-menu__feature-item-is-selected' );
contentContainer
.find( '.fs__slide-is-active' )
.removeClass( 'fs__slide-is-active' );
// Add classes to selected menu item and content
nav
.children()
.eq( index )
.addClass( 'vertical-menu__feature-item-is-selected' );
contentContainer
.children()
.eq( index )
.addClass( 'fs__slide-is-active' );
}
});
function fs_removeParam(key, sourceURL) {
var rtn = sourceURL.split("?")[0],
param,
params_arr = [],
queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
if (queryString !== "") {
params_arr = queryString.split("&");
for (var i = params_arr.length - 1; i >= 0; i -= 1) {
param = params_arr[i].split("=")[0];
if (param === key) {
params_arr.splice(i, 1);
}
}
rtn = rtn + "?" + params_arr.join("&");
}
return rtn;
}
function fs_trimChar(string, charToRemove) {
while(string.charAt(0)==charToRemove) {
string = string.substring(1);
}
while(string.charAt(string.length-1)==charToRemove) {
string = string.substring(0,string.length-1);
}
return string;
}
// Order functions
function fs_id( element ) {
return jQuery(element).closest('.flexible_shipping_shipment').attr('data-id');
}
function fs_data_set_val( data, name, val ) {
if ( typeof name == 'undefined' ) {
return data;
}
if ( name.indexOf("[") == -1 ) {
data[name] = val;
}
else {
var names = name.split("[");
var data2 = data;
var data3 = data;
var name2 = '';
jQuery.each(names,function(index,name) {
name2 = name.replace("]","");
if ( typeof data2[name2] == 'undefined' ) {
data2[name2] = {};
}
data3 = data2;
data2 = data2[name2];
});
data3[name2] = val;
}
return data;
}
function fs_ajax(button, id, fs_action) {
jQuery('.button-shipping').attr('disabled', true);
jQuery(button).parent().find('.spinner').css({visibility: 'visible'});
var data = {};
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_content input, #flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_content select, #flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_content textarea').each(function () {
if (jQuery(this).attr('type') == 'radio') {
data = fs_data_set_val( data, jQuery(this).attr('name'), jQuery('#flexible_shipping_shipment_' + id + ' input[name=' + jQuery(this).attr('name') + ']:checked').val() );
}
else if (jQuery(this).attr('type') == 'checkbox') {
if (jQuery(this).is(':checked')) {
data = fs_data_set_val( data, jQuery(this).attr('name'), jQuery(this).val() );
}
else {
data = fs_data_set_val( data, jQuery(this).attr('name'), '' );
}
}
else {
data = fs_data_set_val( data, jQuery(this).attr('name'), jQuery(this).val() );
}
});
var nonce = jQuery('#flexible_shipping_shipment_nonce_' + id).val();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').hide();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').removeClass("flexible_shipping_shipment_message_error");
jQuery.ajax({
url: fs_admin.ajax_url,
type: 'POST',
data: {
fs_action: fs_action,
action: 'flexible_shipping',
nonce: nonce,
shipment_id: id,
data: data,
},
dataType: 'json',
}).done(function (response) {
if (response) {
if (response == '0') {
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').show();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').html("Invalid response: 0");
}
else if (response.status == 'success') {
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_content').html(response.content);
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').hide();
if ( typeof response.message != 'undefined' ) {
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').show();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').html(response.message);
}
}
else {
if ( typeof response.content !== 'undefined' ) {
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_content').html(response.content);
}
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').addClass("flexible_shipping_shipment_message_error");
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').show();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').html(response.message);
}
}
else {
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').addClass("flexible_shipping_shipment_message_error");
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').show();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').html("Request failed: invalid method?");
}
}).always(function () {
jQuery('.button-shipping').attr('disabled', false);
jQuery('.shipping-spinner').parent().find('.spinner').css({visibility: 'hidden'});
fs_select2();
}).fail(function (jqXHR, textStatus) {
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').addClass("flexible_shipping_shipment_message_error");
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').show();
jQuery('#flexible_shipping_shipment_' + id + ' .flexible_shipping_shipment_message').html("Request failed: " + textStatus + " " + jqXHR.status);
})
}
/* Notice */
jQuery(function($) {
$( document ).on( 'click', '.flexible-shipping-taxes-notice .notice-dismiss', function () {
$.ajax( ajaxurl,
{
type: 'POST',
data: {
action: 'flexible_shipping_taxes_notice',
}
} );
} );
$( document ).on( 'click', '#enable-fs-connect-box', function () {
var fs_connect_checkbox = $('.enable-fs-connect-box');
var fs_box_state;
if ( fs_connect_checkbox.prop('checked') ){
$('.fs-connect-integration-box').slideDown();
fs_box_state = 1;
} else{
$('.fs-connect-integration-box').slideUp();
fs_box_state = 0;
}
$.ajax( ajaxurl,
{
type: 'POST',
data: {
action: 'update_fs_connect_integration_setting',
fs_box_state: fs_box_state
}
} );
} );
$( document ).on( 'click', '#flexible_shipping_rate_plugin .close-fs-rate-notice', function () {
$( '#flexible_shipping_rate_plugin .notice-dismiss' ).click();
} );
$( document ).on( 'click', '#flexible_shipping_rate_plugin .fs-not-good', function () {
$('#flexible_shipping_rate_plugin p').html( fs_admin.notice_not_good_enought );
} );
});

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,61 @@
/**
* Conditional Logic for Access Point
*
* @param field_name
* @param shipment_id
* @param conditions
* @constructor
*/
function ApConditionalLogic(field_name, shipment_id, conditions) {
this.field_name = field_name;
this.shipment_id = shipment_id;
this.conditions = conditions;
this.field_id = '#' + this.field_name + '_' + this.shipment_id;
this.field_id = this.createFieldId( this.field_name, this.shipment_id );
let conditional_logic = this;
this.conditions.forEach(function(value){
jQuery( conditional_logic.createFieldId( value.field, shipment_id ) ).on('change', function(event) {
conditional_logic.doLogic(event)
});
});
jQuery(document).ready(function(event) { conditional_logic.doLogic(event) });
}
/**
* Create field id from field name and shipment id;
*
* @param field_name
* @param shipment_id
* @return {string}
*/
ApConditionalLogic.prototype.createFieldId = function( field_name, shipment_id ) {
return '#' + field_name + '_' + shipment_id;
};
/**
* Do logic.
*
* @param event
*/
ApConditionalLogic.prototype.doLogic = function(event) {
let show_field = true;
let field_id = this.field_id;
let shipment_id = this.shipment_id;
let ap_conditional_logic = this;
this.conditions.forEach(function(condition) {
let cond_value = false;
if ( condition.cond === 'in' && condition.values.indexOf( jQuery( ap_conditional_logic.createFieldId( condition.field, shipment_id ) ).val() ) !== -1 ) {
cond_value = true;
}
show_field = show_field && cond_value;
});
var field_div = jQuery(field_id).closest('div');
if ( show_field ) {
field_div.show();
} else {
field_div.hide();
}
};

View File

@@ -0,0 +1 @@
function ApConditionalLogic(a,c,b){this.field_name=a;this.shipment_id=c;this.conditions=b;this.field_id="#"+this.field_name+"_"+this.shipment_id;this.field_id=this.createFieldId(this.field_name,this.shipment_id);let conditional_logic=this;this.conditions.forEach(function(d){jQuery(conditional_logic.createFieldId(d.field,c)).on("change",function(e){conditional_logic.doLogic(e)})});jQuery(document).ready(function(d){conditional_logic.doLogic(d)})}ApConditionalLogic.prototype.createFieldId=function(a,b){return"#"+a+"_"+b};ApConditionalLogic.prototype.doLogic=function(a){let show_field=true;let field_id=this.field_id;let shipment_id=this.shipment_id;let ap_conditional_logic=this;this.conditions.forEach(function(c){let cond_value=false;if(c.cond==="in"&&c.values.indexOf(jQuery(ap_conditional_logic.createFieldId(c.field,shipment_id)).val())!==-1){cond_value=true}show_field=show_field&&cond_value});var b=jQuery(field_id).closest("div");if(show_field){b.show()}else{b.hide()}};

View File

@@ -0,0 +1 @@
jQuery(document).on("change",".flexible-shipping-collection-point-select",function(){jQuery(document.body).trigger("update_checkout")});

View File

@@ -0,0 +1,58 @@
jQuery(document).ready(function () {
var window_map;
jQuery(document).on('click', '.flexible-shipping-collection-point-map-selector', function () {
var service_id = jQuery(this).attr('data-service-id');
var select_id = jQuery(this).attr('data-select-id');
var params = {
service_id: service_id,
select_id: select_id,
};
var y = window.top.outerHeight / 2 + window.top.screenY - (600 / 2);
var x = window.top.outerWidth / 2 + window.top.screenX - (800 / 2);
window_map = window.open(fs_collection_points_map.collection_points_map_url + '&' + jQuery.param(params), "", "width=800,height=600,top=" + y + ",left=" + x);
window.addEventListener('message', function (event) {
if (event.origin !== window.location.origin) {
return false;
}
if ('get_adresses_data' === event.data.action) {
send_adresses_data_to_map(window_map, service_id, select_id);
}
if (event.data.point_id && 'select_point' === event.data.action) {
update_point_from_map(event.data.point_id, select_id);
}
}, true);
return false;
});
function update_point_from_map(point_id, select_id) {
var point_select = jQuery('#' + select_id);
point_select.val(point_id);
point_select.trigger('change.select2');
jQuery(document.body).trigger('update_checkout');
}
function send_adresses_data_to_map(window_map, service_id, select_field_id) {
var data = {
different_addres: jQuery('#ship-to-different-address-checkbox').prop('checked'),
shipping_country: jQuery('#shipping_country').val(),
shipping_address_1: jQuery('#shipping_address_1').val(),
shipping_address_2: jQuery('#shipping_address_2').val(),
shipping_postcode: jQuery('#shipping_postcode').val(),
shipping_city: jQuery('#shipping_city').val(),
billing_country: jQuery('#billing_country').val(),
billing_address_1: jQuery('#billing_address_1').val(),
billing_address_2: jQuery('#billing_address_2').val(),
billing_postcode: jQuery('#billing_postcode').val(),
billing_city: jQuery('#billing_city').val(),
selected_point: jQuery('#' + select_field_id).val(),
action: 'fs_collection_points_' + service_id,
security: fs_collection_points_map.ajax_nonce
};
window_map.postMessage({addresses_data: data, action: 'send_address_data'}, window.location.origin);
}
})

View File

@@ -0,0 +1 @@
jQuery(document).ready(function(){var b;jQuery(document).on("click",".flexible-shipping-collection-point-map-selector",function(){var e=jQuery(this).attr("data-service-id");var h=jQuery(this).attr("data-select-id");var f={service_id:e,select_id:h};var g=window.top.outerHeight/2+window.top.screenY-(600/2);var d=window.top.outerWidth/2+window.top.screenX-(800/2);b=window.open(fs_collection_points_map.collection_points_map_url+"&"+jQuery.param(f),"","width=800,height=600,top="+g+",left="+d);window.addEventListener("message",function(i){if(i.origin!==window.location.origin){return false}if("get_adresses_data"===i.data.action){c(b,e,h)}if(i.data.point_id&&"select_point"===i.data.action){a(i.data.point_id,h)}},true);return false});function a(d,f){var e=jQuery("#"+f);e.val(d);e.trigger("change.select2");jQuery(document.body).trigger("update_checkout")}function c(d,f,e){var g={different_addres:jQuery("#ship-to-different-address-checkbox").prop("checked"),shipping_country:jQuery("#shipping_country").val(),shipping_address_1:jQuery("#shipping_address_1").val(),shipping_address_2:jQuery("#shipping_address_2").val(),shipping_postcode:jQuery("#shipping_postcode").val(),shipping_city:jQuery("#shipping_city").val(),billing_country:jQuery("#billing_country").val(),billing_address_1:jQuery("#billing_address_1").val(),billing_address_2:jQuery("#billing_address_2").val(),billing_postcode:jQuery("#billing_postcode").val(),billing_city:jQuery("#billing_city").val(),selected_point:jQuery("#"+e).val(),action:"fs_collection_points_"+f,security:fs_collection_points_map.ajax_nonce};d.postMessage({addresses_data:g,action:"send_address_data"},window.location.origin)}});

View File

@@ -0,0 +1,596 @@
<?php
/**
* Plugin.
*
* @package Flexible Shippign
*/
use FSVendor\WPDesk\ABTesting\ABVariant;
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\HookableCollection;
use FSVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
use FSVendor\WPDesk\PluginBuilder\Plugin\TemplateLoad;
use FSVendor\WPDesk\Tracker\Deactivation\PluginData;
use FSVendor\WPDesk\Tracker\Deactivation\TrackerFactory;
use FSVendor\WPDesk\View\Resolver\ChainResolver;
use FSVendor\WPDesk\View\Resolver\DirResolver;
use FSVendor\WPDesk\View\Resolver\WPThemeResolver;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* Class Flexible_Shipping_Plugin
*/
class Flexible_Shipping_Plugin extends AbstractPlugin implements HookableCollection {
use HookableParent;
use TemplateLoad;
/*
* Plugin file
*/
const PLUGIN_FILE = 'flexible-shipping/flexible-shipping.php';
const PRIORITY_BEFORE_SHARED_HELPER = -35;
/**
* Scripts version.
*
* @var string
*/
private $scripts_version = FLEXIBLE_SHIPPING_VERSION . '.199';
/**
* 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 \Psr\Log\LoggerInterface
*/
private $logger;
/**
* Selected variant for AB message testing.
*
* @var ABVariant
*/
private $variant;
/**
* Flexible_Invoices_Reports_Plugin constructor.
*
* @param FSVendor\WPDesk_Plugin_Info $plugin_info Plugin info.
*/
public function __construct( FSVendor\WPDesk_Plugin_Info $plugin_info ) {
$this->plugin_info = $plugin_info;
parent::__construct( $this->plugin_info );
$this->init_logger();
}
/**
* Initialize $this->logger
*
* @return LoggerInterface
*/
private function init_logger() {
$logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings();
if ( $logger_settings->is_enabled() ) {
return $this->logger = ( new WPDeskLoggerFactory() )->createWPDeskLogger( $logger_settings->get_logger_channel_name() );
}
return $this->logger = new NullLogger();
}
/**
* Load dependencies.
*/
private function load_dependencies() {
require_once __DIR__ . '/../inc/functions.php';
require_once( __DIR__ . '/wp-wpdesk-fs-shipment/shipment/functions.php' );
require_once( __DIR__ . '/manifest/functions.php' );
new WPDesk_Flexible_Shipping_Shipment_CPT( $this );
new WPDesk_Flexible_Shipping_Shipping_Manifest_CPT( $this );
new WPDesk_Flexible_Shipping_Shipment_Ajax( $this );
new WPDesk_Flexible_Shipping_Bulk_Actions();
new WPDesk_Flexible_Shipping_Export( $this );
new WPDesk_Flexible_Shipping_Multilingual( $this );
new WPDesk_Flexible_Shipping_Multicurrency( $this );
$this->admin_notices = new WPDesk_Flexible_Shipping_Admin_Notices( $this );
$abtesting = new WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information();
$this->variant = $abtesting->get_variant();
$this->add_hookable( new WPDesk_Flexible_Shipping_Tracker() );
$this->add_hookable( new WPDesk\FS\Rate\Flexible_Shipping_Order_Counter() );
$this->add_hookable( new WPDesk\FS\Rate\WPDesk_Flexible_Shipping_Rate_Notice() );
$this->add_hookable( new WPDesk_Flexible_Shipping_AB_Tracker_Deactivation_Data( $this->variant ) );
$this->add_hookable( new WPDesk_Flexible_Shipping_Add_Shipping() );
$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 WPDesk_Flexible_Shipping_Rest_Api_Order_Response_Data_Appender() );
}
/**
* 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_text_domain = $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://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/' : 'https://docs.flexibleshipping.com/collection/20-fs-table-rate/';
$this->default_view_args = array(
'plugin_url' => $this->get_plugin_url(),
);
}
/**
* 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->hooks();
}
/**
* Hooks.
*/
public function hooks() {
parent::hooks();
add_filter( 'woocommerce_shipping_methods', array( $this, 'woocommerce_shipping_methods_filter' ), 10, 1 );
add_action( 'admin_init', array( $this, 'session_init' ) );
add_action( 'woocommerce_after_shipping_rate', array( $this, 'woocommerce_after_shipping_rate' ), 10, 2 );
add_action(
'flexible_shipping_method_rate_id',
array(
$this,
'flexible_shipping_method_rate_id',
),
9999999,
2
);
add_filter(
'woocommerce_shipping_chosen_method',
array(
$this,
'woocommerce_default_shipment_method',
),
10,
3
);
add_action(
'woocommerce_checkout_update_order_meta',
array(
$this,
'add_flexible_shipping_order_meta_on_checkout_woo_pre_27',
)
);
add_action(
'woocommerce_checkout_create_order',
array(
$this,
'add_flexible_shipping_order_meta_on_checkout',
)
);
add_filter( 'option_woocommerce_cod_settings', array( $this, 'option_woocommerce_cod_settings' ) );
add_action( 'plugins_loaded', array( $this, 'create_tracker' ), self::PRIORITY_BEFORE_SHARED_HELPER );
add_action( 'admin_init', array( $this, 'init_deactivation_tracker' ) );
$this->hooks_on_hookable_objects();
}
/**
* Init deactivation tracker.
*/
public function init_deactivation_tracker() {
$plugin_data = new PluginData(
WPDesk_Flexible_Shipping_Tracker::FLEXIBLE_SHIPPING_PLUGIN_SLUG,
WPDesk_Flexible_Shipping_Tracker::FLEXIBLE_SHIPPING_PLUGIN_FILE,
WPDesk_Flexible_Shipping_Tracker::FLEXIBLE_SHIPPING_PLUGIN_TITLE
);
$thickbox_factory = new WPDesk_Flexible_Shipping_Deactivation_Thickbox_Factory(
$this->variant,
$plugin_data
);
$deactivation_tracker = TrackerFactory::createCustomTracker(
$plugin_data,
null,
$thickbox_factory->create_thickbox()
);
$deactivation_tracker->hooks();
}
/**
* Maybe create tracker.
*/
public function create_tracker() {
$tracker_factory = new WPDesk_Tracker_Factory();
$tracker_factory->create_tracker( basename( dirname( __FILE__ ) ) );
}
/**
* Woocommerce shipping methods filter.
*
* @param array $methods .
*
* @return array
*/
public function woocommerce_shipping_methods_filter( $methods ) {
$methods['flexible_shipping'] = WPDesk_Flexible_Shipping::class;
$methods[ WPDesk_Flexible_Shipping_Settings::METHOD_ID ] = WPDesk_Flexible_Shipping_Settings::class;
return $methods;
}
/**
* 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;
}
/**
* Session init.
*/
public function session_init() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
// @codingStandardsIgnoreStart
if ( ! session_id() ) {
session_start();
}
// @codingStandardsIgnoreEnd
}
/**
* 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();
}
}
/**
* Add flexible shipping order meta on checkout (for WooCommerce versions before 2.7).
*
* @param int $order_id Order id.
*/
public function add_flexible_shipping_order_meta_on_checkout_woo_pre_27( $order_id ) {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
if ( ! $this->is_order_processed_on_checkout ) {
$this->is_order_processed_on_checkout = true;
$order = wc_get_order( $order_id );
$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'] )
&& isset( $shipping_method['item_meta']['_fs_method'][0] )
) {
$fs_method = unserialize( $shipping_method['item_meta']['_fs_method'][0] );
if ( ! empty( $fs_method['method_integration'] ) ) {
add_post_meta( $order->id, '_flexible_shipping_integration', $fs_method['method_integration'] );
}
}
}
}
}
}
/**
* 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.
* @param string|bool|null $chosen_method If false or null then no method is chosen.
*
* @return string
*/
public function woocommerce_default_shipment_method( $default, array $available_methods, $chosen_method ) {
// @TODO: Infinite methods calling on Woocommerce 3.1
if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
return $default;
}
if ( null === $chosen_method || false === $chosen_method || ! $this->check_if_shipment_available_for_current_cart( $chosen_method ) ) {
foreach ( $available_methods as $available_method ) {
$method_meta = $available_method->get_meta_data();
$default_meta_key = WPDesk_Flexible_Shipping::META_DEFAULT;
if ( $method_meta && isset( $method_meta[ $default_meta_key ] ) && 'yes' === $method_meta[ $default_meta_key ] ) {
$candidate_id = $available_method->get_id();
if ( $this->check_if_shipment_available_for_current_cart( $candidate_id ) ) {
return $candidate_id;
}
}
}
return $default;
}
return $chosen_method;
}
/**
* Shipment can be possible but not for the current cart. Check if possible for cart.
*
* @param string $shipment_method_id .
*
* @return bool Possible or not
*/
private function check_if_shipment_available_for_current_cart( $shipment_method_id ) {
$shipping_packages = WC()->shipping()->calculate_shipping( WC()->cart->get_shipping_packages() );
if ( is_array( $shipping_packages ) ) {
foreach ( $shipping_packages as $package ) {
if ( isset( $package['rates'][ $shipment_method_id ] ) && $package['rates'][ $shipment_method_id ] ) {
return true;
}
}
}
return false;
}
/**
* Admin enqueue scripts.
*/
public function admin_enqueue_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script(
'fs_admin',
trailingslashit( $this->get_plugin_assets_url() ) . 'js/admin' . $suffix . '.js',
array( 'jquery' ),
$this->scripts_version
);
$notice_url = get_locale() == 'pl_PL' ? 'https://wpde.sk/fs-rate-not-good-pl' : 'https://wpde.sk/fs-rate-not-good';
wp_localize_script(
'fs_admin',
'fs_admin',
array(
'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();
if ( ! empty( $current_screen ) && 'shop_order' === $current_screen->id ) {
wp_enqueue_media();
}
wp_register_script( 'fs_ap_conditional_logic', trailingslashit( $this->get_plugin_assets_url() ) . 'js/ap_conditional_logic' . $suffix . '.js', array( 'jquery' ), $this->scripts_version );
wp_enqueue_script( 'fs_ap_conditional_logic' );
wp_enqueue_style(
'fs_admin',
trailingslashit( $this->get_plugin_assets_url() ) . 'css/admin' . $suffix . '.css',
array(),
$this->scripts_version
);
wp_enqueue_style(
'fs_font',
trailingslashit( $this->get_plugin_assets_url() ) . 'css/font' . $suffix . '.css',
array(),
$this->scripts_version
);
}
/**
* 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://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/' : 'https://docs.flexibleshipping.com/collection/20-fs-table-rate/';
$support_link = get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/docs/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=&utm_content=fs-plugins-support' : 'https://flexibleshipping.com/support/?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=&utm_content=fs-plugins-support';
$docs_link .= '?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=&utm_content=fs-plugins-docs';
$settings_url = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=' . WPDesk_Flexible_Shipping_Settings::METHOD_ID );
$plugin_links = array(
'<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://www.wpdesk.pl/sklep/flexible-shipping-pro-woocommerce/' : 'https://flexibleshipping.com/table-rate/';
$utm = '?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=&utm_content=fs-plugins-upgrade';
if ( ! wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) ) {
$plugin_links[] = '<a href="' . $pro_link . $utm . '" target="_blank" style="color:#d64e07;font-weight:bold;">' . __(
'Upgrade',
'flexible-shipping'
) . '</a>';
}
return array_merge( $plugin_links, $links );
}
/**
* WooCommerce after shipping rate action.
*
* @param WC_Shipping_Rate $method .
* @param int $index .
*/
public function woocommerce_after_shipping_rate( $method, $index ) {
if ( 'flexible_shipping' === $method->method_id ) {
$description = WC()->session->get( 'flexible_shipping_description_' . $method->id, false );
if ( $description && '' !== $description ) {
echo $this->load_template(
'flexible-shipping/after-shipping-rate',
'cart/',
array(
'method_description' => $description,
)
); // WPCS: XSS OK.
}
}
}
/**
* .
*
* @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,62 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function fs_manifest_integration_exists( $integration ) {
$class_name = 'WPDesk_Flexible_Shipping_Manifest' . '_' . $integration ;
if ( class_exists( $class_name ) ) {
return true;
}
return false;
}
function fs_create_manifest( $integration ) {
$post_title = sprintf( __( 'Shipping manifest %s, %s', 'flexible-shipping' ), $integration, date_i18n( get_option( 'date_format' ) ) );
$post_title = apply_filters( 'flexible_shipping_manifest_post_title_'. $integration, $post_title );
$manifest_post = array(
'post_title' => $post_title,
'post_type' => 'shipping_manifest',
'post_status' => 'publish',
);
$manifest_id = wp_insert_post( $manifest_post );
update_post_meta( $manifest_id, '_integration', $integration );
return fs_get_manifest( $manifest_id );
}
/**
* @param $manifest_id
* @return WPDesk_Flexible_Shipping_Manifest
*/
function fs_get_manifest( $manifest_id ) {
$integration = get_post_meta( $manifest_id, '_integration', true );
$class_name = 'WPDesk_Flexible_Shipping_Manifest';
if ( class_exists( $class_name . '_' . $integration ) ) {
$class_name = $class_name . '_' . $integration;
}
else {
$class_name = 'WPDesk_Flexible_Shipping_Manifest_FS';
}
return new $class_name( $manifest_id );
}
function fs_delete_manifest( $manifest ) {
$shipments_posts = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'shipment',
'post_status' => 'any',
'meta_key' => '_manifest',
'meta_value' => $manifest->get_id()
) );
foreach ( $shipments_posts as $shipment_post ) {
$shipment = fs_get_shipment( $shipment_post->ID );
$shipment->delete_meta( '_manifest' );
$shipment->update_status('fs-confirmed' );
$shipment->save();
}
$manifest->set_meta( '_shipments', array() );
$manifest->update_status( 'trash' );
$manifest->save();
}

View File

@@ -0,0 +1,33 @@
<?php
use FSVendor\WPDesk\ABTesting\ABVariant;
class WPDesk_Flexible_Shipping_AB_Variant_Old implements ABVariant {
/**
* Define a new value for the generated variant.
*
* @var int
*/
const VARIANT_ID = 0;
/**
* Is On?
*
* @param string $functionality Functionality.
*
* @return bool
*/
public function is_on( $functionality ) {
return WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_ON_TOP === ! $functionality;
}
/**
* Get variant id.
*
* @return int|string
*/
public function get_variant_id() {
return self::VARIANT_ID;
}
}

View File

@@ -0,0 +1,34 @@
<?php
use FSVendor\WPDesk\ABTesting\ABVariant;
class WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_Button implements ABVariant {
/**
* Define a new value for the generated variant
*
* @var int
*/
const VARIANT_ID = 12;
/**
* Is on?
*
* @param string $functionality Functionality.
*
* @return bool
*/
public function is_on( $functionality ) {
return WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_BUTTON === $functionality;
}
/**
* Get variant id.
*
* @return int|string
*/
public function get_variant_id() {
return self::VARIANT_ID;
}
}

View File

@@ -0,0 +1,34 @@
<?php
use FSVendor\WPDesk\ABTesting\ABVariant;
class WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_On_Bottom implements ABVariant {
/**
* Define a new value for the generated variant
*
* @var int
*/
const VARIANT_ID = 11;
/**
* Is on?
*
* @param string $functionality Functionality.
*
* @return bool
*/
public function is_on( $functionality ) {
return WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_ON_BOTTOM === $functionality;
}
/**
* Get variant id.
*
* @return int|string
*/
public function get_variant_id() {
return self::VARIANT_ID;
}
}

View File

@@ -0,0 +1,34 @@
<?php
use FSVendor\WPDesk\ABTesting\ABVariant;
class WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_On_Top implements ABVariant {
/**
* Define a new value for the generated variant
*
* @var int
*/
const VARIANT_ID = 10;
/**
* Is on?
*
* @param string $functionality Functionality.
*
* @return bool
*/
public function is_on( $functionality ) {
return WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_ON_TOP === $functionality;
}
/**
* Get variant id.
*
* @return int|string
*/
public function get_variant_id() {
return self::VARIANT_ID;
}
}

View File

@@ -0,0 +1,111 @@
<?php
use FSVendor\WPDesk\ABTesting\ABTest\EqualGroupsRandomABTest;
use FSVendor\WPDesk\Persistence\PersistentContainer;
use FSVendor\WPDesk\Persistence\Wordpress\WordpressOptionsContainer;
use FSVendor\WPDesk\ABTesting\ABVariant;
/**
* AB Menu Test https://docs.google.com/document/d/1O7SDr-suN1ooLrHdtkM7L6ARbsnveSj_fsRWMpFr5Ac/
*
* We've created 2 groups/variants.
*/
class WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information extends EqualGroupsRandomABTest {
const TEST_NAME = 'deactivation-contact-information';
const GROUP_COUNT = 3;
const VARIANT_WITH_CONTACT_INFORMATION_ON_TOP = 1;
const VARIANT_WITH_CONTACT_INFORMATION_ON_BOTTOM = 2;
const VARIANT_WITH_CONTACT_BUTTON = 3;
const NEW_USER_AFTER_THIS_DATE = '2019-11-06 01:00:00';
const VARIANT_ID_FOR_OLD_INSTALLATION = 0;
const CONTACT_INFORMATION_ON_TOP = 'contact_information_on_top';
const CONTACT_INFORMATION_ON_BOTTOM = 'contact_information_on_bottom';
const CONTACT_INFORMATION_BUTTON = 'contact_information_button';
/**
* Persistent container
*
* @var PersistentContainer
*/
public $container;
/**
* WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information constructor.
*/
public function __construct() {
$container = new WordpressOptionsContainer();
$this->container = $container;
parent::__construct( self::GROUP_COUNT, self::TEST_NAME, $container );
$this->override_id_for_old_user( $container );
}
/**
* Clears info about variant and draws again
*/
public function reset() {
parent::reset();
$this->override_id_for_old_user( $this->container );
}
/**
* If old user then should have static group
*
* @param PersistentContainer $container Persistent container.
*/
private function override_id_for_old_user( PersistentContainer $container ) {
if ( self::VARIANT_ID_FOR_OLD_INSTALLATION !== $this->current_variant_id && $this->is_old_installation() ) {
$this->current_variant_id = self::VARIANT_ID_FOR_OLD_INSTALLATION;
$container->set( $this->get_container_key(), self::VARIANT_ID_FOR_OLD_INSTALLATION );
}
}
/**
* If this a old user? If so then FS should work like always.
*
* @return bool
*/
private function is_old_installation() {
return strtotime( self::NEW_USER_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 );
}
/**
* Get variant.
*
* @return ABVariant
*/
public function get_variant() {
switch ( $this->current_variant_id ) {
case self::VARIANT_WITH_CONTACT_INFORMATION_ON_TOP:
return new WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_On_Top();
case self::VARIANT_WITH_CONTACT_INFORMATION_ON_BOTTOM:
return new WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_On_Bottom();
case self::VARIANT_WITH_CONTACT_BUTTON:
return new WPDesk_Flexible_Shipping_AB_Variant_With_Contact_Information_Button();
default:
return new WPDesk_Flexible_Shipping_AB_Variant_Old();
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
use FSVendor\WPDesk\ABTesting\ABVariant;
/**
* AB Test https://docs.google.com/document/d/1JA49dgOqJ1SawEdL506tWdW6zgD30cXDpFZhJ7r_SNo/edit?usp=sharing
*
* Class by which we can push some data to the deactivation filter
*/
class WPDesk_Flexible_Shipping_AB_Tracker_Deactivation_Data implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
/**
* Variant.
*
* @var ABVariant
*/
protected $variant;
/**
* WPDesk_Flexible_Shipping_AB_Tracker_Deactivation_Data constructor.
*
* @param ABVariant $variant Variant.
*/
public function __construct( ABVariant $variant ) {
$this->variant = $variant;
}
/**
* Fires hooks
*
* @return void
*/
public function hooks() {
add_filter( 'wpdesk_tracker_deactivation_data', array( $this, 'append_variant_id_to_data' ) );
}
/**
* Set variant ID to data array
*
* @param array $data Data.
*
* @return array
*/
public function append_variant_id_to_data( array $data ) {
if ( WPDesk_Flexible_Shipping_Tracker::is_plugin_flexible_shipping_in_data( $data ) ) {
$data['variant_id'] = $this->variant->get_variant_id();
}
return $data;
}
}

View File

@@ -0,0 +1,51 @@
<?php
use FSVendor\WPDesk\ABTesting\ABVariant;
use FSVendor\WPDesk\Tracker\Deactivation\PluginData;
use FSVendor\WPDesk\Tracker\Deactivation\Thickbox;
/**
* Can display deactivation thickbox content.
*/
class WPDesk_Flexible_Shipping_Deactivation_Thickbox_Factory {
/**
* Variant.
*
* @var ABVariant
*/
private $variant;
/**
* @var PluginData
*/
private $plugin_data;
/**
* WPDesk_Flexible_Shipping_Deactivation_Thickbox_Factory constructor.
*
* @param ABVariant $variant Variant.
* @param PluginData $plugin_data .
*/
public function __construct( ABVariant $variant, PluginData $plugin_data ) {
$this->variant = $variant;
$this->plugin_data = $plugin_data;
}
/**
* Create thickbox.
*
* @return Thickbox
*/
public function create_thickbox() {
$view_file = null;
if ( $this->variant->is_on( WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_ON_TOP ) ) {
$view_file = __DIR__ . '/views/html-thickbox-contact-information-on-top.php';
} elseif ( $this->variant->is_on( WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_ON_BOTTOM ) ) {
$view_file = __DIR__ . '/views/html-thickbox-contact-information-on-bottom.php';
} elseif ( $this->variant->is_on( WPDesk_Flexible_Shipping_AB_Deactivation_Contact_Information::CONTACT_INFORMATION_BUTTON ) ) {
$view_file = __DIR__ . '/views/html-thickbox-contact-information-button.php';
}
return new Thickbox( $this->plugin_data, $view_file );
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @var $support_link string
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?><h4><strong><?php
echo sprintf(
__(
'Do you have a problem with our plugin or do not know how to configure it? Write to our support department - we will try to help. %1$sGo to contact form →%2$s',
'flexible-shipping'
),
"<a target=\"_blank\" href=\"{$support_link}\">",
'</a>'
);
?></strong></h4>

View File

@@ -0,0 +1,13 @@
<?php
/**
* @var $support_link string
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?><div class="footer">
<a href="#" class="button button-secondary button-close tracker-button-close"><?php _e( 'Cancel', 'flexible-shipping' ); ?></a>
<a target="_blank" href="<?php echo $support_link; ?>" class="button button-secondary button-support"><?php _e( 'Any problems? Write to us.', 'flexible-shipping' ); ?></a>
<a href="#" class="button button-primary button-deactivate allow-deactivate"><?php _e( 'Skip &amp; Deactivate', 'flexible-shipping' ); ?></a>
</div>

View File

@@ -0,0 +1,4 @@
<div class="footer">
<a href="#" class="button button-secondary button-close tracker-button-close"><?php _e( 'Cancel', 'flexible-shipping' ); ?></a>
<a href="#" class="button button-primary button-deactivate allow-deactivate"><?php _e( 'Skip &amp; Deactivate', 'flexible-shipping' ); ?></a>
</div>

View File

@@ -0,0 +1,8 @@
<?php
$support_link = get_locale() === 'pl_PL' ? 'https://wpde.sk/tracker-help-pl-3' : 'https://wpde.sk/tracker-help-3';
$buttons_html_file = __DIR__ . '/html-thickbox-buttons-additional-button.php';
$top_html_file = __DIR__ . '/html-empty.php';
$bottom_html_file = __DIR__ . '/html-empty.php';
require __DIR__ . '/html-thickbox-content.php';

View File

@@ -0,0 +1,7 @@
<?php
$support_link = get_locale() === 'pl_PL' ? 'https://wpde.sk/tracker-help-pl-2' : 'https://wpde.sk/tracker-help-2';
$buttons_html_file = __DIR__ . '/html-thickbox-buttons.php';
$top_html_file = __DIR__ . '/html-empty.php';
$bottom_html_file = __DIR__ . '/html-information.php';
require __DIR__ . '/html-thickbox-content.php';

View File

@@ -0,0 +1,8 @@
<?php
$support_link = get_locale() === 'pl_PL' ? 'https://wpde.sk/tracker-help-pl-1' : 'https://wpde.sk/tracker-help-1';
$buttons_html_file = __DIR__ . '/html-thickbox-buttons.php';
$top_html_file = __DIR__ . '/html-information.php';
$bottom_html_file = __DIR__ . '/html-empty.php';
require __DIR__ . '/html-thickbox-content.php';

View File

@@ -0,0 +1,91 @@
<?php
/**
* @var $top_html_file string
* @var $bottom_html_file string
* @var $plugin_title string
* @var $plugin_file string
* @var $plugin_slug string
* @var $thickbox_id string
* @var $ajax_action string
* @var $ajax_nonce string
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?><div id="<?php echo $thickbox_id; ?>" style="display:none;">
<h2><?php echo sprintf( __( 'You are deactivating %s plugin.', 'flexible-shipping' ), $plugin_title ); ?></h2>
<div class="wpdesk_tracker_deactivate <?php echo $thickbox_id; ?>">
<?php include $top_html_file; ?>
<div class="body">
<div class="panel active" data-panel-id="reasons">
<h4><strong><?php _e( '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 _e( '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 _e( 'The plugin broke my site', 'flexible-shipping' ); ?></span>
</label>
</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 _e( '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 _e( '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 _e('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 _e( '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 _e( '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 _e( 'Other', 'flexible-shipping' ); ?></span>
</label>
<div class="other" class="reason-input" style="display: none">
<input type="text" name="other" class="additional-info" placeholder="<?php _e( 'Please let us know how we can improve our plugin', 'flexible-shipping' ); ?>">
</div>
</li>
</ul>
</div>
</div>
<?php include $bottom_html_file; ?>
<?php include $buttons_html_file; ?>
</div>
</div>

View File

@@ -0,0 +1,521 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Bulk_Actions' ) ) {
class WPDesk_Flexible_Shipping_Bulk_Actions {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_filter( 'manage_edit-shop_order_columns', array( $this, 'manage_edit_shop_order_columns' ), 11 );
add_action( 'manage_shop_order_posts_custom_column', array(
$this,
'manage_shop_order_posts_custom_column'
), 11 );
add_filter( 'bulk_actions-edit-shop_order', array( $this, 'bulk_actions_edit_shop_order' ) );
add_filter( 'handle_bulk_actions-edit-shop_order', array(
$this,
'handle_bulk_actions_edit_shop_order'
), 10, 3 );
add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ), 9999 );
//add_filter( 'parse_query', array( $this, 'parse_query' ), 999 );
add_filter( 'posts_where', array( $this, 'posts_where' ), 999 );
//add_filter( 'posts_clauses', array( $this, 'posts_clauses' ), 999, 2 );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
add_action( 'admin_init', array( $this, 'admin_init' ), 1 );
add_filter( 'flexible_shipping_status', array( $this, 'flexible_shipping_status' ) );
}
public function posts_clauses( $clauses, $query ) {
return $clauses;
}
public function flexible_shipping_status( $statuses ) {
$statuses['new'] = __( 'New', 'flexible-shipping' );
$statuses['created'] = __( 'Created', 'flexible-shipping' );
$statuses['confirmed'] = __( 'Confirmed', 'flexible-shipping' );
$statuses['manifest'] = __( 'Manifest', 'flexible-shipping' );
$statuses['failed'] = __( 'Failed', 'flexible-shipping' );
return $statuses;
}
public function posts_where( $where = '' ) {
global $pagenow;
global $wp_query;
global $wpdb;
$query = $wp_query;
$type = 'shop_order';
if ( isset( $_GET['post_type'] ) ) {
$type = $_GET['post_type'];
}
if ( isset( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] == 'shop_order' ) {
if ( 'shop_order' == $type && is_admin() && 'edit.php' == $pagenow ) {
$integration = '';
if (isset($_GET['flexible_shipping_integration_filter'])) {
$integration = $_GET['flexible_shipping_integration_filter'];
}
$status = '';
if (isset($_GET['flexible_shipping_status_filter'])) {
$status = $_GET['flexible_shipping_status_filter'];
}
if ( $integration != '' || $status != '' ) {
$add_where_meta_integration = '';
$add_where_meta_status = '';
$add_where_shipment_integration = '';
$add_where_shipment_status = '';
$add_where = '';
if ( $integration != '' ) {
$add_where_meta_integration = " EXISTS ( SELECT 1 FROM {$wpdb->postmeta} fs_postmeta WHERE {$wpdb->posts}.ID = fs_postmeta.post_id AND fs_postmeta.meta_key = '_flexible_shipping_integration' AND fs_postmeta.meta_value = '$integration' ) ";
$add_where_shipment_integration = " EXISTS ( SELECT 1 FROM {$wpdb->posts} fs_posts, {$wpdb->postmeta} fs_postmeta WHERE {$wpdb->posts}.ID = fs_posts.post_parent AND fs_posts.ID = fs_postmeta.post_id AND fs_postmeta.meta_key = '_integration' AND fs_postmeta.meta_value = '$integration' ) ";
}
if ( $status != '' ) {
$add_where_meta_status = " EXISTS ( SELECT 1 FROM {$wpdb->postmeta} fs_postmeta WHERE {$wpdb->posts}.ID = fs_postmeta.post_id AND fs_postmeta.meta_key = '_flexible_shipping_status' AND fs_postmeta.meta_value = '$status' ) ";
$add_where_shipment_status = " EXISTS ( SELECT 1 FROM {$wpdb->posts} fs_posts WHERE {$wpdb->posts}.ID = fs_posts.post_parent AND fs_posts.post_status = 'fs-{$status}' ) ";
}
$add_where_meta = '';
if ( $add_where_meta_integration != '' ) {
$add_where_meta .= $add_where_meta_integration;
}
if ( $add_where_meta_status != '' ) {
if ( $add_where_meta != '' ) {
$add_where_meta .= ' AND ';
}
$add_where_meta .= $add_where_meta_status;
}
$add_where_shipment = '';
if ( $add_where_shipment_integration != '' ) {
$add_where_shipment .= $add_where_shipment_integration;
}
if ( $add_where_shipment_status != '' ) {
if ( $add_where_shipment != '' ) {
$add_where_shipment .= ' AND ';
}
$add_where_shipment .= $add_where_shipment_status;
}
$add_where_meta = ' ( ' . $add_where_meta . ' ) ';
$add_where_shipment = ' ( ' . $add_where_shipment . ' ) ';
$add_where = ' AND ( ' . $add_where_meta . ' OR ' . $add_where_shipment . ' ) ';
$where .= $add_where;
}
}
}
return $where;
}
public function parse_query( $query ) {
global $pagenow;
$type = 'shop_order';
if ( isset( $_GET['post_type'] ) ) {
$type = $_GET['post_type'];
}
if ( isset( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] == 'shop_order' ) {
if ( 'shop_order' == $type && is_admin() && 'edit.php' == $pagenow ) {
$integration = '';
if ( isset( $_GET['flexible_shipping_integration_filter'] ) ) {
$integration = $_GET['flexible_shipping_integration_filter'];
}
$status = '';
if ( isset( $_GET['flexible_shipping_status_filter'] ) ) {
$status = $_GET['flexible_shipping_status_filter'];
}
if ( $integration != '' || $status != '' ) {
if ($integration != '') {
if (!isset($query->query_vars['meta_query'])) {
$query->query_vars['meta_query'] = array();
}
$meta_query = array();
$meta_query['key'] = '_flexible_shipping_integration';
$meta_query['value'] = $integration;
$query->query_vars['meta_query'][] = $meta_query;
}
/* */
if ($status != '') {
if (!isset($query->query_vars['meta_query'])) {
$query->query_vars['meta_query'] = array();
}
$meta_query = array();
$meta_query['key'] = '_flexible_shipping_status';
$meta_query['value'] = $status;
$query->query_vars['meta_query'][] = $meta_query;
}
}
}
}
}
public function restrict_manage_posts() {
if ( apply_filters( 'flexible_shipping_disable_order_filters', false ) ) {
return;
}
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
if ( count( $integrations ) == 0 ) {
return;
}
global $typenow;
if ( 'shop_order' == $typenow ){
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
$statuses = apply_filters( 'flexible_shipping_status', array() );
$integration = '';
if ( isset( $_GET['flexible_shipping_integration_filter'] ) ) {
$integration = $_GET['flexible_shipping_integration_filter'];
}
$status = '';
if ( isset( $_GET['flexible_shipping_status_filter'] ) ) {
$status = $_GET['flexible_shipping_status_filter'];
}
include( 'views/html-orders-filter-form.php' );
}
}
public function manage_shop_order_posts_custom_column( $column ) {
global $post;
if ( $column == 'flexible_shipping' ) {
$classes = array(
'error' => 'failed',
'new' => 'on-hold',
'created' => 'processing created',
'confirmed' => 'processing confirmed',
'manifest' => 'processing manifest',
);
$statuses = array(
'error' => __('Error', 'flexible-shipping'),
'new' => __('New shipment', 'flexible-shipping'),
'created' => __('Created', 'flexible-shipping'),
'confirmed' => __('Confirmed', 'flexible-shipping'),
'manifest' => __('Manifest created', 'flexible-shipping'),
);
$shippings = array();
$shipments = fs_get_order_shipments($post->ID);
foreach ($shipments as $shipment) {
/* @var $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */
$shipping = array();
$shipping['order_id'] = $post->ID;
$shipping['integration'] = $shipment->get_integration();
$shipping['url'] = $shipment->get_order_metabox_url();
$shipping['error'] = $shipment->get_error_message();
$shipping['status'] = $shipment->get_status_for_shipping_column();
$shipping['tracking_number'] = $shipment->get_tracking_number();
$shipping['label_url'] = $shipment->get_label_url();
$shipping['tracking_url'] = $shipment->get_tracking_url();
$shipping['shipment'] = $shipment;
$shippings[] = $shipping;
}
$shippings = apply_filters( 'flexible_shipping_shipping_data', $shippings );
if (!session_id()) {
session_start();
}
foreach ($shippings as $shipping) {
if ($shipping['status'] == 'error') {
$statuses['error'] = $shipping['error'];
} else {
$statuses['error'] = __('Error', 'flexible-shipping');
}
include( 'views/html-column-shipping-shipping.php' );
}
$messages = array();
if (isset($_SESSION['flexible_shipping_bulk_send'])) {
$messages = $_SESSION['flexible_shipping_bulk_send'];
}
if (isset($messages[$post->ID])) {
unset($messages[$post->ID]);
}
$_SESSION['flexible_shipping_bulk_send'] = $messages;
}
}
public function manage_edit_shop_order_columns( $columns ) {
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
if ( count( $integrations ) == 0 ) {
return $columns;
}
if ( isset( $columns['flexible_shipping'] ) ) {
return $columns;
}
$ret = array();
$col_added = false;
foreach ( $columns as $key => $column ) {
if ( !$col_added && ( $key == 'order_actions' || $key == 'wc_actions' ) ) {
$ret['flexible_shipping'] = __( 'Shipping', 'flexible-shipping' );
$col_added = true;
}
$ret[$key] = $column;
}
if ( !$col_added ) {
$ret['flexible_shipping'] = __( 'Shipping', 'flexible-shipping' );
}
return $ret;
}
function bulk_actions_edit_shop_order( $bulk_actions ) {
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
if ( count( $integrations ) ) {
$bulk_actions['flexible_shipping_send'] = __('Send shipment', 'flexible-shipping');
$bulk_actions['flexible_shipping_labels'] = __('Get labels', 'flexible-shipping');
if ( apply_filters( 'flexible_shipping_has_manifests', false ) ) {
$bulk_actions['flexible_shipping_manifest'] = __( 'Create shipping manifest', 'flexible-shipping' );
}
}
return $bulk_actions;
}
public function handle_bulk_actions_edit_shop_order( $redirect_to, $do_action, $post_ids ) {
$redirect_to = remove_query_arg( 'bulk_flexible_shipping_send', $redirect_to );
$redirect_to = remove_query_arg( 'bulk_flexible_shipping_labels', $redirect_to );
$redirect_to = remove_query_arg( 'bulk_flexible_shipping_manifests', $redirect_to );
if ( $do_action == 'flexible_shipping_send' ) {
$messages = array();
foreach ( $post_ids as $post_id ) {
$shipments = fs_get_order_shipments( $post_id );
$messages[$post_id] = array();
foreach ($shipments as $shipment) {
/* @var $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */
try {
$shipment->set_sent_via_bulk();
$shipment->api_create();
$messages[$post_id][$shipment->get_id()] = array(
'status' => 'created',
'message' => __( 'Shipment created.', 'flexible-shipping' )
);
}
catch ( Exception $e ) {
$messages[$post_id][$shipment->get_id()] = array(
'status' => 'error',
'message' => $e->getMessage()
);
}
}
$messages[$post_id][] = apply_filters(
'flexible_shipping_bulk_send',
array( 'status' => 'none', 'message' => __( 'No action performed.', 'flexible-shipping' )
), $post_id );
}
if ( ! session_id() ) {
session_start();
}
$_SESSION['flexible_shipping_bulk_send'] = $messages;
$redirect_to = add_query_arg( 'bulk_flexible_shipping_send', count( $post_ids ), $redirect_to );
return $redirect_to;
}
if ( $do_action == 'flexible_shipping_labels' ) {
$labels = array();
foreach ( $post_ids as $post_id ) {
$shipments = fs_get_order_shipments( $post_id );
foreach ($shipments as $shipment) {
/* @var $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */
try {
$label = $shipment->get_label();
$labels[] = array(
'status' => 'created',
'message' => __('Label downloaded.', 'flexible-shipping'),
'content' => $label['content'],
'file_name' => $label['file_name']
);
}
catch ( Exception $e ) {
}
}
$labels = apply_filters( 'flexible_shipping_bulk_label', $labels, $post_id );
}
if ( count( $labels ) == 0 ) {
$redirect_to = add_query_arg( 'bulk_flexible_shipping_labels', count( $post_ids ), $redirect_to );
$redirect_to = add_query_arg( 'bulk_flexible_shipping_no_labels_created', 1, $redirect_to );
return $redirect_to;
}
$tmp_zip = tempnam ( 'tmp', 'labels_' );
if ( $tmp_zip ) {
$tmp_zip .= '.zip';
$zip = new ZipArchive();
}
if ( empty( $tmp_zip ) || !$zip->open( $tmp_zip, ZIPARCHIVE::CREATE) ) {
$labels['error'] = __( 'Unable to create temporary zip archive for labels. Check temporary folder configuration on server.', 'flexible-shipping' );
}
else {
foreach ( $labels as $label ) {
if ( isset( $label['content'] ) ) {
$zip->addFromString( $label['file_name'], $label['content'] );
}
}
$labels['tmp_zip'] = $tmp_zip;
$zip->close();
if ( ! session_id() ) {
session_start();
}
}
$_SESSION['flexible_shipping_bulk_labels'] = $labels;
$redirect_to = add_query_arg( 'bulk_flexible_shipping_labels', count( $post_ids ), $redirect_to );
return $redirect_to;
}
if ( $do_action == 'flexible_shipping_manifest' ) {
$manifests = array();
foreach ( $post_ids as $post_id ) {
$shipments = fs_get_order_shipments( $post_id );
foreach ( $shipments as $shipment ) {
/* @var $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */
if ( $shipment->get_status() != 'fs-confirmed' || $shipment->get_meta( '_manifest', '' ) != '' ) {
continue;
}
try {
$integration = $shipment->get_integration();
$manifest_name = $integration;
if ( method_exists( $shipment, 'get_manifest_name' ) ) {
$manifest_name = $shipment->get_manifest_name();
}
$manifest = null;
if ( empty( $manifests[$manifest_name] ) ) {
if ( fs_manifest_integration_exists( $integration ) ) {
$manifest = fs_create_manifest( $integration );
}
}
else {
$manifest = $manifests[$manifest_name];
}
if ( $manifest != null ) {
$manifest->add_shipments( $shipment );
$manifest->save();
$shipment->update_status('fs-manifest' );
$shipment->save();
$manifests[$manifest_name] = $manifest;
}
}
catch ( Exception $e ) {
}
}
}
$messages = array();
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
foreach ( $manifests as $manifest ) {
try {
$manifest->generate();
$manifest->save();
$download_manifest_url = admin_url('edit.php?post_type=shipping_manifest&flexible_shipping_download_manifest=' . $manifest->get_id() . '&nonce=' . wp_create_nonce('flexible_shipping_download_manifest'));
$messages[] = array(
'type' => 'updated',
'message' => sprintf(
__( 'Created manifest: %s (%s). If download not start automatically click %shere%s.', 'flexible-shipping' ),
$manifest->get_number(),
$integrations[$manifest->get_integration()],
'<a class="shipping_manifest_download" target="_blank" href="' . $download_manifest_url . '">',
'</a>'
)
);
}
catch( Exception $e ) {
$messages[] = array(
'type' => 'error',
'message' => sprintf(
__( 'Manifest creation error: %s (%s).', 'flexible-shipping' ),
$e->getMessage(),
$integrations[$manifest->get_integration()]
)
);
fs_delete_manifest( $manifest );
}
}
if ( count( $messages ) == 0 ) {
$messages[] = array(
'type' => 'updated',
'message' => __( 'No manifests created.', 'flexible-shipping' )
);
}
$_SESSION['flexible_shipping_bulk_manifests'] = $messages;
$redirect_to = add_query_arg( 'bulk_flexible_shipping_manifests', count( $post_ids ), $redirect_to );
return $redirect_to;
}
return $redirect_to;
}
public function admin_notices() {
if ( ! empty( $_REQUEST['bulk_flexible_shipping_send'] ) ) {
$bulk_flexible_shipping_send_count = intval( $_REQUEST['bulk_flexible_shipping_send'] );
printf( '<div id="message" class="updated fade"><p>' .
__( 'Bulk send shipment - processed orders: %d', 'flexible-shipping' ).
'</p></div>', $bulk_flexible_shipping_send_count
);
}
if ( ! empty( $_REQUEST['bulk_flexible_shipping_labels'] ) ) {
$bulk_flexible_shipping_labels_count = intval( $_REQUEST['bulk_flexible_shipping_labels'] );
if ( ! empty( $_REQUEST['bulk_flexible_shipping_no_labels_created'] ) ) {
printf( '<div id="message" class="updated fade"><p>' .
__( 'Bulk labels - processed orders: %d. No labels for processed orders.', 'flexible-shipping' ) .
'</p></div>', $bulk_flexible_shipping_labels_count
);
}
else {
if ( ! session_id() ) {
session_start();
}
$labels = null;
if ( isset( $_SESSION['flexible_shipping_bulk_labels'] ) ) {
$labels = $_SESSION['flexible_shipping_bulk_labels'];
unset( $_SESSION['flexible_shipping_bulk_labels'] );
}
if ( is_array( $labels ) ) {
if ( isset( $labels['error'] ) ) {
new \FSVendor\WPDesk\Notice\Notice( $labels['error'], \FSVendor\WPDesk\Notice\Notice::NOTICE_TYPE_ERROR, true, 20 );
} else {
$nonce = wp_create_nonce( 'flexible_shipping_labels' );
printf( '<div id="message" class="updated fade"><p>' .
__( 'Bulk labels - processed orders: %d. If download not start automatically click %shere%s.', 'flexible-shipping' ) .
'</p></div>', $bulk_flexible_shipping_labels_count, '<a id="flexible_shipping_labels_url" target="_blank" href=' . admin_url( '?flexible_shipping_labels=' . basename( $labels['tmp_zip'] ) . '&nonce=' . $nonce ) . '>', '</a>'
);
}
}
}
}
if ( ! empty( $_REQUEST['bulk_flexible_shipping_manifests'] ) ) {
$bulk_flexible_shipping_manifest_count = intval( $_REQUEST['bulk_flexible_shipping_manifests'] );
printf( '<div id="message" class="updated fade"><p>' .
__( 'Bulk shipping manifest - processed orders: %d', 'flexible-shipping' ).
'</p></div>', $bulk_flexible_shipping_manifest_count
);
if ( ! session_id() ) {
session_start();
}
$messages = null;
if ( isset( $_SESSION['flexible_shipping_bulk_manifests'] ) ) {
$messages = $_SESSION['flexible_shipping_bulk_manifests'];
unset( $_SESSION['flexible_shipping_bulk_manifests'] );
foreach ( $messages as $message ) {
printf( '<div id="message" class="%s fade"><p>%s</p></div>', $message['type'], $message['message'] );
}
}
}
}
public function admin_init() {
if ( isset( $_GET['flexible_shipping_labels'] ) && isset( $_GET['nonce'] ) ) {
if ( wp_verify_nonce( $_GET['nonce'], 'flexible_shipping_labels' ) ) {
$file = trailingslashit( sys_get_temp_dir() ) . $_GET['flexible_shipping_labels'];
header( 'Content-Description: File Transfer' );
header( 'Content-Type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename="' . basename( $file ) . '"' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate' );
header( 'Pragma: public' );
header( 'Content-Length: ' . filesize( $file ) );
readfile( $file );
unlink( $file );
die();
}
}
}
}
}

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,7 @@
<?php
/**
* Import rules from CSV.
*/
class WPDesk_Flexible_Shipping_Csv_Importer_Exception extends RuntimeException {
}

View File

@@ -0,0 +1,413 @@
<?php
/**
* CSV importer
*
* @package \WPDesk_Flexible_Shipping
*/
/**
* Import shipping methods and rules from CSV.
*/
class WPDesk_Flexible_Shipping_Csv_Importer {
const CSV_DELIMITER = ';';
/**
* Flexible Shipping shipping method.
*
* @var WPDesk_Flexible_Shipping
*/
private $flexible_shipping_method;
/**
* Hashmap for shipping classes with name->term_id data.
*
* @var \stdClass[]
*/
private $wc_shipping_classes_hashmap;
/**
* Delimiter used in CSV file.
*
* @return string
*/
public static function get_csv_delimiter() {
return apply_filters( 'flexible_shipping_csv_delimiter', self::CSV_DELIMITER );
}
/**
* WPDesk_Flexible_Shipping_Csv_Importer constructor.
*
* @param WPDesk_Flexible_Shipping $flexible_shipping_method Flexible shipping method.
*/
public function __construct( $flexible_shipping_method ) {
$this->flexible_shipping_method = $flexible_shipping_method;
$this->wc_shipping_classes_hashmap = $this->prepare_shipping_class_hashmap();
}
/**
* Prepares hashmap for fast checking the term_id of given shipment class.
*
* @return array
*/
private function prepare_shipping_class_hashmap() {
$cache = [];
foreach ( WC()->shipping()->get_shipping_classes() as $class ) {
$cache[ html_entity_decode( $class->name ) ] = (int) $class->term_id;
}
return $cache;
}
/**
* Load CSV from file.
*
* @param string $tmp_name File name.
*
* @return array
*/
private function load_csv_from_file( $tmp_name ) {
return array_map(
function ( $v ) {
return str_getcsv( $v, self::get_csv_delimiter() );
}, file( $tmp_name )
);
}
/**
* Add columns to row.
*
* @param array $row Row.
* @param array $columns Columns.
*
* @return array
*/
private function add_columns_to_row( array $row, array $columns ) {
foreach ( $columns as $col_key => $col ) {
$row[ $col ] = $row[ $col_key ];
}
return $row;
}
/**
* Convert rows to named values.
*
* @param array $csv_array CSV.
*
* @return array
*/
private function convert_rows_to_named_values( array $csv_array ) {
$first = true;
$columns = array();
foreach ( $csv_array as $row_key => $csv_row ) {
if ( $first ) {
$columns = $csv_row;
} else {
$csv_array[ $row_key ] = $this->add_columns_to_row( $csv_array[ $row_key ], $columns );
}
$first = false;
}
return $csv_array;
}
/**
* Create new shipping method.
*
* @param array $csv_row CSV row.
* @param array $shipping_methods Shipping methods.
* @param int $import_row_count Rows count.
*
* @return array
* @throws WPDesk_Flexible_Shipping_Csv_Importer_Exception Exception.
*/
private function new_shipping_method( array $csv_row, array $shipping_methods, $import_row_count ) {
$new_shipping_method = array( 'method_enabled' => 'no' );
if ( ! isset( $csv_row['Method Title'] ) || '' === trim( $csv_row['Method Title'] ) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
__(
'Sorry, there has been an error. The CSV is invalid or incorrect file type.',
'flexible-shipping'
)
);
}
$method_title = $csv_row['Method Title'];
$count = 0;
while ( $this->flexible_shipping_method->shipping_method_title_used( $method_title, $shipping_methods ) ) {
if ( 0 === $count ) {
$method_title = $csv_row['Method Title'] . ' (' . __( 'import', 'flexible-shipping' ) . ')';
} else {
$method_title = $csv_row['Method Title'] . ' (' . __(
'import',
'flexible-shipping'
) . ' ' . $count . ')';
}
$count ++;
}
$new_shipping_method['id'] = $this->flexible_shipping_method->shipping_method_next_id( $shipping_methods );
$new_shipping_method['id_for_shipping'] = $this->flexible_shipping_method->id . '_' . $this->flexible_shipping_method->instance_id . '_' . $new_shipping_method['id'];
$new_shipping_method['method_title'] = $method_title;
$new_shipping_method['method_description'] = $csv_row['Method Description'];
if ( '' !== trim( $csv_row['Free Shipping'] ) && ! is_numeric(
str_replace(
',', '.',
$csv_row['Free Shipping']
)
) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
sprintf(
// Translators: free shipping value and row number.
__( 'Free Shipping value %1$s is not valid number. Row number %2$d.', 'flexible-shipping' ),
$csv_row['Free Shipping'], $import_row_count
)
);
}
$new_shipping_method[ WPDesk_Flexible_Shipping::FIELD_METHOD_FREE_SHIPPING ] = str_replace(
',', '.',
$csv_row['Free Shipping']
);
if ( trim( $csv_row['Maximum Cost'] ) !== '' && ! is_numeric(
str_replace(
',', '.',
$csv_row['Maximum Cost']
)
) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
sprintf(
// Translators: maximum cost value and row number.
__( 'Maximum Cost value %1$s is not valid number. Row number %2$d.', 'flexible-shipping' ),
$csv_row['Maximum Cost'], $import_row_count
)
);
}
$new_shipping_method['method_max_cost'] = str_replace( ',', '.', $csv_row['Maximum Cost'] );
$new_shipping_method['method_calculation_method'] = $csv_row['Calculation Method'];
if ( ! in_array(
$new_shipping_method['method_calculation_method'],
array( 'sum', 'lowest', 'highest' ),
true
) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
sprintf(
// Translators: row number.
__( 'Invalid value for Calculation Method in row number %d.', 'flexible-shipping' ), $import_row_count
)
);
}
$new_shipping_method['method_visibility'] = $csv_row['Visibility'];
if ( 'yes' !== $new_shipping_method['method_visibility'] ) {
$new_shipping_method['method_visibility'] = 'no';
}
$new_shipping_method['method_default'] = $csv_row['Default'];
if ( 'yes' !== $new_shipping_method['method_default'] ) {
$new_shipping_method['method_default'] = 'no';
}
$new_shipping_method['method_rules'] = array();
return $new_shipping_method;
}
/**
* Get numeric value from row.
*
* @param array $csv_row CSV row.
* @param string $column Column.
* @param int $import_row_count Row count.
*
* @return string
* @throws WPDesk_Flexible_Shipping_Csv_Importer_Exception Exception.
*/
private function get_numeric_value_from_row( array $csv_row, $column, $import_row_count ) {
if ( '' !== trim( $csv_row[ $column ] ) && ! is_numeric( str_replace( ',', '.', $csv_row[ $column ] ) ) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
sprintf(
// Translators: column name, value and row number.
__( '%1$s value %2$s is not valid number. Row number %3$d.', 'flexible-shipping' ),
$column,
$csv_row['Min'],
$import_row_count
)
);
}
return str_replace( ',', '.', $csv_row[ $column ] );
}
/**
* Find and returns shipping class term id
*
* @param string $name Shipping class name to search.
*
* @return int|null Term id
*/
private function find_shipping_class_by_name( $name ) {
$name = html_entity_decode( $name );
if ( isset( $this->wc_shipping_classes_hashmap[ $name ] ) ) {
return $this->wc_shipping_classes_hashmap[ $name ];
}
return null;
}
/**
* Creates a shipping class
*
* @param string $name Shipping class name.
* @param string $description Shipping class description.
*
* @return int Term id
* @throws WPDesk_Flexible_Shipping_Csv_Importer_Exception When can't create the class.
*/
private function create_shipping_class( $name, $description ) {
$term_id = wp_insert_term( $name, 'product_shipping_class', array( 'description' => $description ) );
if ( is_wp_error( $term_id ) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
sprintf(
// Translators: rule shipping class and wp_error message.
__( 'Error while creating shipping class: %1$s, %2$s', 'flexible-shipping' ), $name,
$term_id->get_error_message()
)
);
}
$term_id = (int) $term_id['term_id'];
$this->wc_shipping_classes_hashmap[ html_entity_decode( $name ) ] = $term_id;
return $term_id;
}
/**
* Maybe populate and create shipping classes.
*
* @param array $rule Rule.
*
* @return array
* @throws WPDesk_Flexible_Shipping_Csv_Importer_Exception Exception.
*/
private function maybe_populate_and_create_shipping_classes( array $rule ) {
if ( '' !== trim( $rule['shipping_class'] ) ) {
$rule_shipping_classes = explode( ',', trim( $rule['shipping_class'] ) );
$rule['shipping_class'] = array();
foreach ( $rule_shipping_classes as $rule_shipping_class ) {
if ( ! in_array( $rule_shipping_class, array( 'all', 'any', 'none' ), true ) ) {
$term_id = $this->find_shipping_class_by_name( $rule_shipping_class );
if ( null === $term_id ) {
$term_id = $this->create_shipping_class( $rule_shipping_class, $rule_shipping_class );
}
$rule['shipping_class'][] = $term_id;
} else {
$rule['shipping_class'][] = $rule_shipping_class;
}
}
}
return $rule;
}
/**
* New shipping method rule.
*
* @param array $csv_row CSV row.
* @param int $import_row_count Row count.
*
* @return array
* @throws WPDesk_Flexible_Shipping_Csv_Importer_Exception Exception.
*/
private function new_rule( array $csv_row, $import_row_count ) {
$rule = array();
$rule['based_on'] = $csv_row['Based on'];
if ( ! in_array(
$rule['based_on'],
array( 'none', 'value', 'weight', 'item', 'cart_line_item' ),
true
) ) {
throw new WPDesk_Flexible_Shipping_Csv_Importer_Exception(
sprintf(
// Translators: row number.
__( 'Invalid value for Based On in row number %d.', 'flexible-shipping' ), $import_row_count
)
);
}
$rule['min'] = $this->get_numeric_value_from_row( $csv_row, 'Min', $import_row_count );
$rule['max'] = $this->get_numeric_value_from_row( $csv_row, 'Max', $import_row_count );
$rule['cost_per_order'] = $this->get_numeric_value_from_row( $csv_row, 'Cost per order', $import_row_count );
$rule['cost_additional'] = $this->get_numeric_value_from_row( $csv_row, 'Additional cost', $import_row_count );
$rule['per_value'] = $this->get_numeric_value_from_row( $csv_row, 'Value', $import_row_count );
$rule['shipping_class'] = trim( $csv_row['Shipping Class'] );
$rule = $this->maybe_populate_and_create_shipping_classes( $rule );
$rule['stop'] = $csv_row['Stop'];
if ( 'yes' === $rule['stop'] ) {
$rule['stop'] = 1;
} else {
$rule['stop'] = 0;
}
$rule['cancel'] = $csv_row['Cancel'];
if ( 'yes' === $rule['cancel'] ) {
$rule['cancel'] = 1;
} else {
$rule['cancel'] = 0;
}
return $rule;
}
/**
* Import file.
*
* @param string $tmp_name Tmp file name.
* @param array $shipping_methods Shipping methods.
*
* @return array
* @throws WPDesk_Flexible_Shipping_Csv_Importer_Exception Exception.
*/
public function import( $tmp_name, array $shipping_methods ) {
$csv_array = $this->load_csv_from_file( $tmp_name );
$csv_array = $this->convert_rows_to_named_values( $csv_array );
$first = true;
$current_method_title = '';
$method_title = '';
$imported_shipping_method = array();
$import_row_count = 0;
foreach ( $csv_array as $row_key => $csv_row ) {
$import_row_count ++;
$new_method = false;
if ( ! $first ) {
if ( ! isset( $csv_row['Method Title'] ) || $current_method_title !== $csv_row['Method Title'] || ! isset( $csv_row['Based on'] ) || '' === $csv_row['Based on'] ) {
$new_method = true;
$imported_shipping_method = $this->new_shipping_method(
$csv_row, $shipping_methods,
$import_row_count
);
$current_method_title = $imported_shipping_method['method_title'];
$method_title = $current_method_title;
} else {
$imported_shipping_method['method_rules'][] = $this->new_rule( $csv_row, $import_row_count );
}
}
if ( ! $first ) {
$shipping_methods[ $imported_shipping_method['id'] ] = $imported_shipping_method;
if ( $new_method ) {
WC_Admin_Settings::add_message(
sprintf(
// Translators: imported method title and method title.
__( 'Shipping method %1$s imported as %2$s.', 'flexible-shipping' ), $current_method_title,
$method_title
)
);
}
}
$first = false;
}
return $shipping_methods;
}
}

View File

@@ -0,0 +1,228 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Export' ) ) {
class WPDesk_Flexible_Shipping_Export {
/**
* @var Flexible_Shipping_Plugin
*/
private $plugin;
/**
* WPDesk_Flexible_Shipping_Export constructor.
*
* @param Flexible_Shipping_Plugin $plugin
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
*
*/
private function hooks() {
add_action( 'wp_ajax_flexible_shipping_export', array( $this, 'wp_ajax_flexible_shipping_export' ) );
}
/**
*
*/
public function wp_ajax_flexible_shipping_export() {
check_ajax_referer( 'flexible_shipping', 'flexible_shipping_nonce' );
$ret = array( 'status' => 'ok' );
$flexible_shipping_action = '';
if ( isset( $_REQUEST['flexible_shipping_action'] ) ) {
$flexible_shipping_action = $_REQUEST['flexible_shipping_action'];
}
if ( $flexible_shipping_action == 'export' ) {
$instance_id = '';
if ( isset( $_REQUEST['instance_id'] ) ) {
$instance_id = $_REQUEST['instance_id'];
}
$ret['instance_id'] = $instance_id;
$methods = '';
if ( isset( $_REQUEST['methods'] ) ) {
$methods = $_REQUEST['methods'];
}
$methods_array = explode( ',', $methods );
$shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id );
$wc_shipping_classes = WC()->shipping->get_shipping_classes();
$ret['shipping_method'] = $shipping_method;
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
/** @var WPDesk_Flexible_Shipping $flexible_shipping */
$flexible_shipping = $all_shipping_methods['flexible_shipping'];
$flexible_shipping_rates = $flexible_shipping->get_all_rates();
$filename = 'fs_' . str_replace( 'http://', '', str_replace( 'https://', '', site_url() ) ) . '-' . $instance_id;
$ret['all_rates'] = $flexible_shipping_rates;
$ret['methods'] = $methods;
$csv_array = array();
$csv_header = array(
'Method Title',
'Method Description',
'Free Shipping',
'Maximum Cost',
'Calculation Method',
'Visibility',
'Default',
'Based on',
'Min',
'Max',
'Cost per order',
'Additional cost',
'Value',
'Shipping Class',
'Stop',
'Cancel',
);
$csv_array[] = $csv_header;
foreach ( $flexible_shipping_rates as $flexible_shipping_rate ) {
if ( strval( $flexible_shipping_rate['instance_id'] ) !== $instance_id
|| ! in_array( strval( $flexible_shipping_rate['id'] ), $methods_array, true )
) {
continue;
}
$filename .= '_' . $flexible_shipping_rate['id'];
if ( ! isset( $flexible_shipping_rate['method_description'] ) ) {
$flexible_shipping_rate['method_description'] = '';
}
if ( ! isset( $flexible_shipping_rate['method_free_shipping'] ) ) {
$flexible_shipping_rate['method_free_shipping'] = '';
}
if ( ! isset( $flexible_shipping_rate['method_max_cost'] ) ) {
$flexible_shipping_rate['method_max_cost'] = '';
}
if ( ! isset( $flexible_shipping_rate['method_calculation_method'] ) ) {
$flexible_shipping_rate['method_calculation_method'] = '';
}
if ( ! isset( $flexible_shipping_rate['method_visibility'] ) ) {
$flexible_shipping_rate['method_visibility'] = '';
}
if ( $flexible_shipping_rate['method_visibility'] != 'yes' ) {
$flexible_shipping_rate['method_visibility'] = '';
}
if ( ! isset( $flexible_shipping_rate['method_default'] ) ) {
$flexible_shipping_rate['method_default'] = '';
}
if ( $flexible_shipping_rate['method_default'] != 'yes' ) {
$flexible_shipping_rate['method_default'] = '';
}
$csv_array[] = array(
$flexible_shipping_rate['method_title'],
$flexible_shipping_rate['method_description'],
$flexible_shipping_rate['method_free_shipping'],
$flexible_shipping_rate['method_max_cost'],
$flexible_shipping_rate['method_calculation_method'],
$flexible_shipping_rate['method_visibility'],
$flexible_shipping_rate['method_default'],
'',
'',
'',
'',
'',
'',
'',
'',
'',
);
foreach ( $flexible_shipping_rate['method_rules'] as $method_rule ) {
if ( ! isset( $method_rule['based_on'] ) ) {
$method_rule['based_on'] = '';
}
if ( ! isset( $method_rule['min'] ) ) {
$method_rule['min'] = '';
}
if ( ! isset( $method_rule['max'] ) ) {
$method_rule['max'] = '';
}
if ( ! isset( $method_rule['cost_per_order'] ) ) {
$method_rule['cost_per_order'] = '';
}
if ( ! isset( $method_rule['cost_additional'] ) ) {
$method_rule['cost_additional'] = '';
}
if ( ! isset( $method_rule['per_value'] ) ) {
$method_rule['per_value'] = '';
}
if ( ! isset( $method_rule['shipping_class'] ) ) {
$method_rule['shipping_class'] = '';
} else {
$method_shipping_class = $method_rule['shipping_class'];
if ( ! is_array( $method_shipping_class ) ) {
$method_shipping_class = array( $method_shipping_class );
}
$method_rule['shipping_class'] = '';
foreach ( $method_shipping_class as $shipping_class ) {
if ( in_array( $shipping_class, array( 'none', 'any', 'all' ) ) ) {
$method_rule['shipping_class'] .= $shipping_class;
$method_rule['shipping_class'] .= ',';
}
}
foreach ( $wc_shipping_classes as $shipping_class ) {
if ( in_array( $shipping_class->term_id, $method_shipping_class ) ) {
$method_rule['shipping_class'] .= $shipping_class->name;
$method_rule['shipping_class'] .= ',';
}
}
$method_rule['shipping_class'] = trim( $method_rule['shipping_class'], ',' );
}
if ( ! isset( $method_rule['stop'] ) ) {
$method_rule['stop'] = '';
}
if ( $method_rule['stop'] == '1' ) {
$method_rule['stop'] = 'yes';
} else {
$method_rule['stop'] = '';
}
if ( ! isset( $method_rule['cancel'] ) ) {
$method_rule['cancel'] = '';
}
if ( $method_rule['cancel'] == '1' ) {
$method_rule['cancel'] = 'yes';
} else {
$method_rule['cancel'] = '';
}
$csv_array[] = array(
$flexible_shipping_rate['method_title'],
'',
'',
'',
'',
'',
'',
$method_rule['based_on'],
$method_rule['min'],
$method_rule['max'],
$method_rule['cost_per_order'],
$method_rule['cost_additional'],
$method_rule['per_value'],
$method_rule['shipping_class'],
$method_rule['stop'],
$method_rule['cancel'],
);
}
}
$ret['csv_array'] = $csv_array;
header( 'Content-Type: text/csv; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=' . $filename . '.csv' );
$out = fopen( 'php://output', 'w' );
foreach ( $csv_array as $fields ) {
fputcsv( $out, $fields, WPDesk_Flexible_Shipping_Csv_Importer::get_csv_delimiter() );
}
fclose( $out );
wp_die();
}
echo json_encode( $ret, JSON_PRETTY_PRINT );
wp_die();
}
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* 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', 'flexible-shipping' );
$this->supports = array(
'settings',
);
$this->logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings( $this );
$this->init_form_fields();
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $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 = $_GET['page'];
$section = $_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 = array(
'flexible_shipping' => array(
'type' => 'flexible_shipping',
),
);
$this->form_fields[] = array(
'type' => 'title',
'title' => __( 'Advanced settings', 'flexible-shipping' )
);
$this->form_fields = $this->logger_settings->add_fields_to_settings( $this->form_fields );
}
/**
* Generate FC connect box
*
* @param string $key Key.
* @param array $data Data.
*
* @return string
*/
public function generate_flexible_shipping_html( $key, $data ) {
ob_start();
include 'views/html-shipping-settings-info-description.php';
$notice_content = ob_get_contents();
ob_end_clean();
return $notice_content;
}
}

View File

@@ -0,0 +1,99 @@
<?php
function flexible_shipping_get_all_shipping_methods() {
/*
$all_shipping_methods = WC()->shipping()->get_shipping_methods();
if ( empty( $all_shipping_methods ) ) {
$all_shipping_methods = WC()->shipping()->load_shipping_methods();
}
*/
$all_shipping_methods = WC()->shipping()->load_shipping_methods();
return $all_shipping_methods;
}
function flexible_shipping_method_selected_in_cart( $shipping_method_integration ) {
global $woocommerce;
$shippings = $woocommerce->session->get('chosen_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 ( $shippings as $id => $shipping ) {
if ( isset( $flexible_shipping_rates[$shipping] ) ) {
$shipping_method = $flexible_shipping_rates[$shipping];
if ( $shipping_method['method_integration'] == $shipping_method_integration ) {
return $shipping_method;
}
}
}
return false;
}
function flexible_shipping_method_selected( $order, $shipping_method_integration ) {
if ( is_numeric( $order ) ) {
$order = wc_get_order( $order );
}
$shippings = $order->get_shipping_methods();
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
if ( isset( $all_shipping_methods['flexible_shipping'] ) ) {
$flexible_shipping_rates = $all_shipping_methods['flexible_shipping']->get_all_rates();
foreach ( $shippings as $id => $shipping ) {
if ( isset( $flexible_shipping_rates[ $shipping['method_id'] ] ) ) {
$shipping_method = $flexible_shipping_rates[ $shipping['method_id'] ];
if ( $shipping_method['method_integration'] == $shipping_method_integration ) {
return $shipping_method;
}
}
}
}
return false;
}
function flexible_shipping_get_integration_for_method( $method_id ) {
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
if ( isset( $all_shipping_methods['flexible_shipping'] ) ) {
$flexible_shipping_rates = $all_shipping_methods['flexible_shipping']->get_all_rates();
if ( isset( $flexible_shipping_rates[$method_id] ) ) {
return $flexible_shipping_rates[$method_id]['method_integration'];
}
}
return false;
}
if ( !function_exists('wpdesk_redirect') ) {
function wpdesk_redirect( $redirect ) {
if ( 1==1 && headers_sent() ) {
?>
<span><?php printf( __( 'Redirecting. If page not redirects click %s here %s.', 'flexible-shipping'), '<a href="' . $redirect . '" >', '</a>' ); ?></span>
<script>
parent.location.replace('<?php echo $redirect; ?>');
</script>
<?php
}
else {
wp_safe_redirect($redirect);
}
exit;
}
}
if ( !function_exists( 'wpdesk__' ) ) {
function wpdesk__( $text, $domain ) {
if ( function_exists( 'icl_sw_filters_gettext' ) ) {
return icl_sw_filters_gettext( $text, $text, $domain, $text );
}
if ( function_exists( 'pll__' ) ) {
return pll__( $text );
}
return __( $text, $domain );
}
}
if ( !function_exists( 'wpdesk__e' ) ) {
function wpdesk__e( $text, $domain ) {
echo wpdesk__( $text, $domain );
}
}

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,108 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Multicurrency' ) ) {
class WPDesk_Flexible_Shipping_Multicurrency {
/**
* @var Flexible_Shipping_Plugin
*/
private $plugin;
/**
* WPDesk_Flexible_Shipping_Export constructor.
*
* @param Flexible_Shipping_Plugin $plugin
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
*
*/
private function hooks() {
add_filter( 'flexible_shipping_value_in_currency', array( $this, 'flexible_shipping_value_in_currency_wpml' ), 1 );
if ( class_exists( 'WC_Aelia_CurrencySwitcher' ) ) {
add_filter( 'flexible_shipping_value_in_currency', array( $this, 'flexible_shipping_value_in_currency_aelia' ), 1 );
}
if ( class_exists( 'Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher' ) ) {
add_filter( 'flexible_shipping_value_in_currency', array( $this, 'flexible_shipping_value_in_currency_aelia_namespaces' ), 1 );
}
if ( function_exists( 'wmcs_convert_price' ) ) {
add_filter( 'flexible_shipping_value_in_currency', array( $this, 'flexible_shipping_value_in_currency_wmcs' ), 1 );
}
if ( isset( $GLOBALS['WOOCS'] ) ) {
add_filter( 'flexible_shipping_value_in_currency', array( $this, 'flexible_shipping_value_in_currency_woocs' ), 1 );
}
}
/**
* @param float $value
*
* @return float
*/
public function flexible_shipping_value_in_currency_aelia( $value ) {
$aelia = WC_Aelia_CurrencySwitcher::instance();
$aelia_settings = WC_Aelia_CurrencySwitcher::settings();
$from_currency = $aelia_settings->base_currency();
$to_currency = $aelia->get_selected_currency();
$value = $aelia->convert( $value, $from_currency, $to_currency );
return $value;
}
/**
* @param float $value
*
* @return float
*/
public function flexible_shipping_value_in_currency_aelia_namespaces( $value ) {
$aelia = Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher::instance();
$aelia_settings = Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher::settings();
$from_currency = $aelia_settings->base_currency();
$to_currency = $aelia->get_selected_currency();
$value = $aelia->convert( $value, $from_currency, $to_currency );
return $value;
}
/**
* @param float $value
*
* @return float
*/
public function flexible_shipping_value_in_currency_wmcs( $value ) {
$value = wmcs_convert_price( $value );
return $value;
}
/**
* @param float $value
*
* @return float
*/
public function flexible_shipping_value_in_currency_wpml( $value ) {
return apply_filters( 'wcml_raw_price_amount', $value );
}
/**
* @param float $value
*
* @return float
*/
public function flexible_shipping_value_in_currency_woocs( $value ) {
return $GLOBALS['WOOCS']->woocs_exchange_value( $value );
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Multilingual' ) ) {
class WPDesk_Flexible_Shipping_Multilingual {
/**
* @var Flexible_Shipping_Plugin
*/
private $plugin;
/**
* WPDesk_Flexible_Shipping_Export constructor.
*
* @param Flexible_Shipping_Plugin $plugin
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
*
*/
private function hooks() {
add_action( 'init', array( $this, 'init_polylang') );
add_action( 'admin_init', array( $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' ) );
}
}
}
}
/**
*
*/
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 );
}
}
}
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$docs_link = get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/' : 'https://docs.flexibleshipping.com/collection/20-fs-table-rate/';
$docs_link .= '?utm_source=flexible-shipping-settings&utm_medium=link&utm_campaign=flexible-shipping-docs-link';
/**
* Settings for flexible shipment
*/
$settings = array(
array(
'title' => __( 'Flexible Shipping', 'flexible-shipping' ),
'type' => 'title',
'description' => sprintf( __( 'See how to %sconfigure Flexible Shipping%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',
'class' => 'wc-enhanced-select',
'default' => 'taxable',
'options' => array(
'taxable' => __( 'Taxable', 'flexible-shipping' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' )
)
),
'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,180 @@
<?php
/**
* Shipping method settings.
*
* @package Flexible Shipping.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Settings for flexible shipment, shipment method
*/
$shipping_classes = array();
$shipping_classes['0'] = __( 'Select shipment class', 'flexible-shipping' );
foreach ( WC()->shipping->get_shipping_classes() as $shipping_class ) {
$shipping_classes[ $shipping_class->term_id ] = $shipping_class->name;
}
$base_location = wc_get_base_location();
$integrations = '';
switch ( $base_location['country'] ) {
case 'PL':
$integrations = __( 'Integrate with DPD, DHL, InPost, eNadawca Poczta Polska, Paczka w Ruchu.', 'flexible-shipping' ) . '&nbsp;&nbsp;' .
// Translators: link.
sprintf( __( '%1$sAdd integrations%2$s', 'flexible-shipping' ), '<a class="button button-primary" href="https://www.wpdesk.pl/kategoria-produktu/wysylka/?utm_source=flexible-shipping-method&utm_medium=button&utm_campaign=flexible-shipping-integrations" target="_blank">', ' &rarr;</a>' );
break;
default:
$integrations = __( 'Integrate with DPD.', 'flexible-shipping' ) . '&nbsp;&nbsp;' .
// Translators: link.
sprintf( __( '%1$sAdd integration%2$s', 'flexible-shipping' ), '<a class="button button-primary" href="https://www.wpdesk.net/products/dpd-uk-woocommerce/?utm_source=flexible-shipping-method&utm_medium=button&utm_campaign=flexible-shipping-integrations" target="_blank">', ' &rarr;</a>' );
break;
}
$integrations_tip = $integrations ? false : true;
if ( ! isset( $shipping_method['method_free_shipping_label'] ) ) {
$shipping_method['method_free_shipping_label'] = __( 'Free', 'flexible-shipping' );
}
$this->settings['method_free_shipping'] = $shipping_method['method_free_shipping'];
if ( empty( $shipping_method['method_integration'] ) ) {
$shipping_method['method_integration'] = '';
}
$method_free_shipping = '';
if ( isset( $shipping_method['method_free_shipping'] ) && '' !== $shipping_method['method_free_shipping'] ) {
$method_free_shipping = floatval( $shipping_method['method_free_shipping'] );
}
$settings = array(
'method_enabled' => array(
'title' => __( 'Enable/Disable', 'flexible-shipping' ),
'type' => 'checkbox',
'default' => $shipping_method['method_enabled'],
'label' => __( 'Enable this shipment method', 'flexible-shipping' ),
),
'method_title' => array(
'title' => __( 'Method 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,
'default' => $shipping_method['method_title'],
'custom_attributes' => array( 'required' => true ),
),
'method_description' => array(
'title' => __( 'Method Description', 'flexible-shipping' ),
'type' => 'text',
'description' => __( 'This controls method description which the user sees during checkout.', 'flexible-shipping' ),
'default' => '',
'desc_tip' => true,
'default' => $shipping_method['method_description'],
),
array(
'title' => '',
'type' => 'title',
'description' => '',
),
'method_free_shipping' => array(
'title' => __( 'Free Shipping', 'flexible-shipping' ),
'type' => 'price',
'default' => $method_free_shipping,
'description' => __( 'Enter a minimum order amount for free shipment. This will override the costs configured below.', 'flexible-shipping' ),
'desc_tip' => true,
),
'method_free_shipping_label' => array(
'title' => __( 'Free Shipping Label', 'flexible-shipping' ),
'type' => 'text',
'default' => $shipping_method['method_free_shipping_label'],
'description' => __( 'Enter additional label for shipment when free shipment available.', 'flexible-shipping' ),
'desc_tip' => true,
),
array(
'title' => '',
'type' => 'title',
'description' => '',
),
'method_calculation_method' => array(
'title' => __( 'Rules Calculation', 'flexible-shipping' ),
'type' => 'select',
'description' => __( 'Select how rules will be calculated. If you choose "sum" the rules order is important.', 'flexible-shipping' ),
'default' => $shipping_method['method_calculation_method'],
'desc_tip' => true,
'options' => array( 'sum' => __( 'Sum', 'flexible-shipping' ) ),
),
'method_visibility' => array(
'title' => __( 'Visibility', 'flexible-shipping' ),
'type' => 'checkbox',
'default' => $shipping_method['method_visibility'],
'label' => __( 'Show only for logged in users', 'flexible-shipping' ),
),
'method_default' => array(
'title' => __( 'Default', 'flexible-shipping' ),
'type' => 'checkbox',
'default' => $shipping_method['method_default'],
'label' => __( 'Check the box to set this option as the default selected choice on the cart page.', 'flexible-shipping' ),
),
'method_integration' => array(
'title' => __( 'Integration', 'flexible-shipping' ),
'type' => 'select',
'description' => __( 'Select integration. ', 'flexible-shipping' ) . $integrations,
'desc_tip' => $integrations_tip,
'default' => $shipping_method['method_integration'],
'options' => apply_filters( 'flexible_shipping_integration_options', array( '' => __( 'None', 'flexible-shipping' ) ) ),
),
);
$settings = apply_filters( 'flexible_shipping_method_settings', $settings, $shipping_method );
if ( isset( $settings['method_max_cost'] ) ) {
$this->settings['method_max_cost'] = $settings['method_max_cost']['default'];
}
$settings['method_rules'] = array(
'title' => __( 'Rules', 'flexible-shipping' ),
'type' => 'shipping_rules',
'default' => isset( $shipping_method['method_rules'] ) ? $shipping_method['method_rules'] : array(),
'method_title' => $shipping_method['method_title'],
);
if ( version_compare( WC()->version, '2.6' ) < 0 ) {
unset( $settings['method_free_shipping_label'] );
}
if ( class_exists( 'WC_Shipping_Zones1' ) ) {
$shipping_zones = WC_Shipping_Zones::get_zones();
$shipping_zones_options = array();
foreach ( $shipping_zones as $shipping_zone ) {
$shipping_zones_options[ $shipping_zone['zone_id'] ] = $shipping_zone['zone_name'];
}
$settings_with_zones = array();
foreach ( $settings as $key => $setting ) {
$settings_with_zones[ $key ] = $setting;
if ( 'method_title' === $key ) {
$settings_with_zones['method_shipping_zone'] = array(
'title' => __( 'Shipping Zone', 'flexible-shipping' ),
'type' => 'select',
'default' => $shipping_method['method_shipping_zone'],
'options' => $shipping_zones_options,
);
}
}
return $settings_with_zones;
}
$docs_link = get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/docs/flexible-shipping-pro-woocommerce-docs/' : 'https://docs.flexibleshipping.com/article/29-shipping-methods/';
$docs_link .= '?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=configure-shipment-methods&utm_content=fs-shippingzone-addnew-seehow';
// Translators: link.
echo '<p>' . sprintf( __( 'See how to %1$sconfigure shipment methods%2$s.', 'flexible-shipping' ), '<a href="' . $docs_link . '" target="_blank">', '</a>' ) . '</p>'; // WPCS: XSS ok.
return $settings;

View File

@@ -0,0 +1,893 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping' ) ) {
class WPDesk_Flexible_Shipping extends WC_Shipping_Method {
const FIELD_METHOD_FREE_SHIPPING = 'method_free_shipping';
const META_DEFAULT = '_default';
const WEIGHT_ROUNDING_PRECISION = 6;
/**
* Message added.
*
* @var bool
*/
private $message_added = false;
/**
* Constructor for your shipment class
*
* @access public
* @return void
*/
public function __construct( $instance_id = 0 ) {
$this->instance_id = absint( $instance_id );
$this->id = 'flexible_shipping';
$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', 'flexible-shipping' );
$this->method_description = __( 'Flexible Shipping', 'flexible-shipping' );
$this->supports = array(
'shipping-zones',
'instance-settings',
);
$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();
//$this->method_title = $this->get_option( 'title' );
//add_action( 'woocommerce_sections_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* 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' );
}
/**
* @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_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>
<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'] ); ?>
<a href="<?php echo remove_query_arg( 'added', add_query_arg( 'action', 'new' ) ); ?>" class="add-new-h2"><?php echo __('Add New', 'flexible-shipping' ); ?></a></h3>
<?php if ( ! empty( $data['description'] ) ) : ?>
<p><?php echo wp_kses_post( $data['description'] ); ?></p>
<?php endif; ?>
<table class="form-table">
<?php
return ob_get_clean();
}
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 ( 'views/html-shipping-method-settings.php' );
return ob_get_clean();
}
public function get_shipping_methods( $enabled = false ) {
$shipping_methods = get_option( $this->shipping_methods_option, array() );
$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;
}
public function get_shipping_method_order() {
$shipping_methods = get_option( $this->shipping_methods_option, array() );
$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;
}
public function generate_shipping_rules_html( $key, $data ) {
if ( ! function_exists( 'woocommerce_form_field' ) ) {
$wc_template_functions = trailingslashit( dirname( __FILE__) ) . '../../woocommerce/includes/wc-template-functions.php';
if ( file_exists( $wc_template_functions ) ) {
include_once( $wc_template_functions );
}
}
ob_start();
include ( 'views/html-shipping-method-rules.php' );
return ob_get_clean();
}
/**
* Initialise Settings Form Fields
*/
public function init_form_fields() {
$this->form_fields = include( 'settings/flexible-shipping.php' );
}
public function update_rates( $shipping_methods ) {
$rates = array();
foreach ( $shipping_methods as $shipping_method ) {
$id = $this->id . '_' . $this->instance_id . '_' . sanitize_title($shipping_method['method_title'] );
$id = apply_filters( 'flexible_shipping_method_rate_id', $id, $shipping_method );
if ( ! isset( $rates[$id] ) && $shipping_method['method_enabled'] == 'yes' )
$rates[$id] = array(
'identifier' => $id,
'title' => $shipping_method['method_title']
);
}
update_option( 'flexible_shipping_rates', $rates );
}
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;
}
/**
* Add method creation date.
*/
private function add_method_creation_date() {
if ( ! get_option( 'flexible_shipping_method_creation_date' ) ) {
add_option( 'flexible_shipping_method_creation_date', current_time('mysql') );
}
}
public function process_admin_options() {
$action = false;
if ( isset( $_POST['method_action'] ) ) {
$action = $_POST['method_action'];
}
if ( $action == 'new' || $action == 'edit' ) {
$this->add_method_creation_date();
$shipping_methods = get_option( $this->shipping_methods_option, array() );
$shipping_method = array();
if ( $action == 'new' ) {
$shipping_methods = get_option( $this->shipping_methods_option, array() );
$shipping_method_order = get_option( $this->shipping_method_order_option, array() );
//
$method_id = get_option( 'flexible_shipping_method_id', 0 );
//$method_id = 0;
foreach ( $shipping_methods as $shipping_method ) {
if ( intval( $shipping_method['id'] ) > $method_id ) $method_id = intval( $shipping_method['id'] );
}
$method_id++;
update_option( 'flexible_shipping_method_id', $method_id );
//
$method_id_for_shipping = $this->id . '_' . $this->instance_id . '_' . $method_id;
}
else {
$method_id = $_POST['method_id'];
$method_id_for_shipping = $_POST['method_id_for_shipping'];
if ( isset( $shipping_methods[ $method_id ] ) ) {
$shipping_method = $shipping_methods[ $method_id ];
}
}
$shipping_method['woocommerce_method_instance_id'] = $this->instance_id;
$shipping_method['id'] = $method_id;
$shipping_method['id_for_shipping'] = $method_id_for_shipping;
$shipping_method['method_title'] = wp_unslash( $_POST['woocommerce_' . $this->id . '_method_title'] );
$shipping_method['method_description'] = wp_unslash( $_POST['woocommerce_' . $this->id . '_method_description'] );
$shipping_method[self::FIELD_METHOD_FREE_SHIPPING] = '';
if ( isset( $_POST['woocommerce_' . $this->id . '_method_free_shipping'] ) && $_POST['woocommerce_' . $this->id . '_method_free_shipping'] != '' ) {
$shipping_method[self::FIELD_METHOD_FREE_SHIPPING] = wc_format_decimal( $_POST['woocommerce_' . $this->id . '_method_free_shipping'] );
}
if ( version_compare( WC()->version, '2.6' ) >= 0 ) {
$shipping_method['method_free_shipping_label'] = wp_unslash( $_POST['woocommerce_' . $this->id . '_method_free_shipping_label'] );
}
$shipping_method['method_calculation_method'] = $_POST['woocommerce_' . $this->id . '_method_calculation_method'];
$shipping_method['method_visibility'] = 'no';
if ( isset( $_POST['woocommerce_' . $this->id . '_method_visibility'] ) && $_POST['woocommerce_' . $this->id . '_method_visibility'] == 1 )
$shipping_method['method_visibility'] = 'yes';
//
$shipping_method['method_default'] = 'no';
if ( isset( $_POST['woocommerce_' . $this->id . '_method_default'] ) && $_POST['woocommerce_' . $this->id . '_method_default'] == 1 )
$shipping_method['method_default'] = 'yes';
//
$shipping_method['method_enabled'] = 'no';
if ( isset( $_POST['woocommerce_' . $this->id . '_method_enabled'] ) && $_POST['woocommerce_' . $this->id . '_method_enabled'] == 1 )
$shipping_method['method_enabled'] = 'yes';
//
$shipping_method['method_integration'] = $_POST['woocommerce_' . $this->id . '_method_integration'];
//
$shipping_method = apply_filters( 'flexible_shipping_process_admin_options', $shipping_method );
//
$count = 0;
$shipping_method['method_rules'] = array();
if ( isset( $_POST['method_rules'] ) ) {
foreach ( $_POST['method_rules'] as $rule ) {
$count++;
$method_rule = array();
$method_rule['based_on'] = $rule['based_on'];
$method_rule['min'] = wc_format_decimal( $rule['min'] );
$method_rule['max'] = wc_format_decimal( $rule['max'] );
$method_rule['cost_per_order'] = wc_format_decimal( $rule['cost_per_order'] );
$method_rule = apply_filters( 'flexible_shipping_method_rule_save', $method_rule, $rule );
$shipping_method['method_rules'][$count] = $method_rule;
}
}
//
$shipping_methods[$method_id] = $shipping_method;
//
update_option( $this->shipping_methods_option, $shipping_methods );
//
$this->update_rates($shipping_methods);
//
if ( $action == 'new' ) {
$shipping_method_order[$method_id] = $method_id;
update_option( $this->shipping_method_order_option, $shipping_method_order );
}
if ( $action == 'new' ) {
$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 );
exit;
}
if ( $action == 'edit' ) {
$redirect = add_query_arg( array('updated' => $method_id, 'action' => false, 'method_id' => false ));
$redirect .= '#method_' . $method_id;
}
}
else {
if ( isset( $_POST['import_action'] ) && $_POST['import_action'] == '1' ) {
$tmp_name = $_FILES['import_file']['tmp_name'];
$shipping_methods = get_option( $this->shipping_methods_option, array() );
try {
$importer = new WPDesk_Flexible_Shipping_Csv_Importer( $this );
$shipping_methods = $importer->import( $tmp_name, $shipping_methods );
update_option( $this->shipping_methods_option, $shipping_methods );
} catch ( Exception $e ) {
WC_Admin_Settings::add_message( $e->getMessage() );
}
WC_Admin_Settings::show_messages();
}
else {
parent::process_admin_options();
if ( isset( $_POST['method_order'] ) ) {
update_option( $this->shipping_method_order_option, $_POST['method_order'] );
}
}
}
}
public function get_shipping_method_form( $shipping_method ) {
$this->form_fields = include( 'settings/shipping-method-form.php' );
}
public function admin_options() {
?>
<table class="form-table">
<?php
$action = false;
if ( isset( $_GET['action'] ) )
{
$action = $_GET['action'];
}
if ( $action == 'new' || $action == 'edit' ) {
$shipping_methods = get_option( $this->shipping_methods_option, array() );
$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 = $_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 = $_GET['added'];
$shipping_methods = get_option( $this->shipping_methods_option, array() );
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->generate_settings_html( $this->get_shipping_method_form($shipping_method) );
}
else if ( $action == 'delete' ) {
$methods_id = '';
if ( isset( $_GET['methods_id'] ) ) {
$methods_id = explode( ',' , $_GET['methods_id'] );
}
$shipping_methods = get_option( $this->shipping_methods_option, array() );
$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 = $_GET['added'];
$shipping_methods = get_option( $this->shipping_methods_option, array() );
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 = $_GET['updated'];
$shipping_methods = get_option( $this->shipping_methods_option, array() );
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>
<script type="text/javascript">
if ( typeof window.history.pushState == 'function' ) {
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,'?');
window.history.pushState({}, "", url);
}
</script>
<?php do_action( 'flexible_shipping_method_script' ); ?>
<?php
}
private function package_subtotal( $items ) {
$subtotal = 0;
foreach( $items as $item )
$subtotal += $item['line_subtotal'];
return $subtotal;
}
public function package_weight( $items ) {
$weight = 0;
foreach( $items as $item ) {
$weight += $item['data']->weight * $item['quantity'];
}
return $weight;
}
/**
* Get cart weight.
* It rounds return value to declared precision.
*
* @return float
*/
public function cart_weight() {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
add_filter( 'woocommerce_product_weight', array( $this, 'woocommerce_product_weight' ) );
}
$cart_weight = WC()->cart->get_cart_contents_weight();
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
remove_filter( 'woocommerce_product_weight', array( $this, 'woocommerce_product_weight' ) );
}
return round( $cart_weight, apply_filters( 'flexible_shipping_weight_rounding_precision', self::WEIGHT_ROUNDING_PRECISION ) );
}
/* Fix for Woocommerce 2.6 weight calculation */
/* PHP Warning: A non-numeric value encountered in /wp-content/plugins/woocommerce/includes/class-wc-cart.php on line 359 */
public function woocommerce_product_weight( $weight ) {
if ( $weight === '' ) {
return 0;
}
return $weight;
}
public function package_item_count( $items ) {
$item_count = 0;
foreach( $items as $item ) {
$item_count += $item['quantity'];
}
return $item_count;
}
public function cart_item_count() {
$item_count = 0;
$cart = WC()->cart;
foreach( $cart->cart_contents as $item ) {
$item_count += $item['quantity'];
}
return $item_count;
}
function calculate_method_cost( $shipping_method, $rule_costs ) {
$cost = 0;
if ( $shipping_method['method_calculation_method'] == 'sum' ) {
$cost = 0;
foreach ( $rule_costs as $rule_cost ) {
$cost += $rule_cost['cost'];
}
}
return $cost;
}
public function cart_display_prices_including_tax() {
if ( version_compare( WC_VERSION, '3.3', '<' ) ) {
$display_prices_including_tax = 'incl' === WC()->cart->tax_display_cart;
}
else {
$display_prices_including_tax = WC()->cart->display_prices_including_tax();
}
return $display_prices_including_tax;
}
/**
* @return int
*/
public function contents_cost_with_tax() {
$display_prices_including_tax = $this->cart_display_prices_including_tax();
if ( $display_prices_including_tax ) {
$total = WC()->cart->get_displayed_subtotal();
}
else {
if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
$total = WC()->cart->subtotal;
}
else {
$total = WC()->cart->get_displayed_subtotal() + WC()->cart->get_subtotal_tax();
}
}
if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
$total_discount = WC()->cart->discount_cart + WC()->cart->discount_cart_tax;
}
else {
$total_discount = WC()->cart->get_cart_discount_total() + WC()->cart->get_cart_discount_tax_total();
}
$total = round( $total - $total_discount, wc_get_price_decimals() );
return $total;
}
/**
* @return int
*/
public function contents_cost_without_tax() {
$display_prices_including_tax = $this->cart_display_prices_including_tax();
$total = WC()->cart->get_displayed_subtotal();
if ( $display_prices_including_tax ) {
if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
$total = WC()->cart->subtotal_ex_tax;
}
else {
$total = $total - WC()->cart->get_subtotal_tax();
}
}
if ( version_compare( WC_VERSION, '3.2', '<' ) ) {
$discount_without_tax = WC()->cart->discount_cart;
}
else {
$discount_without_tax = WC()->cart->get_cart_discount_total();
}
$total = round( $total - $discount_without_tax, wc_get_price_decimals() );
return $total;
}
public function prices_include_tax() {
if ( version_compare( WC_VERSION, '3.3', '<' ) ) {
$prices_include_tax = 'incl' === WC()->cart->tax_display_cart;
}
else {
$prices_include_tax = WC()->cart->display_prices_including_tax();
}
return apply_filters( 'flexible_shipping_prices_include_tax', $prices_include_tax );
}
/**
* Is free shipping?
*
* @param array $shipping_method_settings Flexible shipping method settings.
* @param float $cart_contents_cost Cart contents cost.
*
* @return bool
*/
public function is_free_shipping( array $shipping_method_settings, $cart_contents_cost ) {
if ( isset( $shipping_method_settings[ self::FIELD_METHOD_FREE_SHIPPING ] ) && '' !== $shipping_method_settings[ self::FIELD_METHOD_FREE_SHIPPING ] ) {
$shipping_method_settings[self::FIELD_METHOD_FREE_SHIPPING] = trim( $shipping_method_settings[self::FIELD_METHOD_FREE_SHIPPING] );
if ( '0' !== $shipping_method_settings[self::FIELD_METHOD_FREE_SHIPPING] && is_numeric( $shipping_method_settings[self::FIELD_METHOD_FREE_SHIPPING] ) ) {
if ( apply_filters( 'flexible_shipping_value_in_currency', floatval( $shipping_method_settings[self::FIELD_METHOD_FREE_SHIPPING] ) ) <= floatval( $cart_contents_cost ) ) {
return true;
}
}
}
return false;
}
/**
* Calculate contents cost.
*
* @return float
*/
public function contents_cost() {
if ( $this->prices_include_tax() ) {
return $this->contents_cost_with_tax();
} else {
return $this->contents_cost_without_tax();
}
}
/**
* @param array $package
*/
public function calculate_shipping( $package = array() ) {
$cart_contents_cost = 0;
$processed = apply_filters( 'flexible_shipping_calculate_shipping', false, $this, $package, 0 );
if ( $processed === false ) {
$shipping_methods = $this->get_shipping_methods( true );
foreach ( $shipping_methods as $shipping_method ) {
$rule_costs = array();
$add_method = false;
if ( isset( $shipping_method['method_visibility'] ) && $shipping_method['method_visibility'] == 'yes' && !is_user_logged_in() ) {
/* only for logged in */
continue;
}
foreach ( $shipping_method['method_rules'] as $rule_key => $method_rule ) {
$rule_triggered = false;
if ( $method_rule['based_on'] == 'none' ) {
$rule_triggered = true;
}
$contents_cost = $this->contents_cost();
$cart_contents_cost = $contents_cost;
if ( $method_rule['based_on'] == 'value' ) {
if ( trim( $method_rule['min'] ) == '' ) {
$min = 0;
}
else {
$min = floatval( apply_filters( 'flexible_shipping_value_in_currency', floatval( $method_rule['min'] ) ) );
}
if ( trim( $method_rule['max'] ) == '' ) {
$max = INF;
}
else {
$max = floatval( apply_filters( 'flexible_shipping_value_in_currency', floatval( $method_rule['max'] ) ) );
}
if ( $contents_cost >= $min && $contents_cost <= $max ) {
$rule_triggered = true;
}
}
if ( $method_rule['based_on'] == 'weight' ) {
if ( trim( $method_rule['min'] ) == '' ) {
$min = 0;
}
else {
$min = floatval( $method_rule['min'] );
}
if ( trim( $method_rule['max'] ) == '' ) {
$max = INF;
}
else {
$max = floatval( $method_rule['max'] );
}
$contents_weight = floatval( $this->cart_weight() );
if ( $contents_weight >= $min && $contents_weight <= $max ) {
$rule_triggered = true;
}
}
if ( $rule_triggered ) {
$rule_triggered = apply_filters( 'flexible_shipping_rule_triggered', $rule_triggered, $method_rule, $package );
}
if ( $rule_triggered ) {
$rule_cost = array( 'cost' => floatval( $method_rule['cost_per_order'] ) );
$rule_costs[$rule_key] = $rule_cost;
$add_method = true;
}
}
$cost = $this->calculate_method_cost( $shipping_method, $rule_costs );
$add_method = apply_filters( 'flexible_shipping_add_method' , $add_method, $shipping_method, $package, $this );
if ( $add_method === true ) {
if ( $this->is_free_shipping( $shipping_method, $cart_contents_cost ) ) {
$cost = 0;
}
$method_title = wpdesk__( $shipping_method['method_title'], 'flexible-shipping' );
if ( version_compare( WC()->version, '2.6' ) >= 0 ) {
if ( $cost == 0 ) {
if ( ! isset( $shipping_method['method_free_shipping_label'] ) ) {
$shipping_method['method_free_shipping_label'] = __( 'Free', 'flexible-shipping' );
}
if ( $shipping_method['method_free_shipping_label'] != '' ) {
$method_title .= ' (' . wpdesk__( $shipping_method['method_free_shipping_label'], 'flexible-shipping' ) . ')';
}
}
}
$id = $this->id . '_' . $this->instance_id . '_' . sanitize_title( $shipping_method['method_title'] );
$id = apply_filters( 'flexible_shipping_method_rate_id', $id, $shipping_method );
$this->add_rate( array(
'id' => $id,
'label' => $method_title,
'cost' => $cost,
'method' => $shipping_method,
'rule_costs' => $rule_costs,
'meta_data' => array(
self::META_DEFAULT => $shipping_method['method_default'],
'_fs_method' => $shipping_method
)
) );
if ( isset( $shipping_method['method_description'] ) ) {
WC()->session->set('flexible_shipping_description_' . $id, wpdesk__( $shipping_method['method_description'], 'flexible-shipping' ) );
}
else {
WC()->session->set( 'flexible_shipping_description_' . $id, '' );
}
}
}
}
}
public function is_available( $package ) {
return parent::is_available( $package );
}
public function get_all_rates() {
if ( class_exists( 'WC_Shipping_Zones' ) ) {
$zones = WC_Shipping_Zones::get_zones();
$zone0 = WC_Shipping_Zones::get_zone(0);
$zones[0] = $zone0->get_data();
$zones[0]['formatted_zone_location'] = $zone0->get_formatted_location();
$zones[0]['shipping_methods'] = $zone0->get_shipping_methods();
$rates = array();
foreach ( $zones as $zone ) {
foreach ( $zone['shipping_methods'] as $instance_id => $woo_shipping_method ) {
if ( $woo_shipping_method->id == $this->id ) {
$shipping_methods = $woo_shipping_method->get_shipping_methods();
foreach ( $shipping_methods as $shipping_method ) {
$id = $this->id . '_' . $woo_shipping_method->instance_id . '_' . sanitize_title($shipping_method['method_title'] );
$id = apply_filters( 'flexible_shipping_method_rate_id', $id, $shipping_method );
$shipping_method['instance_id'] = $woo_shipping_method->instance_id;
$rates[$id] = $shipping_method;
}
}
}
}
}
else {
$shipping_methods = $this->get_shipping_methods();
$rates = array();
foreach ( $shipping_methods as $shipping_method ) {
$id = $this->id . '_' . $this->instance_id . '_' . sanitize_title($shipping_method['method_title'] );
$id = apply_filters( 'flexible_shipping_method_rate_id', $id, $shipping_method );
$rates[$id] = $shipping_method;
}
}
return $rates;
}
public function get_method_from_rate( $rate_id ) {
$rates = $this->get_all_rates();
return $rates[$rate_id];
}
public function generate_header_html( $key, $data ) {
$field_key = $this->get_field_key( $key );
$defaults = array(
'title' => '',
'class' => '',
);
$data = wp_parse_args( $data, $defaults );
return sprintf( '<tr><td colspan="2"><h4 class="%1$s" id="%2$s">%3$s</h4></td></tr>', esc_attr( $data['class'] ), esc_attr( $field_key ), esc_html( $data['title'] ) );
}
/**
* Generate SaaS connection error field HTML.
*
* @param string $key
* @param array $data
*
* @return string
*/
public function generate_saas_connection_error_html( $key, $data ) {
$field_key = $this->get_field_key( $key );
$defaults = array(
'title' => '',
'class' => '',
);
$data = wp_parse_args( $data, $defaults );
return sprintf( '<tr><td></td><td><span class="%1$s" id="%2$s">%3$s</span></td></tr>', esc_attr( $data['class'] ), esc_attr( $field_key ), $data['description'] );
}
/**
* Generate custom_services field HTML.
*
* @param string $key
* @param array $data
*
* @return string
*/
public function generate_custom_services_html( $key, $data ) {
$field_key = $this->get_field_key( $key );
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'css' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array(),
'services' => array()
);
$data = wp_parse_args( $data, $defaults );
ob_start();
$services = $data['services'];
include ( 'views/html-custom-services.php' );
return ob_get_clean();
}
}
}

View File

@@ -0,0 +1,24 @@
<div class="flexible-shipping-pro-box">
<div class="metabox-holder">
<div class="stuffbox">
<h3 class="hndle"><?php _e( 'Get Flexible Shipping PRO!', 'flexible-shipping' ); ?></h3>
<?php
$fs_link = get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/sklep/flexible-shipping-pro-woocommerce/' : 'https://flexibleshipping.com/table-rate/';
?>
<div class="inside">
<div class="main">
<ul>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Shipping Classes support', 'flexible-shipping' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Product count based costs', 'flexible-shipping' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Stopping, Cancelling a rule', 'flexible-shipping' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Additional calculation methods', 'flexible-shipping' ); ?></li>
</ul>
<a class="button button-primary" href="<?php echo $fs_link; ?>?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=button&utm_term=upgrade-now&utm_content=fs-shippingzone-upgradenow" target="_blank"><?php _e( 'Upgrade Now &rarr;', 'flexible-shipping' ); ?></a>
</div>
</div>
</div>
</div>
</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,20 @@
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<div class="shipping">
<div class="shipping-status">
<a class="icon-status icon-status-<?php echo $shipping['status']; ?> tips" href="<?php echo $shipping['url']; ?>" data-tip="<?php echo esc_html( $statuses[$shipping['status']] ); ?>">
<?php echo esc_html( $statuses[$shipping['status']] ); ?>
</a>
<?php do_action( 'flexible_shipping_shipping_status_html', $shipping ); ?>
</div>
<div class="shipping-actions order_actions">
<?php if ( !empty( $shipping['label_url'] ) ) : ?>
<a class="button tips get-label" target="_blank" href="<?php echo $shipping['label_url']; ?>" data-tip="<?php _e( 'Get label for: ', 'flexible-shipping' ); ?><?php echo $shipping['tracking_number']; ?>"><?php _e( 'Get label for: ', 'flexible-shipping' ); ?><?php echo $shipping['tracking_number']; ?></a>
<?php endif; ?>
<?php if ( !empty( $shipping['tracking_url'] ) ) : ?>
<a class="button tips track" target="_blank" href="<?php echo $shipping['tracking_url']; ?>" data-tip="<?php _e( 'Track shipment for: ', 'flexible-shipping' ); ?><?php echo $shipping['tracking_number']; ?>"><?php _e( 'Track shipment for: ', 'flexible-shipping' ); ?><?php echo $shipping['tracking_number']; ?></a>
<?php endif; ?>
<?php do_action( 'flexible_shipping_shipping_actions_html', $shipping ); ?>
</div>
<div style="clear: both;"></div>
<?php do_action( 'flexible_shipping_shipping_html', $shipping ); ?>
</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,19 @@
<?php ?>
<div class="alignleft actions">
<select name="flexible_shipping_integration_filter">
<option value=""><?php _e( 'All shippings', 'flexible-shipping' ); ?></option>
<optgroup label="<?php _e( 'Integration', 'flexible-shipping' ); ?>">
<?php foreach ( $integrations as $key => $val ) : ?>
<option value="<?php echo $key; ?>" <?php echo ($key == $integration ? 'selected' : '' ); ?>><?php echo $val; ?></option>
<?php endforeach; ?>
</optgroup>
</select>
<select name="flexible_shipping_status_filter">
<option value=""><?php _e( 'All shippings', 'flexible-shipping' ); ?></option>
<optgroup label="<?php _e( 'Shipment status', 'flexible-shipping' ); ?>">
<?php foreach ( $statuses as $key => $val ) : ?>
<option value="<?php echo $key; ?>" <?php echo ($key == $status ? 'selected' : '' ); ?>><?php echo $val; ?></option>
<?php endforeach; ?>
</optgroup>
</select>
</div>

View File

@@ -0,0 +1,249 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
$field = $this->get_field_key( $key );
$options_based_on = apply_filters( 'flexible_shipping_method_rule_options_based_on', array(
'none' => __( 'None', 'flexible-shipping' ),
'value' => __( 'Price', 'flexible-shipping' ),
'weight' => __( 'Weight', 'flexible-shipping' ),
));
$key = 'method_rules[xxx][based_on]';
$args = array(
'type' => 'select',
'options' => $options_based_on,
'return' => true,
);
$value = 'none';
$field_based_on = woocommerce_form_field( $key, $args, $value );
$key = 'method_rules[xxx][min]';
$args = array(
'type' => 'text',
'return' => true,
'input_class' => array( 'wc_input_price' ),
);
$value = '';
$field_min = woocommerce_form_field( $key, $args, wc_format_localized_price( $value ) );
$key = 'method_rules[xxx][max]';
$args = array(
'type' => 'text',
'return' => true,
'input_class' => array( 'wc_input_price' ),
);
$value = '';
$field_max = woocommerce_form_field( $key, $args, wc_format_localized_price( $value ) );
$key = 'method_rules[xxx][cost_per_order]';
$args = array(
'type' => 'text',
'return' => true,
'input_class' => array( 'wc_input_price' ),
);
$value = '';
$field_cost_per_order = woocommerce_form_field( $key, $args, wc_format_localized_price( $value ) );
$count_rules = 0;
?>
<tr valign="top" class="flexible_shipping_method_rules">
<th class="forminp" colspan="2">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo $data['title']; ?></label>
<?php
$fs_pro_link = get_locale() === 'pl_PL' ? 'https://www.wpdesk.pl/sklep/flexible-shipping-pro-woocommerce/' : 'https://flexibleshipping.com/table-rate/';
if ( ! in_array( 'flexible-shipping-pro/flexible-shipping-pro.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ):
?>
<p><?php printf( __( 'Check %sFlexible Shipping PRO &rarr;%s to add advanced rules based on shipment classes, product/item count or additional handling fees/insurance.', 'flexible-shipping' ), '<a href="' . $fs_pro_link . '?utm_campaign=flexible-shipping&utm_source=user-site&utm_medium=link&utm_term=flexible-shipping-pro&utm_content=fs-shippingzone-addnew-rules" target="_blank">', '</a>' ); ?></p>
<?php endif; ?>
</th>
</tr>
<tr valign="top" class="flexible_shipping_method_rules">
<td colspan="2" style="padding:0;">
<table id="<?php echo esc_attr( $field ); ?>" class="flexible_shipping_method_rules wc_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th class="based_on">
<?php _e( 'Based on', 'flexible-shipping' ); ?>
<span class="woocommerce-help-tip" data-tip="<?php _e( 'Shipping cost will be calculated based on the selected parameter.', 'flexible-shipping' ); ?>"></span>
</th>
<th class="min">
<?php _e( 'Min', 'flexible-shipping' ); ?>
<span class="woocommerce-help-tip" data-tip="<?php _e( 'Enter minimum value for the &quot;Based on&quot; parameter. Value based on the price will be calculated by WooCommerce tax settings &quot;Display prices during cart and checkout&quot;', 'flexible-shipping' ); ?>"></span>
</th>
<th class="max">
<?php _e( 'Max', 'flexible-shipping' ); ?>
<span class="woocommerce-help-tip" data-tip="<?php _e( 'Enter maximum value for the &quot;Based on&quot; parameter. Value based on the price will be calculated by WooCommerce tax settings &quot;Display prices during cart and checkout&quot;', 'flexible-shipping' ); ?>"></span>
</th>
<th class="cost_per_order">
<?php _e( 'Cost per<br/>order', 'flexible-shipping' ); ?>
<span class="woocommerce-help-tip" data-tip="<?php _e( 'Enter shipment cost for this rule.', 'flexible-shipping' ); ?>"></span>
</th>
<?php do_action( 'flexible_shipping_method_rule_thead', '' ); ?>
</tr>
</thead>
<tbody>
<?php if ( isset( $data['default'] ) ) : ?>
<?php foreach ( $data['default'] as $key => $rule ) : $count_rules++; ?>
<tr>
<td class="sort"></td>
<td class="based_on">
<?php
$key = 'method_rules[' . $count_rules . '][based_on]';
$args = array(
'type' => 'select',
'options' => $options_based_on,
);
$value = '';
if ( isset( $rule['based_on'] ) ) {
$value = $rule['based_on'];
}
woocommerce_form_field( $key, $args, $value );
?>
</td>
<td class="min">
<?php
$key = 'method_rules[' . $count_rules . '][min]';
$args = array(
'type' => 'text',
'input_class' => array( 'wc_input_price' ),
);
$value = '';
if ( isset( $rule['min'] ) ) {
$value = $rule['min'];
}
woocommerce_form_field( $key, $args, wc_format_localized_price( $value ) );
?>
</td>
<td class="max">
<?php
$key = 'method_rules[' . $count_rules . '][max]';
$args = array(
'type' => 'text',
'input_class' => array( 'wc_input_price' ),
);
$value = '';
if ( isset( $rule['max'] ) ) {
$value = $rule['max'];
}
woocommerce_form_field( $key, $args, wc_format_localized_price( $value ) );
?>
</td>
<td class="cost_per_order">
<?php
$key = 'method_rules[' . $count_rules . '][cost_per_order]';
$args = array(
'type' => 'text',
'input_class' => array( 'wc_input_price' ),
);
$value = '';
if ( isset( $rule['cost_per_order'] ) ) {
$value = $rule['cost_per_order'];
}
woocommerce_form_field( $key, $args, wc_format_localized_price( $value ) );
?>
</td>
<?php do_action( 'flexible_shipping_method_rule_row', $rule, $count_rules ); ?>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<th colspan="99">
<a id="insert_rule" href="#" class="button plus insert"><?php _e( 'Insert rule', 'flexible-shipping' ); ?></a>
<a id="remove_rules" href="#" class="button minus"><?php _e( 'Delete selected rules', 'flexible-shipping' ); ?></a>
</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
function append_row( id ) {
var code = '<tr class="new">\
<td class="sort"></td>\
<td class="based_on">\
<?php echo str_replace( "'", '"', str_replace( "\r", "", str_replace( "\n", "", $field_based_on ) ) ); ?> \
</td>\
<td class="min">\
<?php echo str_replace( "'", '"', str_replace( "\r", "", str_replace( "\n", "", $field_min ) ) ); ?> \
</td>\
<td class="max">\
<?php echo str_replace( "'", '"', str_replace( "\r", "", str_replace( "\n", "", $field_max ) ) ); ?> \
</td>\
<td class="cost_per_order">\
<?php echo str_replace( "'", '"', str_replace( "\r", "", str_replace( "\n", "", $field_cost_per_order ) ) ); ?> \
</td>\
<?php do_action( 'flexible_shipping_method_rule_js', '' ); ?>
</tr>';
var code2 = code.replace(/xxx/g, id );
var $tbody = jQuery('#<?php echo esc_attr( $field ); ?>').find('tbody');
$tbody.append( code2 );
}
jQuery(document).ready(function() {
var tbody = jQuery('#<?php echo esc_attr( $field ); ?>').find('tbody');
var append_id = <?php echo $count_rules ?>;
var size = tbody.find('tr').size();
if ( size == 0 ) {
append_id = append_id+1;
append_row(append_id);
jQuery('#insert_rule').trigger( 'insert_rule' , [append_id] );
}
jQuery('#insert_rule').click(function() {
append_id = append_id+1;
append_row(append_id);
jQuery('#rules_'+append_id+'_min').focus();
jQuery('#insert_rule').trigger( 'insert_rule' , [append_id] );
return false;
});
jQuery('#remove_rules').click(function() {
if ( current = tbody.children( '.current' ) ) {
current.each(function() {
jQuery(this).remove();
});
} else {
alert( '<?php _e( 'No rows selected.' , 'flexible-shipping' ); ?>' );
}
return false;
});
jQuery(document).on('click', '.delete_rule', function() {
if (confirm('<?php _e( 'Are you sure?' , 'flexible-shipping' ); ?>')) {
jQuery(this).closest('tr').remove();
}
return false;
});
jQuery('#mainform').attr('action', '<?php echo remove_query_arg( 'added', add_query_arg( 'added', '1' ) ); ?>' );
});
</script>
<?php
if( version_compare( WC()->version, '2.6.0', ">=" ) ) {
?>
<script type="text/javascript">
<?php
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $_GET['instance_id'] );
$shipping_method_woo = WC_Shipping_Zones::get_shipping_method( $_GET['instance_id'] );
$content = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping' ) . '">' . __( 'Shipping Zones', 'woocommerce' ) . '</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=' . $_GET['instance_id'] ) . '">' . esc_html( $shipping_method_woo->get_title() ) . '</a>';
if ( isset( $data['method_title'] ) && $data['method_title'] != '' ) {
$content .= ' &gt ';
$content .= esc_html( $data['method_title'] );
}
else {
$content .= ' &gt ';
$content .= __( 'Add New', 'flexible-shipping' );
}
?>
jQuery('#mainform h2').first().replaceWith( '<h2>' + '<?php echo $content; ?>' + '</h2>' );
</script>
<?php
}
?>
</td>
</tr>

View File

@@ -0,0 +1,205 @@
<?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 _e( 'Title', 'flexible-shipping' ); ?></th>
<th class="status"><?php _e( 'Enabled', 'flexible-shipping' ); ?></th>
<th class="visibility"><?php _e( 'Visibility', 'flexible-shipping' ); ?></th>
<th class="default"><?php _e( 'Default', 'flexible-shipping' ); ?></th>
<th class="integration"><?php _e( 'Integration', 'flexible-shipping' ); ?></th>
<th class="select"><input type="checkbox" class="tips checkbox-select-all" value="1" data-tip="<?php _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 ) : $shipping_method = $shipping_methods[$shipping_method_id]; ?>
<?php $tr_class = ''; ?>
<?php if ( isset( $_GET['added'] ) && $_GET['added'] == $shipping_method_id ) $tr_class = 'highlight'; ?>
<?php if ( isset( $_GET['updated'] ) && $_GET['updated'] == $shipping_method_id ) $tr_class = 'highlight'; ?>
<tr id="method_<?php echo $shipping_method_id; ?>" class="<?php echo $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 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 _e( 'yes', 'flexible-shipping' ); ?>"><?php _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 _e( 'Show only for logged in users', 'flexible-shipping' ); ?>"><?php _e( 'yes', 'flexible-shipping' ); ?></span>
<?php else : ?>
<span class="na tips" data-tip="<?php _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 _e( 'yes', 'flexible-shipping' ); ?>"><?php _e( 'yes', 'flexible-shipping' ); ?></span>
<?php else : ?>
<span class="na">-</span>
<?php endif; ?>
</td>
<?php echo apply_filters( 'flexible_shipping_method_integration_col', '<td width="1%" class="integration default">-</td>', $shipping_method );?>
<td width="1%" class="select" 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 _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 _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" />
<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 _e( 'Cancel import', 'flexible-shipping' ); ?></button>
<input id="flexible_shipping_do_import" style="display:none;" class="button button-primary" data-instance-id="<?php echo isset( $_GET['instance_id'] ) ? $_GET['instance_id'] : '1'; ?>" data-nonce="<?php echo wp_create_nonce( "flexible_shipping" ); ?>" type="submit" value="<?php _e( 'Import', 'flexible-shipping' ); ?>" />
<button id="flexible_shipping_import" class="button" data-instance-id="<?php isset( $_GET['instance_id'] ) ? $_GET['instance_id'] : '1'; ?>" data-nonce="<?php echo wp_create_nonce( "flexible_shipping" ); ?>" ><?php _e( 'Import', 'flexible-shipping' ); ?></button>
<?php do_action( 'flexible_shipping_actions_row' ); ?>
</div>
<div style="clear:both;"></div>
</th>
</tr>
</tfoot>
</table>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
if ( ! wpdesk_is_plugin_active( 'flexible-shipping-pro/flexible-shipping-pro.php' ) )
include( 'html-ads.php' );
?>
<script type="text/javascript">
<?php
if( version_compare( WC()->version, '2.6.0', ">=" ) ) :
?>
<?php
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $_GET['instance_id'] );
$shipping_method_woo = WC_Shipping_Zones::get_shipping_method( $_GET['instance_id'] );
$content = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping' ) . '">' . __( 'Shipping Zones', 'woocommerce' ) . '</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 .= esc_html( $shipping_method_woo->get_title() );
?>
jQuery('#mainform h2').first().replaceWith( '<h2>' + '<?php echo $content; ?>' + '</h2>' );
<?php
global $wp;
$current_url = 'admin.php?page=wc-settings&tab=shipping&instance_id=' . $_GET['instance_id'];
?>
jQuery('#mainform').attr('action', '<?php echo $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 url = '<?php echo add_query_arg( 'methods_id' , '', add_query_arg( 'action', 'delete' ) ); ?>';
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 _e( 'Please select shipment methods to remove', 'flexible-shipping' ); ?>' );
return false;
}
if ( url != '<?php echo add_query_arg( 'method_id' , '', add_query_arg( 'action', 'delete' ) ); ?>' ) {
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 _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'] ) && $_POST['import_action'] == '1' ) {
?>
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,55 @@
<?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>
</div>
</div>
<table>

View File

@@ -0,0 +1,101 @@
<?php
/**
* 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;
/**
* 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' ) );
}
/**
* 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 ( 'flexible_shipping' === $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 ) {
update_option( self::OPTION_FS_METHOD_CREATED_TRACKER, self::FLEXIBLE_SHIPPING_METHOD_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,237 @@
<?php
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Handle Tracker actions and filrers.
*
* Class WPDesk_Flexible_Shipping_Tracker
*/
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';
/**
* 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', array( $this, 'wpdesk_tracker_data_flexible_shipping' ), 11 );
add_filter( 'wpdesk_tracker_notice_screens', array( $this, 'wpdesk_tracker_notice_screens' ) );
add_filter( self::PLUGIN_ACTION_LINKS_FILTER_NAME, array( $this, 'plugin_action_links' ) );
}
/**
* 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'] = array();
$data['flexible_shipping']['total_shipping_methods'] = 0;
$data['flexible_shipping']['avg_rules'] = 0;
$data['flexible_shipping']['max_rules'] = 0;
$data['flexible_shipping']['integrations'] = array();
$data['flexible_shipping']['free_shipping_requires'] = array();
$data['flexible_shipping']['calculation_methods'] = array();
$data['flexible_shipping']['based_on'] = array();
$data['flexible_shipping']['shipping_class_option'] = array();
$data['flexible_shipping']['method_description_count'] = 0;
$data['flexible_shipping']['free_shipping_label_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 $flexible_shipping_rate ) {
$data['flexible_shipping']['total_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['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'] ++;
}
foreach ( $flexible_shipping_rate['method_rules'] as $method_rule ) {
if ( empty( $data['flexible_shipping']['based_on'][ $method_rule['based_on'] ] ) ) {
$data['flexible_shipping']['based_on'][ $method_rule['based_on'] ] = 0;
}
$data['flexible_shipping']['based_on'][ $method_rule['based_on'] ] ++;
if ( ! empty( $method_rule['shipping_class'] ) ) {
$shipping_class = $method_rule['shipping_class'];
if ( ! in_array( $shipping_class, array( 'all', 'any', 'none' ), true ) ) {
$shipping_class = 'shipping_class';
}
if ( empty( $data['flexible_shipping']['shipping_class_option'][ $shipping_class ] ) ) {
$data['flexible_shipping']['shipping_class_option'][ $shipping_class ] = 0;
}
$data['flexible_shipping']['shipping_class_option'][ $shipping_class ] ++;
}
if ( ! empty( $method_rule['cost_additional'] ) ) {
$data['flexible_shipping']['additional_cost_count'] ++;
}
if ( ! empty( $method_rule['min'] ) ) {
$data['flexible_shipping']['min_count'] ++;
}
if ( ! empty( $method_rule['max'] ) ) {
$data['flexible_shipping']['max_count'] ++;
}
if ( ! empty( $method_rule['cost_per_order'] ) ) {
$data['flexible_shipping']['cost_per_order_count'] ++;
}
if ( ! empty( $method_rule['stop'] ) ) {
$data['flexible_shipping']['stop_count'] ++;
}
if ( ! empty( $method_rule['cancel'] ) ) {
$data['flexible_shipping']['cancel_count'] ++;
}
}
}
if ( 0 !== intval( $data['flexible_shipping']['total_shipping_methods'] ) ) {
$data['flexible_shipping']['avg_rules'] = $data['flexible_shipping']['avg_rules'] / $data['flexible_shipping']['total_shipping_methods'];
}
return $data;
}
/**
* Tracker notice screens.
*
* @param array $screens Screens.
*
* @return array
*/
public function wpdesk_tracker_notice_screens( $screens ) {
$current_screen = get_current_screen();
if ( 'woocommerce_page_wc-settings' === $current_screen->id ) {
if ( isset( $_GET['tab'] ) && 'shipping' === $_GET['tab'] ) {
$screens[] = $current_screen->id;
}
}
return $screens;
}
/**
* Add action links.
*
* @param array $links Links.
*
* @return array
*/
public function plugin_action_links( $links ) {
if ( ! wpdesk_tracker_enabled() || apply_filters( 'wpdesk_tracker_do_not_ask', false ) ) {
return $links;
}
$options = get_option( 'wpdesk_helper_options', array() );
if ( ! is_array( $options ) ) {
$options = array();
}
if ( empty( $options['wpdesk_tracker_agree'] ) ) {
$options['wpdesk_tracker_agree'] = '0';
}
$plugin_links = array();
if ( '0' === $options['wpdesk_tracker_agree'] ) {
$opt_in_link = admin_url( 'admin.php?page=wpdesk_tracker&plugin=' . self::FLEXIBLE_SHIPPING_PLUGIN_FILE );
$plugin_links[] = '<a href="' . $opt_in_link . '">' . __( 'Opt-in', 'flexible-shipping' ) . '</a>';
} else {
$opt_in_link = admin_url( 'plugins.php?wpdesk_tracker_opt_out=1&plugin=' . self::FLEXIBLE_SHIPPING_PLUGIN_FILE );
$plugin_links[] = '<a href="' . $opt_in_link . '">' . __( 'Opt-out', 'flexible-shipping' ) . '</a>';
}
return array_merge( $plugin_links, $links );
}
}
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,237 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Admin_Notices' ) ) {
class WPDesk_Flexible_Shipping_Admin_Notices {
/**
*
*/
const SETTINGS_CHECKED_OPTION_NAME = 'flexible_shipping_smsc';
/**
*
*/
const SETTINGS_CHECKED_OPTION_NAME_DISMISS = 'flexible_shipping_smsc_dismiss';
/**
*
*/
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_Export constructor.
*
* @param Flexible_Shipping_Plugin $plugin
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
*
*/
private function hooks() {
//add_action( 'admin_notices', array( $this, 'admin_notices_plugin_versions' ) );
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' ) );
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_woo_fs' ) );
add_action( 'admin_notices', array( $this, 'admin_notices_taxes' ) );
add_action( 'wp_ajax_flexible_shipping_taxes_notice', array( $this, 'wp_ajax_flexible_shipping_taxes_notice' ) );
}
/**
*
*/
public function wp_ajax_flexible_shipping_taxes_notice() {
update_option( self::SETTINGS_CHECKED_OPTION_NAME_DISMISS, 1 );
}
/**
* @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'] ) && $rule['based_on'] == self::BASED_ON_VALUE ) {
return true;
}
}
}
}
}
return false;
}
/**
*
*/
private function update_show_admin_notice_taxes_option() {
$has_value_based_rule = false;
$shipping_zones = WC_Shipping_Zones::get_zones();
$shipping_zones[0] = WC_Shipping_Zones::get_zone_by( 'zone_id', 0 );
foreach ( $shipping_zones as $zone_id => $shipping_zone_array ) {
$shipping_zone = WC_Shipping_Zones::get_zone( $zone_id );
/** @var WC_Shipping_Zone $shipping_zone */
$shipping_methods = $shipping_zone->get_shipping_methods();
foreach ( $shipping_methods as $shipping_method ) {
/** @var WC_Shipping_Method $shipping_method */
if ( $shipping_method->id == 'flexible_shipping' ) {
$has_value_based_rule = $has_value_based_rule || $this->has_value_based_rule( $shipping_method );
}
}
}
if ( $has_value_based_rule ) {
$shipping_methods_settings_checked = self::SETTINGS_CHECKED_OPTION_VALUE_SHOW_MESSAGE;
}
else {
$shipping_methods_settings_checked = self::SETTINGS_CHECKED_OPTION_VALUE_DO_NOT_SHOW_MESSAGE;
}
update_option( self::SETTINGS_CHECKED_OPTION_NAME, $shipping_methods_settings_checked );
}
/**
* @return bool
*/
public function is_show_admin_notice_taxes() {
$shipping_methods_settings_checked = get_option( self::SETTINGS_CHECKED_OPTION_NAME, '0' );
if ( $shipping_methods_settings_checked == '0' ) {
$this->update_show_admin_notice_taxes_option();
$shipping_methods_settings_checked = get_option( self::SETTINGS_CHECKED_OPTION_NAME, '0' );
}
return $shipping_methods_settings_checked == self::SETTINGS_CHECKED_OPTION_VALUE_SHOW_MESSAGE;
}
/**
* @return bool
*/
public function is_in_zones() {
if ( isset( $_GET['page'] ) && $_GET['page'] == 'wc-settings'
&& isset( $_GET['tab'] ) && $_GET['tab'] == 'shipping'
&& ( !isset( $_GET['section'] ) || $_GET['section'] == '' )
) {
return true;
}
return false;
}
/**
* @return bool
*/
public function is_admin_notice_taxes_dismissed() {
if ( get_option( self::SETTINGS_CHECKED_OPTION_NAME_DISMISS, '0' ) == '1' ) {
return true;
}
return false;
}
/**
*
*/
public function admin_notices_taxes() {
if ( wc_tax_enabled() && !$this->is_admin_notice_taxes_dismissed() && $this->is_show_admin_notice_taxes() ) {
$class = 'notice notice-error is-dismissible flexible-shipping-taxes-notice';
$message = sprintf(
__( 'Flexible Shipping has changed the calculation method for shipping rules. Currently, the cart value for rules based on price is determined by WooCommerce tax option "Display prices during cart and checkout". You should check the %ssettings%s.', 'flexible-shipping' ),
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=tax' ) . '">',
'</a>'
);
$this->print_notice( $class, $message );
}
}
/*
*
*/
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 );
}
}
}
/**
*
*/
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 );
}
}
}
/**
*
*/
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 Paczka w Ruchu plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/*
*
*/
public function admin_notices_plugin_woo_fs() {
if ( is_plugin_active( 'woo-flexible-shipping/flexible-shipping.php' ) ) {
$class = 'notice notice-error';
$message = sprintf( __( 'You are using WooCommerce Flexible Shipping below 1.4. Please deactivate it on %splugins page%s. Read about big changes in Flexible Shipping on %sour blog →%s', 'flexible-shipping' ), '<a href="' . admin_url('plugins.php') . '">', '</a>', '<a href="https://www.wpdesk.pl/blog/nowy-flexible-shipping/">', '</a>' );
$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 );
}
}
}

View File

@@ -0,0 +1,140 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Add_Shipping
*/
class WPDesk_Flexible_Shipping_Add_Shipping implements \FSVendor\WPDesk\PluginBuilder\Plugin\HookablePluginDependant {
use \FSVendor\WPDesk\PluginBuilder\Plugin\PluginAccess;
/**
* Shipping added?
*
* @var bool
*/
private $shipping_added = false;
/**
* Hooks.
*/
public function hooks() {
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 20, 2 );
add_action( 'admin_init', array( $this, 'handle_add_shipping' ) );
}
/**
* Add shipping.
*
* @param string $integration Integration.
*/
private function add_shipping( $integration ) {
$class_name = apply_filters( 'flexible_shipping_shipment_class', 'WPDesk_Flexible_Shipping_Shipment_' . $integration, $integration );
if ( class_exists( $class_name ) ) {
$order = wc_get_order( $_GET['post'] );
if ( $order ) {
$order_id = $order->get_id();
$integration = $_GET['fs_add_shipping'];
// Translators: order id and integration.
$post_title = sprintf( __( 'Shipment for order %1$s, %2$s', 'flexible-shipping' ), $order_id, $integration );
$shipment_post = array(
'post_title' => $post_title,
'post_type' => 'shipment',
'post_status' => 'fs-new',
'post_parent' => $order_id
);
$shipment_id = wp_insert_post( $shipment_post );
update_post_meta( $shipment_id, '_integration', $integration );
$shipment = fs_get_shipment( $shipment_id, $order );
$shipment->set_created_via_add_shipment();
if ( method_exists( $shipment, 'admin_add_shipment' ) ) {
$shipment->admin_add_shipment();
}
$shipment->save();
$order->add_order_note( sprintf( __( 'Added new shipment via metabox. Shipment ID: %s', 'flexible-shipping' ), $shipment->get_id() ) );
$this->shipping_added = true;
}
}
}
/**
* Handle add shipping.
*/
public function handle_add_shipping() {
if ( isset( $_GET['fs_add_shipping'] ) && isset( $_GET['post'] ) ) {
if ( isset( $_GET['_wpnonce'] ) ) {
if ( wp_verify_nonce( $_GET['_wpnonce'], 'fs_add_shipping' ) ) {
$integration = $_GET['fs_add_shipping'];
$this->add_shipping( $integration );
}
}
}
}
/**
* Add metabox.
*
* @param string $post_type Post type.
* @param WP_Post $post Post.
*/
public function add_meta_box( $post_type, $post ) {
if ( 'shop_order' === $post_type ) {
$add_metabox = false;
$order = wc_get_order( $post->ID );
$created_via = $order->get_created_via();
if ( 'checkout' !== $created_via ) {
$add_metabox = true;
}
if ( ! $add_metabox ) {
$order_shipping_methods = $order->get_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 ( $order_shipping_methods as $order_shipping_method ) {
/** @var WC_Order_Item_Shipping $order_shipping_method */
$fs_method = $order_shipping_method->get_meta( '_fs_method' );
if ( ! empty( $fs_method ) && isset( $flexible_shipping_rates[ $fs_method['id_for_shipping'] ] ) ) {
$add_metabox = true;
}
}
}
$select_options = array();
$select_options = apply_filters( 'flexible_shipping_add_shipping_options', $select_options );
if ( $add_metabox && count( $select_options ) ) {
$select_options = array_merge(
array( '' => __( 'Select integration', 'flexible-shipping' ) ),
$select_options
);
$args = array(
'select_options' => $select_options,
'order_id' => $post->ID,
);
add_meta_box(
'add_shipping_meta_box',
__( 'Add shipping', 'flexible-shipping' ),
array( $this, 'display_order_metabox' ),
'shop_order',
'side',
'default',
$args
);
}
}
}
/**
* Display order metabox.
*
* @param WP_Post $post Post.
* @param array $args Args.
*/
public function display_order_metabox( $post, $args ) {
$select_options = $args['args']['select_options'];
$order_id = $args['args']['order_id'];
$add_shipping_url = admin_url( 'post.php?post=' . $order_id . '&action=edit' );
$add_shipping_url = wp_nonce_url( $add_shipping_url, 'fs_add_shipping' );
$add_shipping_url = str_replace( '&amp;', '&', $add_shipping_url );
include 'views/html-order-add_shipping-metabox.php';
}
}

View File

@@ -0,0 +1,7 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Send_Shipment_Exception
*/
class WPDesk_Flexible_Shipping_Cancel_Shipment_Exception extends RuntimeException {
}

View File

@@ -0,0 +1,7 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Send_Shipment_Exception
*/
class WPDesk_Flexible_Shipping_Get_Label_Exception extends RuntimeException {
}

View File

@@ -0,0 +1,7 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Send_Shipment_Exception
*/
class WPDesk_Flexible_Shipping_Label_Not_Available_Exception extends RuntimeException {
}

View File

@@ -0,0 +1,7 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Send_Shipment_Exception
*/
class WPDesk_Flexible_Shipping_Send_Shipment_Exception extends RuntimeException {
}

View File

@@ -0,0 +1,7 @@
<?php
/**
* Class WPDesk_Flexible_Shipping_Send_Shipment_Exception
*/
class WPDesk_Flexible_Shipping_Shipment_Plan_Exceeded_Exception extends RuntimeException {
}

View File

@@ -0,0 +1,42 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WPDesk_Flexible_Shipping_Manifest_FS extends WPDesk_Flexible_Shipping_Manifest implements WPDesk_Flexible_Shipping_Manifest_Interface {
/**
* @return array
* Returns manifest data in array
* file_name => file name for manifest
* content => pdf content
*/
public function get_manifest() {
return null;
}
/**
* @return string
* Returns manifest number
*/
public function get_number() {
return null;
}
/**
* @return null
* Generates manifest (ie. in API)
*/
public function generate() {
return null;
}
/**
* @return null
* Cancels manifest (ie. in API)
*/
public function cancel() {
return null;
}
}

View File

@@ -0,0 +1,214 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Manifest' ) ) {
/**
* Class WPDesk_Flexible_Shipping_Shipment
*/
abstract class WPDesk_Flexible_Shipping_Manifest {
/**
* @var int
*/
private $id;
/**
* @var WP_Post
* Post assigned to manifest
*/
private $post;
/**
* @var bool
* True if assigned post ich changed. Used when saving post
*/
private $save_post = false;
/**
* @var null
* Holds old status when manifest status is changed
*/
private $old_status = null;
/**
* @var bool
* True when status changing
*/
private $status_changed = false;
/**
* @var array
* Manifest metadata (from postmeta table)
*/
private $meta_data = array();
/**
* @var bool
* True when manifest metadata loaded
*/
private $meta_data_loaded = false;
/**
* @var array
* Holds changed metadata keys. Used when saving manifest
*/
private $meta_data_save_keys = array();
/**
* WPDesk_Flexible_Shipping_Manifest constructor.
*
* @param int|WPDesk_Flexible_Shipping_Manifest|WP_Post $manifest Manifest.
* @param WC_Order|null $order Order.
*/
public function __construct( $manifest, $order = null ) {
if ( is_numeric( $manifest ) ) {
$this->id = absint( $manifest );
$this->post = get_post( $this->id );
} elseif ( $manifest instanceof WPDesk_Flexible_Shipping_Manifest ) {
$this->id = absint( $manifest->get_id() );
$this->post = $manifest->get_post();
} elseif ( isset( $manifest->ID ) ) {
$this->id = absint( $manifest->ID );
$this->post = $manifest;
}
$this->order = $order;
}
/**
* @return mixed
*/
public function get_id() {
return $this->id;
}
/**
* @return mixed
*/
public function get_post() {
return $this->post;
}
/**
* @param string $meta_key
* @param null|string $default
* @return array|string|null
*/
public function get_meta( $meta_key = '', $default = null ) {
$this->load_meta_data();
if ( $meta_key == '' ) {
return $this->meta_data;
}
if ( isset( $this->meta_data[$meta_key] ) ) {
return maybe_unserialize( $this->meta_data[$meta_key][0] );
}
else {
return $default;
}
}
/**
* @param string $meta_key
* @param int|string|array|object|null $value
*/
public function set_meta( $meta_key, $value ) {
$this->load_meta_data();
if ( !isset( $this->meta_data[$meta_key] ) ) {
$this->meta_data[$meta_key] = array();
}
$this->meta_data[$meta_key][0] = $value;
$this->meta_data_save_keys[$meta_key] = $meta_key;
}
/**
* @param string $meta_key
*/
public function delete_meta( $meta_key ) {
unset( $this->meta_data[$meta_key] );
$this->meta_data_save_keys[$meta_key] = $meta_key;
}
/**
* Saves manifest data to database.
*/
public function save() {
if ( $this->save_post ) {
wp_update_post($this->post);
$this->save_post = false;
}
foreach ( $this->meta_data_save_keys as $key ) {
if ( isset( $this->meta_data[$key] ) ) {
update_post_meta( $this->id, $key, $this->meta_data[$key][0] );
}
else {
delete_post_meta( $this->id, $key );
}
unset( $this->meta_data_save_keys[$key] );
}
if ( $this->status_changed ) {
do_action( 'flexible_shipping_manifest_status_updated', $this->old_status, $this->post->post_status, $this );
$this->status_changed = false;
$this->old_status = null;
}
}
/**
* Loads all meta data from postmeta
*/
public function load_meta_data() {
if ( !$this->meta_data_loaded ) {
$this->meta_data = get_post_meta( $this->id );
$this->meta_data_loaded = true;
}
}
/**
* @return array|null
* Returns integration assigned to manifest
*/
public function get_integration() {
return $this->get_meta( '_integration' );
}
/**
* @return string
*/
public function get_status() {
return $this->post->post_status;
}
public function get_date() {
return $this->post->post_date;
}
/**
* @param string $new_status
*/
public function update_status( $new_status ) {
$this->old_status = $this->post->post_status;
$this->post->post_status = $new_status;
$this->save_post = true;
$this->status_changed = true;
}
/**
* @param mixed $shipments
*/
public function add_shipments( $shipments ) {
if ( !is_array( $shipments ) ) {
$shipments = array( $shipments );
}
$shipments_ids = $this->get_meta( '_shipments', array() );
foreach ( $shipments as $shipment ) {
/* @var WPDesk_Flexible_Shipping_Shipment $shipment */
$shipment->add_to_manifest( $this );
$shipment->save();
$shipments_ids[] = $shipment->get_id();
}
$this->set_meta( '_shipments', $shipments_ids );
$this->save();
}
}
}

View File

@@ -0,0 +1,328 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WPDesk_Flexible_Shipping_Shipping_Manifest_CPT {
private $plugin = null;
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
public function hooks() {
add_action( 'init', array( $this, 'register_post_types' ), 20 );
add_action( 'admin_init', array( $this, 'cancel_manifest' ), 20 );
add_action( 'admin_init', array( $this, 'download_manifest' ), 20 );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 199 );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 20, 2 );
add_action( 'trash_shipping_manifest', array( $this, 'trash_shipping_manifest' ) );
add_filter( 'manage_edit-shipping_manifest_columns', array( $this, 'manage_edit_shipping_manifest_columns' ), 11 );
add_action( 'manage_shipping_manifest_posts_custom_column', array(
$this,
'manage_shipping_manifest_posts_custom_column'
), 11 );
add_filter( 'post_row_actions', array( $this, 'shipping_manifest_row_actions' ), 10, 2 ) ;
add_action( 'do_meta_boxes', array( $this, 'hide_publish_metabox' ) );
add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
add_filter( 'bulk_actions-edit-shipping_manifest', array( $this, 'bulk_actions_edit_shipping_manifest' ) );
add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ), 9999 );
add_filter( 'parse_query', array( $this, 'parse_query' ), 999 );
}
/**
* Register post types.
*/
public function register_post_types() {
if ( post_type_exists( 'shipping_manifest' ) ) {
return;
}
register_post_type( 'shipping_manifest',
array(
'labels' => array(
'name' => __( 'Shipping Manifests', 'flexible-shipping' ),
'singular_name' => __( 'Shipping Manifest', 'flexible-shipping' ),
'menu_name' => __( 'Shipping Manifests', 'flexible-shipping' ),
'parent_item_colon' => '',
'all_items' => __( 'Shipping Manifests', 'flexible-shipping' ),
'view_item' => __( 'View Shipping Manifests', 'flexible-shipping' ),
'add_new_item' => __( 'Add new Shipping Manifest', 'flexible-shipping' ),
'add_new' => __( 'Add new Shipping Manifests', 'flexible-shipping' ),
'edit_item' => __( 'Edit Shipping Manifest', 'flexible-shipping' ),
'update_item' => __( 'Save Shipping Manifest', 'flexible-shipping' ),
'search_items' => __( 'Search Shipping Manifests', 'flexible-shipping' ),
'not_found' => __( 'Shipping Manifests not found', 'flexible-shipping' ),
'not_found_in_trash' => __( 'Shipping Manifests not found in trash', 'flexible-shipping' )
),
'description' => __( 'Shipping Manifests.', 'flexible-shipping' ),
'public' => false,
'show_ui' => true,
'capability_type' => 'post',
'capabilities' => array( 'create_posts' => false ),
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'query_var' => true,
'supports' => array( 'title' ),
'has_archive' => false,
'show_in_nav_menus' => false,
'show_in_menu' => 'edit.php?post_type=shop_order',
'menu_icon' => 'dashicons-upload',
)
);
}
public function admin_menu() {
$show_in_menu = current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : false;
if ( apply_filters( 'flexible_shipping_has_manifests', false ) ) {
$slug = add_submenu_page( $show_in_menu, __( 'Shipping Manifests', 'flexible-shipping' ), __( 'Shipping Manifests', 'flexible-shipping' ), 'manage_woocommerce', 'edit.php?post_type=shipping_manifest' );
}
}
public function add_meta_boxes( $post_type, $post ) {
if ( $post_type == 'shipping_manifest' ) {
/*
add_meta_box(
'shipping_manifest_meta_box',
__('Shipping manifest data', 'flexible-shipping'),
array( $this, 'metabox' ),
'shipping_manifest',
'normal',
'high'
);
*/
add_meta_box(
'shipping_manifest_shipments',
__('Shipments', 'flexible-shipping'),
array( $this, 'shipments_metabox' ),
'shipping_manifest',
'normal',
'high'
);
}
}
public function metabox() {
global $post;
echo '<pre>';
print_r( $post );
echo '</pre>';
$meta_data = get_post_meta( $post->ID );
foreach ( $meta_data as $key => $val ) {
echo '<pre>';
echo $key;
echo ' = ';
print_r( maybe_unserialize( $val[0] ) );
echo '</pre>';
}
}
public function shipments_metabox() {
global $post;
$manifest = fs_get_manifest( $post->ID );
$shipments_array = $manifest->get_meta( '_shipments', array() );
$shipments = array();
foreach ( $shipments_array as $shipment_id ) {
$shipments[] = fs_get_shipment( $shipment_id );
}
include( 'views/manifest-metabox.php' );
/*
echo "<pre>";
print_r($shipments);
echo "</pre>";
*/
}
public function manage_edit_shipping_manifest_columns( $columns ) {
unset( $columns['title'] );
unset( $columns['date'] );
unset( $columns['cb'] );
$columns['manifest_date'] = __( 'Date', 'flexible-shipping' );
$columns['integration'] = __( 'Integration', 'flexible-shipping' );
$columns['external_number'] = __( 'Number', 'flexible-shipping' );
$columns['shipment_count'] = __( 'Shipments count', 'flexible-shipping' );
$columns['actions'] = __( 'Actions', 'flexible-shipping' );
return $columns;
}
public function shipping_manifest_row_actions( $actions, $post ) {
if ( $post->post_type == 'shipping_manifest' ) {
$actions = array();
}
return $actions;
}
public function manage_shipping_manifest_posts_custom_column( $column ) {
global $post;
global $manifest;
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
if ( empty( $manifest ) || $manifest->get_id() != $post->ID ) {
$manifest = fs_get_manifest( $post->ID );
}
if ( $column == 'manifest_date' ) {
echo $manifest->get_date();
}
if ( $column == 'integration' ) {
echo $integrations[$manifest->get_integration()];
}
if ( $column == 'external_number' ) {
$download_manifest_url = admin_url('edit.php?post_type=shipping_manifest&flexible_shipping_download_manifest=' . $manifest->get_id() . '&nonce=' . wp_create_nonce('flexible_shipping_download_manifest'));
include( 'views/column-number.php' );
}
if ( $column == 'shipment_count' ) {
echo count( $manifest->get_meta( '_shipments', array() ) );
}
if ( $column == 'actions' ) {
if ( $manifest->get_status() != 'trash' ) {
$download_manifest_url = admin_url('edit.php?post_type=shipping_manifest&flexible_shipping_download_manifest=' . $manifest->get_id() . '&nonce=' . wp_create_nonce('flexible_shipping_download_manifest'));
$cancel_url = admin_url('edit.php?post_type=shipping_manifest&flexible_shipping_cancel_manifest=' . $manifest->get_id() . '&nonce=' . wp_create_nonce('flexible_shipping_cancel_manifest'));
include( 'views/column-actions.php' );
}
}
}
public function woocommerce_screen_ids( $screen_ids ) {
$screen_ids[] = 'edit-shipping_manifest';
$screen_ids[] = 'shipping_manifest';
return $screen_ids;
}
public function bulk_actions_edit_shipping_manifest( $bulk_actions ) {
$bulk_actions = array();
return $bulk_actions;
}
public function cancel_manifest() {
if ( !empty( $_GET['flexible_shipping_cancel_manifest'] ) && !empty( $_GET['nonce'] ) ) {
$nonce = $_GET['nonce'];
if ( !wp_verify_nonce( $nonce, 'flexible_shipping_cancel_manifest' ) ) {
echo __( 'Invalid nonce!', 'flexible-shipping' );
exit;
}
$sendback = admin_url( 'edit.php?post_type=shipping_manifest' );
try {
$shipping_manifest_id = $_GET['flexible_shipping_cancel_manifest'];
$shipping_manifest = fs_get_manifest( $shipping_manifest_id );
$shipping_manifest->cancel();
fs_delete_manifest( $shipping_manifest );
wp_redirect( $sendback );
exit();
}
catch ( Exception $e ) {
wp_redirect( $sendback );
exit();
}
}
}
public function download_manifest() {
if ( !empty( $_GET['flexible_shipping_download_manifest'] ) && !empty( $_GET['nonce'] ) ) {
$nonce = $_GET['nonce'];
if ( !wp_verify_nonce( $nonce, 'flexible_shipping_download_manifest' ) ) {
echo __( 'Invalid nonce!', 'flexible-shipping' );
}
try {
$shipping_manifest_id = $_GET['flexible_shipping_download_manifest'];
$shipping_manifest = fs_get_manifest( $shipping_manifest_id );
$manifest = $shipping_manifest->get_manifest();
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=" . $manifest['file_name'] );
echo $manifest['content'];
}
catch ( Exception $e ) {
echo $e->getMessage();
}
exit();
}
}
public function hide_publish_metabox() {
remove_meta_box( 'submitdiv', 'shipping_manifest', 'side' );
}
public function trash_shipping_manifest( $post_id ) {
$manifest = fs_get_manifest( $post_id );
$shipments_posts = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'shipment',
'post_status' => 'any',
'meta_key' => '_manifest',
'meta_value' => $post_id
));
foreach ( $shipments_posts as $shipment_post ) {
$shipment = fs_get_shipment( $shipment_post->ID );
$shipment->delete_meta( '_manifest' );
$shipment->update_status('fs-confirmed' );
$shipment->save();
}
$manifest->delete_meta( '_shipments' );
$manifest->save();
}
public function restrict_manage_posts() {
global $typenow;
if ( 'shipping_manifest' == $typenow ){
$integrations = apply_filters( 'flexible_shipping_integration_options', array() );
foreach ( $integrations as $key => $integration ) {
if ( !class_exists( 'WPDesk_Flexible_Shipping_Manifest_' . $key ) ) {
unset( $integrations[$key] );
}
}
$integration = '';
if ( isset( $_GET['flexible_shipping_integration_filter'] ) ) {
$integration = $_GET['flexible_shipping_integration_filter'];
}
include( 'views/filter-form.php' );
}
}
public function parse_query( $query ) {
global $pagenow;
$type = 'shipping_manifest';
if ( isset( $_GET['post_type'] ) ) {
$type = $_GET['post_type'];
}
if ( isset( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] == 'shipping_manifest' ) {
if ( 'shipping_manifest' == $type && is_admin() && 'edit.php' == $pagenow ) {
$integration = '';
if ( isset( $_GET['flexible_shipping_integration_filter'] ) ) {
$integration = $_GET['flexible_shipping_integration_filter'];
}
if ( $integration != '' ) {
if ($integration != '') {
if (!isset($query->query_vars['meta_query'])) {
$query->query_vars['meta_query'] = array();
}
$meta_query = array();
$meta_query['key'] = '_integration';
$meta_query['value'] = $integration;
$query->query_vars['meta_query'][] = $meta_query;
}
}
}
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function fs_manifest_integration_exists( $integration ) {
$class_name = 'WPDesk_Flexible_Shipping_Manifest' . '_' . $integration ;
if ( class_exists( $class_name ) ) {
return true;
}
return false;
}
function fs_create_manifest( $integration ) {
$post_title = sprintf( __( 'Shipping manifest %s, %s', 'flexible-shipping' ), $integration, date_i18n( get_option( 'date_format' ) ) );
$post_title = apply_filters( 'flexible_shipping_manifest_post_title_'. $integration, $post_title );
$manifest_post = array(
'post_title' => $post_title,
'post_type' => 'shipping_manifest',
'post_status' => 'publish',
);
$manifest_id = wp_insert_post( $manifest_post );
update_post_meta( $manifest_id, '_integration', $integration );
return fs_get_manifest( $manifest_id );
}
/**
* @param $manifest_id
* @return WPDesk_Flexible_Shipping_Manifest
*/
function fs_get_manifest( $manifest_id ) {
$integration = get_post_meta( $manifest_id, '_integration', true );
$class_name = 'WPDesk_Flexible_Shipping_Manifest';
if ( class_exists( $class_name . '_' . $integration ) ) {
$class_name = $class_name . '_' . $integration;
}
else {
$class_name = 'WPDesk_Flexible_Shipping_Manifest_FS';
}
return new $class_name( $manifest_id );
}
function fs_delete_manifest( $manifest ) {
$shipments_posts = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'shipment',
'post_status' => 'any',
'meta_key' => '_manifest',
'meta_value' => $manifest->get_id()
) );
foreach ( $shipments_posts as $shipment_post ) {
$shipment = fs_get_shipment( $shipment_post->ID );
$shipment->delete_meta( '_manifest' );
$shipment->update_status('fs-confirmed' );
$shipment->save();
}
$manifest->set_meta( '_shipments', array() );
$manifest->update_status( 'trash' );
$manifest->save();
}

View File

@@ -0,0 +1,37 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! interface_exists( 'WPDesk_Flexible_Shipping_Manifest_Interface' ) ) {
interface WPDesk_Flexible_Shipping_Manifest_Interface {
/**
* @return array
* Returns manifest data in array
* file_name => file name for manifest
* content => pdf content
*/
public function get_manifest();
/**
* @return string
* Returns manifest number
*/
public function get_number();
/**
* @return null
* Generates manifest (ie. in API)
*/
public function generate();
/**
* @return null
* Cancels manifest (ie. in API)
*/
public function cancel();
}
}

View File

@@ -0,0 +1,2 @@
<a class="button button-primary" target="_blank" href="<?php echo $download_manifest_url; ?>"><?php _e( 'Download', 'flexible-shipping' ); ?></a>
<a class="button" href="<?php echo $cancel_url; ?>"><?php _e( 'Cancel', 'flexible-shipping' ); ?></a>

View File

@@ -0,0 +1 @@
<a target="_blank" href="<?php echo $download_manifest_url; ?>"><?php echo $manifest->get_number(); ?></a>

View File

@@ -0,0 +1,11 @@
<?php ?>
<div class="alignleft actions">
<select name="flexible_shipping_integration_filter">
<option value=""><?php _e( 'All manifests', 'flexible-shipping' ); ?></option>
<optgroup label="<?php _e( 'Integration', 'flexible-shipping' ); ?>">
<?php foreach ( $integrations as $key => $val ) : ?>
<option value="<?php echo $key; ?>" <?php echo ($key == $integration ? 'selected' : '' ); ?>><?php echo $val; ?></option>
<?php endforeach; ?>
</optgroup>
</select>
</div>

View File

@@ -0,0 +1,55 @@
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th>
</th>
<th>
<?php _e( 'Shipment', 'flexible-shipping' ); ?>
</th>
<th>
<?php _e( 'Order', 'flexible-shipping' ); ?>
</th>
</tr>
</thead>
<tbody id="the-list">
<?php $count = 0; ?>
<?php foreach ( $shipments as $shipment ) : ?>
<?php
$count++;
$order = $shipment->get_order();
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
$order_id = $order->id;
}
else {
$order_id = $order->get_id();
}
?>
<tr>
<td>
<?php echo $count; ?>
</td>
<td>
<a href="<?php echo $shipment->get_order_metabox_url(); ?>"><?php echo $shipment->get_tracking_number(); ?></a>
</td>
<td>
<a href="<?php echo admin_url( 'post.php?action=edit&post=' . $order_id ); ?>"><?php echo $order->get_order_number(); ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th>
</th>
<th>
<?php _e( 'Shipment', 'flexible-shipping' ); ?>
</th>
<th>
<?php _e( 'Order', 'flexible-shipping' ); ?>
</th>
</tr>
</tfoot>
</table>

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( $_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 = $_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;
}
}
}

View File

@@ -0,0 +1,126 @@
<?php
namespace WPDesk\FS\Rate;
/**
* Display rate notice.
*/
class WPDesk_Flexible_Shipping_Rate_Notice implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
const FIRST_NOTICE_MIN_ORDERS = 100;
const CLOSE_TEMPORARY_NOTICE_NUMBER = 'close-temporary-notice-number';
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';
const SETTINGS_OPTION_RATE_NOTICE_NUMBER_DISMISS = 'flexible_shipping_rate_notice_number_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 ) {
$variant_id = get_option( self::SETTINGS_RATE_NOTICE_VARIANT_ID );
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 ) && ( $variant_id === FirstRateNotice::SETTINGS_VARIANT_ID || $variant_id === SecondRateNotice::SETTINGS_VARIANT_ID ) ) {
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 ( ( empty( $source ) || self::CLOSE_TEMPORARY_NOTICE_NUMBER === $source ) && $variant_id === ThirdRateNotice::SETTINGS_VARIANT_ID ) {
update_option( Flexible_Shipping_Order_Counter::FS_ORDER_COUNTER, 0 );
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()
{
$variant = get_option(self::SETTINGS_RATE_NOTICE_VARIANT_ID, '0');
if ( $variant === '0' ) {
$variant = 'notice_' . mt_rand(1, 3);
add_option( self::SETTINGS_RATE_NOTICE_VARIANT_ID, $variant );
$this->set_notice_defaults( $variant );
}
return $variant;
}
/**
* Set defaults for notice
*
* @param string $variant Variant ID.
*/
private function set_notice_defaults( $variant ) {
if( 'notice_3' !== $variant ) {
add_option( self::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime('NOW + 2 weeks') ) );
} else {
add_option( Flexible_Shipping_Order_Counter::FS_ORDER_COUNTER, 0 );
}
}
/**
* Add admin notice.
*/
public function add_admin_notice_action()
{
$variant = $this->generate_rate_notice_variant_id();
if ( $this->should_display_notice() ) {
$creator = new \WPDesk\FS\Rate\RateNoticeCreator();
$instance = $creator->create( $variant );
if( $instance->should_show_message() ) {
$instance->show_message();
}
}
}
}

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;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Default data provider. Can get data from shipment.
*/
class WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider_Default implements WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider {
const COMMON_KEYS_TO_REMOVE = array(
'_fs_method',
'_shipping_method',
'_package',
'_packages',
);
/**
* Keys to remove.
*
* @var array
*/
protected $keys_to_remove = array();
/**
* Get data from shipment.
*
* @param WPDesk_Flexible_Shipping_Shipment $shipment .
*
* @return array
*/
public function get_data_from_shipment( WPDesk_Flexible_Shipping_Shipment $shipment ) {
return $this->remove_internal_data_from_shipment_data( get_post_meta( $shipment->get_id() ) );
}
/**
* Filter data.
*
* @param array $data .
*
* @return array
*/
protected function remove_internal_data_from_shipment_data( array $data ) {
$keys_to_remove = array_merge( self::COMMON_KEYS_TO_REMOVE, $this->keys_to_remove );
foreach ( $keys_to_remove as $key ) {
if ( isset( $data[ $key ] ) ) {
unset( $data[ $key ] );
}
}
return $this->format_data( $data );
}
/**
* Format data.
*
* @param array $data .
*
* @return array
*/
private function format_data( array $data ) {
$formatted_data = array();
foreach ( $data as $key => $value ) {
if ( is_array( $value ) && isset( $value[0] ) ) {
$formatted_data[ $key ] = $value[0];
} else {
$formatted_data[ $key ] = $value;
}
}
return $formatted_data;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Data providers.
* Collects data providers and can return provider per integration or default provider.
*/
class WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Providers_Collection {
/**
* Providers.
*
* @var WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider[]
*/
private $providers = array();
/**
* Add provider.
*
* @param string $integration .
* @param WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider $provider .
*/
public function set_provider( $integration, WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider $provider ) {
$this->providers[ $integration ] = $provider;
}
/**
* Get provider for integration.
*
* @param string $integration .
*
* @return WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider
*/
public function get_provider_for_integration( $integration ) {
if ( isset( $this->providers[ $integration ] ) ) {
return $this->providers[ $integration ];
}
return new WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider_Default();
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Data providers factory.
*/
class WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Providers_Factory {
/**
* Providers.
*
* @var WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Providers_Collection
*/
private static $data_providers = null;
/**
* Get data providers.
*
* @return WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Providers_Collection
*/
public static function get_providers() {
if ( empty( self::$data_providers ) ) {
self::$data_providers = new WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Providers_Collection();
}
return self::$data_providers;
}
}

View File

@@ -0,0 +1,69 @@
<?php
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Can append shipments data to WooCommerce REST API Order response.
*/
class WPDesk_Flexible_Shipping_Rest_Api_Order_Response_Data_Appender implements Hookable {
const REST_API_DATA_KEY = 'fs_shipping_lines';
/**
* Hooks.
*/
public function hooks() {
add_filter( 'woocommerce_rest_prepare_shop_order_object', array( $this, 'maybe_append_shipment_to_order_data' ), 10, 3 );
}
/**
* Appends shipment data if exists to order in REST API response.
*
* @param WP_REST_Response $response .
* @param WC_Order $order .
* @param WP_REST_Request $request .
*
* @return WP_REST_Response
*/
public function maybe_append_shipment_to_order_data( $response, $order, $request ) {
$shipments = fs_get_order_shipments( $order->get_id() );
if ( ! empty( $shipments ) ) {
return $this->append_shipment_to_order_data( $response, $order, $request, $shipments );
}
return $response;
}
/**
* Appends shipment data to order in REST API response.
*
* @param WP_REST_Response $response .
* @param WC_Order $order .
* @param WP_REST_Request $request .
* @param WPDesk_Flexible_Shipping_Shipment[] $shipments .
*
* @return WP_REST_Response
*/
private function append_shipment_to_order_data( $response, $order, $request, $shipments ) {
$response_data = $response->get_data();
if ( empty( $response_data[ self::REST_API_DATA_KEY ] ) ) {
$response_data[ self::REST_API_DATA_KEY ] = array();
}
$providers = WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Providers_Factory::get_providers();
foreach ( $shipments as $shipment ) {
$integration = $shipment->get_integration();
$data_provider = $providers->get_provider_for_integration( $integration );
$response_data[ self::REST_API_DATA_KEY ][] = $data_provider->get_data_from_shipment( $shipment );
}
$response->set_data( $response_data );
return $response;
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Defines interface that REST API Order Data Provider should implement.
*/
interface WPDesk_Flexible_Shipping_Rest_Api_Order_Data_Provider {
/**
* Get data from shipment.
*
* @param WPDesk_Flexible_Shipping_Shipment $shipment .
*
* @return array
*/
public function get_data_from_shipment( WPDesk_Flexible_Shipping_Shipment $shipment );
}

View File

@@ -0,0 +1,435 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Flexible_Shipping_Shipment' ) ) {
/**
* Class WPDesk_Flexible_Shipping_Shipment
*/
abstract class WPDesk_Flexible_Shipping_Shipment {
const STATUS_FS_NEW = 'fs-new';
const STATUS_FS_CREATED = 'fs-created';
const STATUS_FS_CONFIRMED = 'fs-confirmed';
const STATUS_FS_FAILED = 'fs-failed';
const STATUS_FS_MANIFEST = 'fs-manifest';
const CREATED_VIA = 'created_via';
const SENT_VIA_METABOX = 'metabox';
const SENT_VIA_BULK = 'bulk';
const SENT_VIA_AUTO = 'auto';
const SENT_VIA = '_sent_via';
const NOT_SET = 'not_set';
/**
* @var int
*/
private $id;
/**
* @var WP_Post
* Post assigned to shipment
*/
private $post;
/**
* @var null|WC_Order
* WC_Order assigned to shipment
*/
private $order = null;
/**
* @var bool
* True if assigned post ich changed. Used when saving post
*/
private $save_post = false;
/**
* @var null
* Holds old status when shipment status is changed
*/
private $old_status = null;
/**
* @var bool
* True when status changing
*/
private $status_changed = false;
/**
* @var array
* Shipment metadata (from postmeta table)
*/
private $meta_data = array();
/**
* @var bool
* True when shipment metadata loaded
*/
private $meta_data_loaded = false;
/**
* @var array
* Holds changed metadata keys. Used when saving shipment
*/
private $meta_data_save_keys = array();
/**
* @var string
* Context for order metabox
*/
private $order_metabox_context = 'side';
/**
* WPDesk_Flexible_Shipping_Shipment constructor.
*
* @param int|WP_Post|WPDesk_Flexible_Shipping_Shipment $shipment Shipment or shipment ID.
* @param WC_Order|null $order Order.
*/
public function __construct( $shipment, $order = null ) {
if ( is_numeric( $shipment ) ) {
$this->id = absint( $shipment );
$this->post = get_post( $this->id );
} elseif ( $shipment instanceof WPDesk_Flexible_Shipping_Shipment ) {
$this->id = absint( $shipment->get_id() );
$this->post = $shipment->get_post();
} elseif ( isset( $shipment->ID ) ) {
$this->id = absint( $shipment->ID );
$this->post = $shipment;
}
$this->order = $order;
}
/**
* @return mixed
*/
public function get_id() {
return $this->id;
}
/**
* @return mixed
*/
public function get_post() {
return $this->post;
}
/**
* @return WC_Order
*/
public function get_order() {
if ( $this->order == null ) {
$this->order = wc_get_order( $this->post->post_parent );
}
return $this->order;
}
/**
* @return int
*/
public function get_order_id() {
return $this->post->post_parent;
}
/**
* @return string
*/
public function get_order_metabox_context() {
return $this->order_metabox_context;
}
/**
* @param string $order_metabox_context
*/
public function set_order_metabox_context( $order_metabox_context ) {
$this->order_metabox_context = $order_metabox_context;
}
/**
* @param string $meta_key
* @param null|sting $default
* @return array|string|null
*/
public function get_meta( $meta_key = '', $default = null ) {
$this->load_meta_data();
if ( $meta_key == '' ) {
return $this->meta_data;
}
if ( isset( $this->meta_data[$meta_key] ) ) {
return maybe_unserialize( $this->meta_data[$meta_key][0] );
}
else {
return $default;
}
return null;
}
/**
* @param string $meta_key
* @param int|string|array|object|null $value
*/
public function set_meta( $meta_key, $value ) {
$this->load_meta_data();
if ( !isset( $this->meta_data[$meta_key] ) ) {
$this->meta_data[$meta_key] = array();
}
$this->meta_data[$meta_key][0] = $value;
$this->meta_data_save_keys[$meta_key] = $meta_key;
}
/**
* @param string $meta_key
*/
public function delete_meta( $meta_key ) {
unset( $this->meta_data[$meta_key] );
$this->meta_data_save_keys[$meta_key] = $meta_key;
}
/**
* Saves shipment data to database.
*/
public function save() {
if ( $this->save_post ) {
wp_update_post($this->post);
$this->save_post = false;
}
foreach ( $this->meta_data_save_keys as $key ) {
if ( isset( $this->meta_data[$key] ) ) {
update_post_meta( $this->id, $key, $this->meta_data[$key][0] );
}
else {
delete_post_meta( $this->id, $key );
}
unset( $this->meta_data_save_keys[$key] );
}
if ( $this->status_changed ) {
do_action( 'flexible_shipping_shipment_status_updated', $this->old_status, $this->post->post_status, $this );
$this->status_changed = false;
$this->old_status = null;
}
}
/**
* Loads all meta data from postmeta
*/
public function load_meta_data() {
if ( !$this->meta_data_loaded ) {
$this->meta_data = get_post_meta( $this->id );
$this->meta_data_loaded = true;
}
}
/**
* @return string|null
* Returns integration assigned to shipment
*/
public function get_integration() {
return $this->get_meta( '_integration' );
}
/**
* @return string
* Returns URL for admin metabox for this shipment
*/
public function get_order_metabox_url() {
return admin_url( 'post.php?post=' . $this->get_order_id() . '&action=edit#shipment_meta_box_' . $this->get_id() );
}
/**
* @return string
*/
public function get_status() {
return $this->post->post_status;
}
/**
* @return string
*/
public function get_status_for_shipping_column() {
$statuses = array(
self::STATUS_FS_NEW => 'new',
self::STATUS_FS_CREATED => 'created',
self::STATUS_FS_CONFIRMED => 'confirmed',
self::STATUS_FS_FAILED => 'error',
self::STATUS_FS_MANIFEST => 'manifest',
);
return $statuses[$this->get_status()];
}
/**
* @return null|string
* Returns URL for label
*/
public function get_label_url() {
if ( in_array( $this->get_status(), array( self::STATUS_FS_NEW, self::STATUS_FS_CREATED, self::STATUS_FS_FAILED ) ) ) {
return null;
}
$label_url = '?flexible_shipping_get_label=' . $this->get_id() . '&nonce=' . wp_create_nonce( 'flexible_shipping_get_label' ) ;
return site_url( $label_url );
}
/**
* @param string $new_status
*/
public function update_status( $new_status ) {
$this->old_status = $this->post->post_status;
$this->post->post_status = $new_status;
$this->save_post = true;
$this->status_changed = true;
}
public function add_to_manifest( WPDesk_Flexible_Shipping_Manifest $manifest ) {
$this->set_meta( '_manifest', $manifest->get_id() );
}
public function label_avaliable() {
if ( in_array( $this->get_status(), array( self::STATUS_FS_CONFIRMED, self::STATUS_FS_MANIFEST ) ) ) {
return true;
}
return false;
}
/**
* Displays shipping column in orders list view.
* Must be overwritten!
*/
public function shipping_column() {
echo _( 'Please override shipping_column method!', 'flexible-shipping' );
echo '<pre>';
print_r( $this->post );
echo '</pre>';
echo '<pre>';
print_r( $this->meta_data );
echo '</pre>';
}
/**
* Is status fs-new?
*
* @return bool
*/
public function is_status_fs_new() {
return self::STATUS_FS_NEW === $this->get_status();
}
/**
* Is status fs-created?
*
* @return bool
*/
public function is_status_fs_created() {
return self::STATUS_FS_CREATED === $this->get_status();
}
/**
* Is status fs-confirmed?
*
* @return bool
*/
public function is_status_fs_confirmed() {
return self::STATUS_FS_CONFIRMED === $this->get_status();
}
/**
* Is status fs-failed?
*
* @return bool
*/
public function is_status_fs_failed() {
return self::STATUS_FS_FAILED === $this->get_status();
}
/**
* Is status fs-manifest?
*
* @return bool
*/
public function is_status_fs_manifest() {
return self::STATUS_FS_MANIFEST === $this->get_status();
}
/**
* Set created via.
*
* @param string $created_via Created via.
*/
public function set_created_via( $created_via ) {
$this->set_meta( self::CREATED_VIA, $created_via );
}
/**
* Set created via checkout.
*/
public function set_created_via_checkout() {
$this->set_created_via( 'checkout' );
}
/**
* Set created via add shipment.
*/
public function set_created_via_add_shipment() {
$this->set_created_via( 'add_shipment' );
}
/**
* Get created via.
*
* @return string
*/
public function get_created_via() {
return $this->get_meta( self::CREATED_VIA, self::NOT_SET );
}
/**
* Set sent via.
*
* @param string $sent_via
*/
public function set_sent_via( $sent_via ) {
$this->set_meta( self::SENT_VIA, $sent_via );
}
/**
* Set sent via bulk.
*/
public function set_sent_via_bulk() {
$this->set_sent_via( self::SENT_VIA_BULK );
}
/**
* Set sent via auto.
*/
public function set_sent_via_auto() {
$this->set_sent_via( self::SENT_VIA_AUTO );
}
/**
* Set sent via metabox.
*/
public function set_sent_via_metabox() {
$this->set_sent_via( self::SENT_VIA_METABOX );
}
/**
* Get sent via.
*
* @return string
*/
public function get_sent_via() {
return $this->get_meta( self::SENT_VIA, self::NOT_SET );
}
/**
* Get meta shipping method.
*
* @return WC_Order_Item_Shipping
*/
protected function get_meta_shipping_method() {
return $this->get_meta( '_shipping_method' );
}
}
}

View File

@@ -0,0 +1,344 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WPDesk_Flexible_Shipping_Shipment_CPT {
const POST_TYPE_SHIPMENT = 'shipment';
private $plugin = null;
/**
* Is order processed on checkout?
*
* @var bool
*/
private $is_order_processed_on_checkout = false;
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
public function hooks() {
add_action( 'init', array( $this, 'register_post_types' ), 20 );
add_action( 'init', array( $this, 'flexible_shipping_get_label' ), 9999999 );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 20, 2 );
$last_priority = PHP_INT_MAX;
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'create_shipping_for_order' ), $last_priority );
add_action( 'woocommerce_order_details_after_order_table', array( $this, 'woocommerce_order_details_after_order_table' ) );
add_action( 'woocommerce_email_after_order_table', array( $this, 'woocommerce_email_after_order_table' ), 10, 2 );
}
/**
* Register post types.
*/
public function register_post_types() {
if ( post_type_exists( self::POST_TYPE_SHIPMENT ) ) {
return;
}
register_post_type( self::POST_TYPE_SHIPMENT,
array(
'labels' => array(
'name' => __( 'Shipments', 'flexible-shipping' ),
'singular_name' => __( 'Shipment', 'flexible-shipping' ),
'menu_name' => __( 'Shipments', 'flexible-shipping' ),
'parent_item_colon' => '',
'all_items' => __( 'Shipments', 'flexible-shipping' ),
'view_item' => __( 'View Shipments', 'flexible-shipping' ),
'add_new_item' => __( 'Add new Shipment', 'flexible-shipping' ),
'add_new' => __( 'Add new Shipment', 'flexible-shipping' ),
'edit_item' => __( 'Edit Shipment', 'flexible-shipping' ),
'update_item' => __( 'Save Shipment', 'flexible-shipping' ),
'search_items' => __( 'Search Shipments', 'flexible-shipping' ),
'not_found' => __( 'Shipment not found', 'flexible-shipping' ),
'not_found_in_trash' => __( 'Shipment not found in trash', 'flexible-shipping' )
),
'description' => __( 'Shipments.', 'flexible-shipping' ),
'public' => false,
'show_ui' => false,
'capability_type' => 'post',
'capabilities' => array(),
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'query_var' => true,
'supports' => array( 'title' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'menu_icon' => 'dashicons-upload',
)
);
$shipment_statuses = apply_filters( 'flexible_shipping_register_shipment_statuses',
array(
'fs-new' => array(
'label' => _x( 'New', 'Shipment status', 'flexible-shipping' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'New <span class="count">(%s)</span>', 'New <span class="count">(%s)</span>', 'flexible-shipping' ),
),
'fs-created' => array(
'label' => _x( 'Created', 'Shipment status', 'flexible-shipping' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Created <span class="count">(%s)</span>', 'Created <span class="count">(%s)</span>', 'flexible-shipping' ),
),
'fs-confirmed' => array(
'label' => _x( 'Confirmed', 'Shipment status', 'flexible-shipping' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Confirmed <span class="count">(%s)</span>', 'Confirmed <span class="count">(%s)</span>', 'flexible-shipping' ),
),
'fs-manifest' => array(
'label' => _x( 'Manifest created', 'Shipment status', 'flexible-shipping' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Confirmed <span class="count">(%s)</span>', 'Confirmed <span class="count">(%s)</span>', 'flexible-shipping' ),
),
'fs-failed' => array(
'label' => _x( 'Failed', 'Shipment status', 'flexible-shipping' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'flexible-shipping' ),
),
)
);
foreach ( $shipment_statuses as $shipment_status => $values ) {
register_post_status( $shipment_status, $values );
}
}
public function add_meta_boxes( $post_type, $post ) {
if ( $post_type == self::POST_TYPE_SHIPMENT ) {
add_meta_box(
'shipment_meta_box',
__('Shipment data', 'flexible-shipping'),
array( $this, 'metabox' ),
'shipment',
'normal',
'high'
);
}
if ( $post_type == 'shop_order' ) {
$shipments = fs_get_order_shipments( $post->ID );
foreach ( $shipments as $shipment ) {
$args = array( 'shipment' => $shipment );
add_meta_box(
'shipment_meta_box_' . $shipment->get_id(),
$shipment->get_order_metabox_title(),
array( $this, 'order_metabox' ),
'shop_order',
$shipment->get_order_metabox_context(),
'default',
$args
);
}
}
}
public function order_metabox( $post, $args ) {
/** @var WPDesk_Flexible_Shipping_Shipment $shipment */
$shipment = $args['args']['shipment'];
$shipment_id = $shipment->get_id();
$message = $shipment->get_error_message();
$message_heading = $shipment->get_order_metabox_title();
$message_css_style = '';
include( 'views/order-metabox.php' );
}
public function metabox() {
global $post;
echo '<pre>';
print_r( $post );
echo '</pre>';
$meta_data = get_post_meta( $post->ID );
foreach ( $meta_data as $key => $val ) {
echo '<pre>';
echo $key;
echo ' = ';
print_r( maybe_unserialize( $val[0] ) );
echo '</pre>';
}
}
public function flexible_shipping_get_label() {
if ( !empty( $_GET['flexible_shipping_get_label'] ) && !empty( $_GET['nonce'] ) ) {
$nonce = $_GET['nonce'];
if ( !wp_verify_nonce( $nonce, 'flexible_shipping_get_label' ) ) {
echo __( 'Invalid nonce!', 'flexible-shipping' );
exit;
}
try {
$shipment_id = $_GET['flexible_shipping_get_label'];
$shipment = fs_get_shipment( $shipment_id );
$label_data = $shipment->get_label();
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=" . $label_data['file_name'] );
echo $label_data['content'];
}
catch ( Exception $e ) {
echo $e->getMessage();
}
exit();
}
}
/**
* Get Flexible Shipping method from order shipping method meta data.
*
* @param WC_Order_Item_Shipping $shipping_method
*
* @return array
*/
private function get_fs_method_from_order_shipping_method( $shipping_method ) {
$fs_method = array();
if ( version_compare( WC_VERSION, '2.6', '<' ) ) {
if ( isset( $shipping_method['item_meta'] )
&& isset( $shipping_method['item_meta']['method_id'] )
&& isset( $shipping_method['item_meta']['method_id'][0] )
) {
$all_shipping_methods = flexible_shipping_get_all_shipping_methods();
$flexible_shipping = $all_shipping_methods['flexible_shipping'];
$flexible_shipping_rates = $flexible_shipping->get_all_rates();
$fs_method = $flexible_shipping_rates[ $shipping_method['item_meta']['method_id'][0] ];
}
}
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
if ( isset( $shipping_method['item_meta'] )
&& isset( $shipping_method['item_meta']['_fs_method'] )
&& isset( $shipping_method['item_meta']['_fs_method'][0] )
) {
$fs_method = unserialize( $shipping_method['item_meta']['_fs_method'][0] );
}
} else {
if ( isset( $shipping_method['item_meta'] )
&& isset( $shipping_method['item_meta']['_fs_method'] )
) {
$fs_method = $shipping_method['item_meta']['_fs_method'];
}
}
return $fs_method;
}
/**
* Create shipment for order and shipping method.
*
* @param WC_Order $order Order.
* @param array $fs_method Flexible Shipping shipping method.
* @param string $shipping_id Shipping Id.
* @param WC_Order_Item_Shipping $shipping_method Shipping method.
* @param array $packages Packages.
* @param int $package_id Package Id.
*
* @return WPDesk_Flexible_Shipping_Shipment
*/
private function create_shipment_for_order_and_fs_shipping_method(
WC_Order $order,
array $fs_method,
$shipping_id,
WC_Order_Item_Shipping $shipping_method,
array $packages,
$package_id
) {
$shipment = fs_create_shipment( $order, $fs_method );
$shipment->set_meta( '_fs_method', $fs_method );
$shipment->set_meta( '_shipping_id', $shipping_id );
$shipment->set_meta( '_shipping_method', $shipping_method );
$shipment->set_meta( '_package', $packages[ $package_id ] );
$shipment->set_meta( '_packages', $packages );
$shipment->set_created_via_checkout();
$shipment->checkout( $fs_method, $packages[ $package_id ] );
$shipment->save();
return $shipment;
}
/**
* Create shipping for order.
*
* @param $order_id
*/
public function create_shipping_for_order( $order_id ) {
$order = wc_get_order( $order_id );
if ( $order && ! $this->is_order_processed_on_checkout ) {
$mutex = \FSVendor\WPDesk\Mutex\WordpressPostMutex::fromOrder( $order );
$mutex->acquireLock();
$shipments = fs_get_order_shipments( $order_id );
if ( 0 === count( $shipments ) ) {
$this->is_order_processed_on_checkout = true;
$order_shipping_methods = $order->get_shipping_methods();
$packages = WC()->shipping->get_packages();
$package_id = - 1;
global $fs_package_id;
foreach ( $order_shipping_methods as $shipping_id => $shipping_method ) {
$package_id ++;
$fs_package_id = $package_id;
$fs_method = $this->get_fs_method_from_order_shipping_method( $shipping_method );
if ( ! empty( $fs_method['method_integration'] ) ) {
if ( fs_shipment_integration_exists( $fs_method['method_integration'] ) ) {
$shipment = $this->create_shipment_for_order_and_fs_shipping_method(
$order, $fs_method, $shipping_id, $shipping_method, $packages, $package_id
);
}
}
}
}
$mutex->releaseLock();
}
}
/**
* Hook woocommerce_order_details_after_order_table.
*
* @param WC_Abstract_Order $order Order.
*/
public function woocommerce_order_details_after_order_table( $order ) {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
$order_id = $order->id;
}
else {
$order_id = $order->get_id();
}
$shipments = fs_get_order_shipments( $order_id );
foreach ( $shipments as $shipment ) {
echo $shipment->get_after_order_table();
}
}
public function woocommerce_email_after_order_table( $order, $sent_to_admin ) {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
$order_id = $order->id;
}
else {
$order_id = $order->get_id();
}
$shipments = fs_get_order_shipments( $order_id );
foreach ( $shipments as $shipment ) {
echo $shipment->get_email_after_order_table();
}
}
}

View File

@@ -0,0 +1,126 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function fs_shipment_integration_exists( $integration ) {
$class_name = apply_filters( 'flexible_shipping_shipment_class', 'WPDesk_Flexible_Shipping_Shipment' . '_' . $integration, $integration );
if ( class_exists( $class_name ) ) {
return true;
}
return false;
}
/**
* @param WC_Abstract_Order $order Order.
* @param array $fs_method Flexible shipping method.
*
* @return WPDesk_Flexible_Shipping_Shipment
*/
function fs_create_shipment( $order, $fs_method ) {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
$order_id = $order->id;
}
else {
$order_id = $order->get_id();
}
$integration = $fs_method['method_integration'];
$post_title = sprintf( __( 'Shipment for order %s, %s', 'flexible-shipping' ), $order_id, $integration );
$post_title = apply_filters( 'flexible_shipping_shipment_post_title_'. $integration, $post_title, $fs_method );
$shipment_post = array(
'post_title' => $post_title,
'post_type' => 'shipment',
'post_status' => 'fs-new',
'post_parent' => $order_id
);
$shipment_id = wp_insert_post( $shipment_post );
update_post_meta( $shipment_id, '_integration', $integration );
return fs_get_shipment( $shipment_id, $order );
}
/**
* Returns shipments for order.
* Shipments are ordered from oldest to newest.
*
* @param $order_id
* @param string|null $integration
* @return WPDesk_Flexible_Shipping_Shipment_Interface[]
*/
function fs_get_order_shipments( $order_id, $integration = null ) {
$shipments_posts_query = array(
'posts_per_page' => -1,
'post_parent' => $order_id,
'post_type' => 'shipment',
'post_status' => 'any',
'orderby' => 'ID',
'order' => 'ASC',
);
if ( !empty( $integration ) ) {
$shipments_posts_query['meta_key'] = '_integration';
$shipments_posts_query['meta_value'] = $integration;
}
$shipments_posts = get_posts( $shipments_posts_query );
$shipments = array();
if ( count( $shipments_posts ) ) {
$order = wc_get_order($order_id);
foreach ($shipments_posts as $shipment_post) {
$integration = get_post_meta($shipment_post->ID, '_integration', true);
if ( fs_shipment_integration_exists( $integration ) ) {
$shipments[] = fs_get_shipment($shipment_post->ID, $order);
}
}
}
return $shipments;
}
/**
* Get shipment.
*
* @param int $shipment_id Shipment id.
* @param WC_Order|null $order Order.
* @return WPDesk_Flexible_Shipping_Shipment
*/
function fs_get_shipment( $shipment_id, $order = null ) {
$integration = get_post_meta( $shipment_id, '_integration', true );
$class_name = 'WPDesk_Flexible_Shipping_Shipment';
$integration_class_name = 'WPDesk_Flexible_Shipping_Shipment' . '_' . $integration;
$integration_class_name = apply_filters( 'flexible_shipping_shipment_class', $integration_class_name, $integration );
if ( class_exists( $integration_class_name ) ) {
$class_name = $integration_class_name;
}
return new $class_name( $shipment_id, $order );
}
/**
* @param WC_Abstract_Order $order Order.
*
* @return float
*/
function fs_calculate_order_weight( $order ) {
$weight = 0;
if ( sizeof( $order->get_items() ) > 0 ) {
foreach( $order->get_items() as $item ) {
if ( $item['product_id'] > 0 ) {
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
$product = $order->get_product_from_item( $item );
}
else {
$product = $item->get_product();
}
$product_weight = $product->get_weight();
if ( ! $product->is_virtual() && is_numeric( $product_weight ) ) {
$weight += floatval( $product->get_weight() ) * floatval( $item['qty'] );
}
}
}
}
return $weight;
}
function fs_calculate_package_weight( $package ) {
$weight = 0;
foreach( $package['contents'] as $item ) {
$weight += floatval( $item['data']->get_weight() ) * floatval( $item['quantity'] );
}
return $weight;
}

View File

@@ -0,0 +1,76 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! interface_exists( 'WPDesk_Flexible_Shipping_Shipment_Interface' ) ) {
interface WPDesk_Flexible_Shipping_Shipment_Interface {
/**
* @param array $fs_method
* @param array $package
* @return void
* Executes on woocommerce checkout when order is created
*/
public function checkout( array $fs_method, $package );
/**
* @return void
* Displays metabox in woocommerce order
*/
public function order_metabox();
/**
* @return string
* Returns woocommerce metabox title
*/
public function get_order_metabox_title();
/**
* @param string $action
* @param array $data
* @return void
* Executes on ajax request. $data contains all woocommerce order metabox fields values from metabox generated in order_metabox() method.
*/
public function ajax_request( $action, $data );
/**
* @return string
* Returns error message
*/
public function get_error_message();
/**
* @return string
* Returns tracking number for shipment
*/
public function get_tracking_number();
/**
* @return string
* Returns tracking URL for shipping
*/
public function get_tracking_url();
/**
* @return array
* Return label data foe shipping in array:
* 'label_format' => 'pdf'
* 'content' => pdf content,
* 'file_name' => file name for label
*/
public function get_label();
/**
* @return mixed
*/
public function get_after_order_table();
/**
* @return mixed
*/
public function get_email_after_order_table();
}
}

View File

@@ -0,0 +1,9 @@
<div class="flexible_shipping_shipment" id="flexible_shipping_shipment_<?php echo $shipment->get_id(); ?>" data-id="<?php echo $shipment_id; ?>">
<?php wp_nonce_field( 'flexible_shipping_shipment_nonce', 'flexible_shipping_shipment_nonce_' . $shipment_id, false ); ?>
<div class="flexible_shipping_shipment_content">
<?php $shipment->order_metabox(); ?>
</div>
<div class="flexible_shipping_shipment_message flexible_shipping_shipment_message_error" style="<?php echo $message_css_style; ?>">
<?php echo $message; ?>
</div>
</div>

View File

@@ -0,0 +1,40 @@
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php
$params = array(
'type' => 'select',
'options' => $select_options,
'class' => array('first','paczkomaty'),
//'label' => __( 'Integration ', 'flexible-shipping' ),
'id' => 'fs_add_shipping',
);
woocommerce_form_field( 'fs_add_shipping', $params );
?>
<button id="fs_add_shipping_button" class="button button-primary" href="" disabled="disabled"><?php _e( 'Add', 'flexible-shipping' ); ?></button>
<script type="text/javascript">
jQuery('#fs_add_shipping').change(function(){
if ( jQuery(this).val() != '' ) {
jQuery('#fs_add_shipping_button').attr( 'disabled', false );
}
else {
jQuery('#fs_add_shipping_button').attr( 'disabled', true );
}
})
jQuery('#fs_add_shipping_button').click(function(e){
e.preventDefault();
window.location.href = '<?php echo $add_shipping_url; ?>' + '&fs_add_shipping=' + jQuery('#fs_add_shipping').val();
});
if ( typeof window.history.pushState == 'function' ) {
var url = document.location.href;
var url2 = document.location.href;
url = fs_removeParam('_wpnonce', url);
url = fs_removeParam('fs_add_shipping', url);
url = fs_trimChar(url,'?');
if ( url != url2 ) {
window.history.pushState({}, "", url);
}
}
</script>

Some files were not shown because too many files have changed in this diff Show More