Plugin Directory

Changeset 3061907


Ignore:
Timestamp:
04/01/2024 06:30:19 AM (2 years ago)
Author:
mswebarts
Message:

Opproval update v1.2.3

Location:
order-approval-by-customer-for-woocommerce
Files:
66 added
2 edited

Legend:

Unmodified
Added
Removed
  • order-approval-by-customer-for-woocommerce/trunk/order-approval.php

    r3061739 r3061907  
    33 * Plugin Name: Opproval - Order Approval by Customer
    44 * Description: Deliver the order and let your customers mark the delivery as completed after receiving the product.
    5  * Version:     1.2.2
     5 * Version:     1.2.3
    66 * Author:      MS Web Arts
    77 * Author URI:  https://www.mswebarts.com/
     
    99 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010 * Text Domain: opproval
    11 
     11 */
     12/**
     13 * @package Opproval
    1214 */
    1315
    14 // Check if woocommerce is installed
     16// integrate Appsero
     17require __DIR__ . '/vendor/autoload.php';
     18/**
     19 * Initialize the plugin tracker
     20 *
     21 * @return void
     22 */
     23function appsero_init_tracker_order_approval_by_customer_for_woocommerce() {
    1524
    16 add_action('plugins_loaded', 'msoa_check_for_woocommerce');
     25    if ( ! class_exists( 'Appsero\Client' ) ) {
     26      require_once __DIR__ . '/appsero/src/Client.php';
     27    }
     28
     29    $client = new Appsero\Client( '0d9a463a-7106-45e6-a63f-21c831f4e1b2', 'Opproval – Order Approval by Customer for WooCommerce', __FILE__ );
     30
     31    // Active insights
     32    $client->insights()->init();
     33
     34}
     35appsero_init_tracker_order_approval_by_customer_for_woocommerce();
     36
     37// Check if woocommerce is installed.
     38add_action( 'plugins_loaded', 'msoa_check_for_woocommerce' );
    1739function msoa_check_for_woocommerce() {
    18     if ( !defined('WC_VERSION') ) {
    19         add_action( 'admin_notices', 'msoa_woocommerce_dependency_error' );
    20         return;
    21     }
     40    if ( ! defined( 'WC_VERSION' ) ) {
     41        add_action( 'admin_notices', 'msoa_woocommerce_dependency_error' );
     42        return;
     43    }
    2244}
    2345
    2446function msoa_woocommerce_dependency_error() {
    25     $class = 'notice notice-error';
    26     $message = __( 'You must need to install and activate woocommerce for Order Approval to work', 'opproval' );
     47    $class  = 'notice notice-error';
     48    $message = __( 'You must need to install and activate woocommerce for Order Approval to work', 'opproval' );
    2749
    28     printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
     50    printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
    2951}
    3052
    31 // Load plugin textdomain
     53// Load plugin textdomain.
    3254add_action( 'init', 'msoa_load_textdomain' );
    3355function msoa_load_textdomain() {
    34     load_plugin_textdomain( 'opproval', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     56    load_plugin_textdomain( 'opproval', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    3557}
    3658
    37 add_action( "wp_enqueue_scripts", "msoa_register_styles" );
     59add_action( 'wp_enqueue_scripts', 'msoa_register_styles' );
    3860function msoa_register_styles() {
    39     wp_enqueue_style( "msoa_style", plugins_url( 'style.css', __FILE__ ) );
     61    wp_enqueue_style( 'msoa_style', plugins_url( 'style.css', __FILE__ ) );
    4062}
    4163
    42 /*================================
     64/*
     65================================
    4366    Add Delivered Order Status
    4467==================================*/
     
    4669add_action( 'init', 'msoa_register_delivered_order_status' );
    4770function msoa_register_delivered_order_status() {
    48     register_post_status( 'wc-delivered', array(
    49         'label'                     => 'Session Completed',
    50         'public'                    => true,
    51         'show_in_admin_status_list' => true,
    52         'show_in_admin_all_list'    => true,
    53         'exclude_from_search'       => false,
    54         'label_count'               => _n_noop( 'Delivered <span class="count">(%s)</span>', 'Delivered <span class="count">(%s)</span>' )
    55     ) );
     71    register_post_status(
     72        'wc-delivered',
     73        array(
     74            'label'                     => 'Session Completed',
     75            'public'                    => true,
     76            'show_in_admin_status_list' => true,
     77            'show_in_admin_all_list'    => true,
     78            'exclude_from_search'       => false,
     79            // translators: %s: count of orders.
     80            'label_count'               => _n_noop( 'Delivered <span class="count">(%s)</span>', 'Delivered <span class="count">(%s)</span>' ),
     81        )
     82    );
    5683}
    5784
    5885add_filter( 'wc_order_statuses', 'msoa_add_delivered_status_to_order_statuses' );
     86/**
     87 * Add "Delivered" order status to WooCommerce.
     88 *
     89 * @param array $order_statuses Array of order statuses.
     90 */
    5991function msoa_add_delivered_status_to_order_statuses( $order_statuses ) {
    6092
    61     $new_order_statuses = array();
     93    $new_order_statuses = array();
    6294
    63     foreach ( $order_statuses as $key => $status ) {
     95    foreach ( $order_statuses as $key => $status ) {
    6496
    65         $new_order_statuses[ $key ] = $status;
     97        $new_order_statuses[ $key ] = $status;
    6698
    67         if ( 'wc-processing' === $key ) {
    68             $new_order_statuses['wc-delivered'] = __( 'Delivered', 'opproval' );
    69         }
    70     }
     99        if ( 'wc-processing' === $key ) {
     100            $new_order_statuses['wc-delivered'] = __( 'Delivered', 'opproval' );
     101        }
     102    }
    71103
    72     return $new_order_statuses;
     104    return $new_order_statuses;
    73105}
    74106
    75107add_filter( 'woocommerce_my_account_my_orders_actions', 'msoa_mark_as_received', 10, 2 );
     108/**
     109 * Add "Mark as Received" button to my account order actions.
     110 */
    76111function msoa_mark_as_received( $actions, $order ) {
    77112    $order_id = $order->id;
    78113
    79     if ( ! is_object( $order ) ) {
    80         $order_id = absint( $order );
    81         $order    = wc_get_order( $order_id );
    82     }
    83    
    84     // check if order status delivered and form not submitted
     114    if ( ! is_object( $order ) ) {
     115        $order_id = absint( $order );
     116        $order    = wc_get_order( $order_id );
     117    }
    85118
    86     if ( ( $order->has_status( 'delivered' ) ) && ( !isset( $_POST['mark_as_received'] ) ) ) {
    87         $check_received = ( $order->has_status( 'delivered' ) ) ? "true" : "false";
    88         ?>
    89         <div class="ms-mark-as-received">
    90             <form method="post">
     119    // check if order status delivered and form not submitted.
     120
     121    if ( ( $order->has_status( 'delivered' ) ) && ( ! isset( $_POST['mark_as_received'] ) ) ) {
     122        $check_received = ( $order->has_status( 'delivered' ) ) ? 'true' : 'false';
     123        ?>
     124        <div class="ms-mark-as-received">
     125            <form method="post">
    91126                <input type="hidden" name="mark_as_received" value="<?php echo esc_attr( $check_received ); ?>">
    92                 <input type="hidden" name="order_id" value="<?php echo esc_attr($order_id);?>">
     127                <input type="hidden" name="order_id" value="<?php echo esc_attr( $order_id ); ?>">
    93128                <?php wp_nonce_field( 'so_38792085_nonce_action', '_so_38792085_nonce_field' ); ?>
    94129                <input class="int-button-small" type="submit" value="<?php echo esc_attr_e( 'Mark as Received', 'opproval' ); ?>" data-toggle="tooltip" title="<?php echo esc_attr_e( 'Click to mark the order as complete if you have received the product', 'opproval' ); ?>">
    95130            </form>
    96         </div>
    97         <?php
     131        </div>
     132        <?php
    98133    }
    99134
    100     /*
    101     //refresh page if form submitted
     135    /**
     136    * Refresh page if form submitted.
     137    * fix status not updating
     138    */
     139    if ( isset( $_POST['mark_as_received'] ) ) {
     140        echo "<meta http-equiv='refresh' content='0'>";
     141    }
    102142
    103     * fix status not updating
    104     */
    105     if( isset( $_POST['mark_as_received'] ) ) {
    106         echo "<meta http-equiv='refresh' content='0'>";
    107     }
     143    // not a "mark as received" form submission.
     144    if ( ! isset( $_POST['mark_as_received'] ) ) {
     145        return $actions;
     146    }
    108147
    109     // not a "mark as received" form submission
    110     if ( ! isset( $_POST['mark_as_received'] ) ){
    111         return $actions;
    112     }
     148    // basic security check.
     149    if ( isset( $_POST['_so_38792085_nonce_field'] ) ) {
     150        $nonce_field = sanitize_text_field( wp_unslash( $_POST['_so_38792085_nonce_field'] ) );
     151        if ( ! wp_verify_nonce( sanitize_text_field( $nonce_field ), 'so_38792085_nonce_action' ) ) {
     152            return $actions;
     153        }
    113154
    114     // basic security check
    115     if ( ! isset( $_POST['_so_38792085_nonce_field'] ) || ! wp_verify_nonce( $_POST['_so_38792085_nonce_field'], 'so_38792085_nonce_action' ) ) {   
    116         return $actions;
    117     }
     155        // make sure order id is submitted.
     156        if ( ! isset( $_POST['order_id'] ) ) {
     157            $order_id = intval( $_POST['order_id'] );
     158            $order    = wc_get_order( $order_id );
     159            $order->update_status( 'completed' );
     160            return $actions;
     161        }
     162        if ( isset( $_POST['mark_as_received'] ) === true ) {
     163            $order_id = intval( $_POST['order_id'] );
     164            $order    = wc_get_order( $order_id );
     165            $order->update_status( 'completed' );
     166        }
    118167
    119     // make sure order id is submitted
    120     if ( ! isset( $_POST['order_id'] ) ){
    121         $order_id = intval( $_POST['order_id'] );
    122         $order = wc_get_order( $order_id );
    123         $order->update_status( "completed" );
    124         return $actions;
    125     } 
    126     if ( isset( $_POST['mark_as_received'] ) == true ) {
    127         $order_id = intval( $_POST['order_id'] );
    128         $order = wc_get_order( $order_id );
    129         $order->update_status( "completed" );
    130     }
     168        $actions = array(
     169            'pay'    => array(
     170                'url'  => $order->get_checkout_payment_url(),
     171                'name' => __( 'Pay', 'woocommerce' ),
     172            ),
     173            'view'   => array(
     174                'url'  => $order->get_view_order_url(),
     175                'name' => __( 'View', 'woocommerce' ),
     176            ),
     177            'cancel' => array(
     178                'url'  => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
     179                'name' => __( 'Cancel', 'woocommerce' ),
     180            ),
     181        );
    131182
    132     $actions = array(
    133         'pay'    => array(
    134             'url'  => $order->get_checkout_payment_url(),
    135             'name' => __( 'Pay', 'woocommerce' ),
    136         ),
    137         'view'   => array(
    138             'url'  => $order->get_view_order_url(),
    139             'name' => __( 'View', 'woocommerce' ),
    140         ),
    141         'cancel' => array(
    142             'url'  => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
    143             'name' => __( 'Cancel', 'woocommerce' ),
    144         ),
    145     );
     183        if ( ! $order->needs_payment() ) {
     184            unset( $actions['pay'] );
     185        }
    146186
    147     if ( ! $order->needs_payment() ) {
    148         unset( $actions['pay'] );
    149     }
     187        if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ), true ) ) {
     188            unset( $actions['cancel'] );
     189        }
     190    }
    150191
    151     if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ), true ) ) {
    152         unset( $actions['cancel'] );
    153     }
    154 
    155     return $actions;
    156 
     192    return $actions;
    157193}
  • order-approval-by-customer-for-woocommerce/trunk/readme.txt

    r3061742 r3061907  
    55Tested up to: 6.5
    66Requires PHP: 5.6
    7 Stable tag: 1.2.2
     7Stable tag: 1.2.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8787== Changelog ==
    8888
    89 = 1.2.1 =
     89= 1.2.3 =
     90* Analytics integration
     91* Fixed compatibility issues
     92
     93= 1.2.2 =
    9094* Compatibility with WordPress 6.5 and WC 8.7
    9195
Note: See TracChangeset for help on using the changeset viewer.