Plugin Directory

Changeset 2735659


Ignore:
Timestamp:
06/01/2022 12:58:43 PM (4 years ago)
Author:
codup
Message:

Code Update

Location:
codup-woocommerce-dynamic-pricing-table-view/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • codup-woocommerce-dynamic-pricing-table-view/trunk/class-wc-pricing-table.php

    r2715246 r2735659  
    77 * Author: Codup.io
    88 * Author URI: http://codup.io/
    9  * Requires at least: 5.0.1
    10  * Tested up to: 5.9.1
     9 * Requires at least: 5.0.0
     10 * Tested up to: 5.9.2
    1111 *
    1212 * Text Domain: woocommerce
  • codup-woocommerce-dynamic-pricing-table-view/trunk/includes/class-wc-pricing-table-display.php

    r2715246 r2735659  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ){
     2/**
     3 * CodupWcPricingTableDisplay Class File.
     4 */
     5
     6if ( ! defined( 'ABSPATH' ) ) {
    37    exit;
    48}
    59
    6 class CodupWcPricingTableDisplay{
    7    
    8     /** @var object Class Instance */
     10/**
     11 * CodupWcPricingTableDisplay Class.
     12 */
     13class CodupWcPricingTableDisplay {
     14
     15    /**
     16     * Define instance.
     17     */
    918    private static $instance;
    10    
    11     /**
    12      * Get the class instance
    13      */
    14     public static function get_instance(){
    15         return null === self::$instance ? ( self::$instance = new self ) : self::$instance;
    16     }
    17    
    18     public function __construct(){
    19         //  Show discount table on product page
     19
     20    /**
     21     * Get the class instance.
     22     */
     23    public static function get_instance() {
     24        return null === self::$instance ? ( self::$instance = new self() ) : self::$instance;
     25    }
     26
     27    /**
     28     * Construct.
     29     */
     30    public function __construct() {
     31        // Show discount table on product page.
    2032        add_action( 'woocommerce_before_add_to_cart_form', array( $this, 'codup_wc_pricing_table_show_pricing_table' ) );
    2133
    22         //  Show discount table in a tab if tab is selected in a option
    23         add_filter( 'woocommerce_product_tabs', array( $this,'codup_wc_pricing_table_add_tab_of_pricing_table'), 110 );
    24        
    25         //  Add admin scripts
     34        // Show discount table in a tab if tab is selected in a option.
     35        add_filter( 'woocommerce_product_tabs', array( $this, 'codup_wc_pricing_table_add_tab_of_pricing_table' ), 110 );
     36
     37        // Add admin scripts.
    2638        add_action( 'admin_enqueue_scripts', array( $this, 'codup_wc_pricing_table_enqueue_scripts' ) );
    2739
    28         //  Enqueue ajax on the pricing table menu to show date expiration notification
     40        // Enqueue ajax on the pricing table menu to show date expiration notification.
    2941        self::codup_wc_pricing_table_enqueue_ajax_scripts();
    3042    }
    31     /*
    32     * Enquque your scripts here
    33     */
    34     public function codup_wc_pricing_table_enqueue_scripts(){
    35        
    36         wp_enqueue_script('wc-notification-ajax-js', CODUP_WC_PRICING_TABLE_PLUGIN_URL. '/assets/js/wc-pricing-table-admin-date-expiry-notification.js', array( 'jquery' ), CODUP_WC_PRICING_TABLE_VERSION, false );
    37         wp_enqueue_script('wc-notification-ajax-js');
    38         wp_localize_script( 'wc-notification-ajax-js', 'myAjax', array( 'ajaxurl' => admin_url('admin-ajax.php')));
    39     }
    40 
    41     public function codup_wc_pricing_table_enqueue_ajax_scripts(){
    42 
    43         add_action("wp_ajax_codup_wc_pricing_table_notify_rules_status_on_admin", array($this,'codup_wc_pricing_table_notify_rules_status_on_admin'));
    44         add_action('wp_ajax_nopriv_codup_wc_pricing_table_notify_rules_status_on_admin', array($this,'codup_wc_pricing_table_notify_rules_status_on_admin'));
    45     }
    46        
    47    
     43
     44    /**
     45     * Enquque your scripts here.
     46     */
     47    public function codup_wc_pricing_table_enqueue_scripts() {
     48
     49        wp_enqueue_script( 'wc-notification-ajax-js', CODUP_WC_PRICING_TABLE_PLUGIN_URL . '/assets/js/wc-pricing-table-admin-date-expiry-notification.js', array( 'jquery' ), CODUP_WC_PRICING_TABLE_VERSION, false );
     50        wp_enqueue_script( 'wc-notification-ajax-js' );
     51        wp_localize_script( 'wc-notification-ajax-js', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
     52    }
     53
     54    /**
     55     * Defines Ajax calls.
     56     */
     57    public function codup_wc_pricing_table_enqueue_ajax_scripts() {
     58
     59        add_action( 'wp_ajax_codup_wc_pricing_table_notify_rules_status_on_admin', array( $this, 'codup_wc_pricing_table_notify_rules_status_on_admin' ) );
     60        add_action( 'wp_ajax_nopriv_codup_wc_pricing_table_notify_rules_status_on_admin', array( $this, 'codup_wc_pricing_table_notify_rules_status_on_admin' ) );
     61    }
     62
     63
    4864    /**
    4965     * Fetch show pricing table meta
    50      */
    51     public function codup_wc_pricing_table_show_table_meta($product_id){
    52         return get_post_meta($product_id, '_show_pricing_table', true);
    53     }
    54    
     66     *
     67     * @param int $product_id product_id.
     68     */
     69    public function codup_wc_pricing_table_show_table_meta( $product_id ) {
     70        return get_post_meta( $product_id, '_show_pricing_table', true );
     71    }
     72
    5573    /**
    5674     * Fetch pricing table location meta
    57      */
    58     public function codup_wc_pricing_table_location_meta($product_id){
    59         return get_post_meta($product_id, '_pricing_table_loc', true);
    60     }
    61    
     75     *
     76     * @param int $product_id product_id.
     77     */
     78    public function codup_wc_pricing_table_location_meta( $product_id ) {
     79        return get_post_meta( $product_id, '_pricing_table_loc', true );
     80    }
     81
    6282    /**
    6383     * Fetch tab label meta
    64      */
    65     public function codup_wc_pricing_table_tab_label_meta($product_id){
    66         return get_post_meta($product_id, '_tab_label', true);
    67     }
    68    
     84     *
     85     * @param int $product_id product_id.
     86     */
     87    public function codup_wc_pricing_table_tab_label_meta( $product_id ) {
     88        return get_post_meta( $product_id, '_tab_label', true );
     89    }
     90
    6991    /**
    7092     * Fetch quantity label meta
    71      */
    72     public function codup_wc_pricing_table_quantity_label_meta($product_id){
    73         return get_post_meta($product_id, '_qty_label', true);
    74        
    75     }
    76    
     93     *
     94     * @param int $product_id product_id.
     95     */
     96    public function codup_wc_pricing_table_quantity_label_meta( $product_id ) {
     97        return get_post_meta( $product_id, '_qty_label', true );
     98
     99    }
     100
    77101    /**
    78102     * Fetch discount label meta
    79      */
    80     public function codup_wc_pricing_table_discount_type_label_meta($product_id){
    81         return get_post_meta($product_id, '_discount_type_label', true);
    82     }
    83    
     103     *
     104     * @param int $product_id product_id.
     105     */
     106    public function codup_wc_pricing_table_discount_type_label_meta( $product_id ) {
     107        return get_post_meta( $product_id, '_discount_type_label', true );
     108    }
     109
    84110    /**
    85111     * Gets the dynamic pricing rules sets from the post meta.
    86      * @access  public
    87      * @since   1.0.0
    88      * @return  get_post_meta()
    89      */
    90     public function codup_wc_pricing_table_get_pricing_array_rule_sets(){
     112     */
     113    public function codup_wc_pricing_table_get_pricing_array_rule_sets() {
    91114        return get_post_meta( get_the_ID(), '_pricing_rules', true );
    92115    }
     
    94117    /**
    95118     * Add new tab if tab option is selected
    96      * @access  public
    97      * @since   1.0.0
    98      * @return  $tabs
    99      */
    100     public function codup_wc_pricing_table_add_tab_of_pricing_table( $tabs ){
     119     *
     120     * @param array $tabs tabs.
     121     */
     122    public function codup_wc_pricing_table_add_tab_of_pricing_table( $tabs ) {
    101123        global $product;
    102         $rules = [];
    103         $product_id = $product->get_id();
    104         $is_price_table_shown   = $this->codup_wc_pricing_table_show_table_meta($product_id);
    105         $pricing_table_location = $this->codup_wc_pricing_table_location_meta($product_id);
    106         $tab_label              = $this->codup_wc_pricing_table_tab_label_meta($product_id);
    107        
     124        $product_id             = $product->get_id();
     125        $is_price_table_shown   = $this->codup_wc_pricing_table_show_table_meta( $product_id );
     126        $pricing_table_location = $this->codup_wc_pricing_table_location_meta( $product_id );
     127        $tab_label              = $this->codup_wc_pricing_table_tab_label_meta( $product_id );
     128
    108129        $array_rule_sets = self::codup_wc_pricing_table_get_pricing_array_rule_sets();
    109         if(!empty($array_rule_sets)){
    110             $array_rule_sets_keys = array_keys($array_rule_sets);
    111             $rules = $array_rule_sets[$array_rule_sets_keys[0]];
    112         }
    113        
    114         if($is_price_table_shown == CodupWcShowPricingTableEnum::CHECKED &&
    115         $pricing_table_location == CodupWcPricingTableLocationEnum::IN_A_TAB &&
    116         $rules != null && ($rules['mode'] == 'continuous')&&
    117         ($rules['collector']['type'] == 'product')){
    118            
    119             $tab_label = !empty($tab_label) ? $tab_label : CodupWcPricingTableLabels::DEFAULT_TAB_LABEL;
     130        if ( ! empty( $array_rule_sets ) ) {
     131            $array_rule_sets_keys = array_keys( $array_rule_sets );
     132            $rules                = $array_rule_sets[ $array_rule_sets_keys[0] ];
     133        }
     134
     135        if ( CodupWcShowPricingTableEnum::CHECKED == $is_price_table_shown &&
     136        CodupWcPricingTableLocationEnum::IN_A_TAB == $pricing_table_location &&
     137        null != $rules && ( 'continuous' == $rules['mode'] ) &&
     138        ( 'product' == $rules['collector']['type'] ) ) {
     139
     140            $tab_label                 = ! empty( $tab_label ) ? $tab_label : CodupWcPricingTableLabels::DEFAULT_TAB_LABEL;
    120141            $tabs['pricing_table_tab'] = array(
    121                                             'title'     => __( $tab_label, 'woocommerce' ),
    122                                             'priority'  => 110,
    123                                             'callback'  => array($this, 'codup_wc_pricing_table_show_pricing_table_in_a_tab')
    124                                         );
     142                'title'    => $tab_label,
     143                'priority' => 110,
     144                'callback' => array( $this, 'codup_wc_pricing_table_show_pricing_table_in_a_tab' ),
     145            );
    125146        }
    126147        return $tabs;
    127148    }
    128     /**
    129      * Shows the table view in a tab
    130      * Gets the dynamic pricing rules and send rules as args to bulk pricing table function.
    131     */
    132     public function codup_wc_pricing_table_show_pricing_table_in_a_tab(){
    133    
    134         $array_rule_sets= $this-> codup_wc_pricing_table_get_pricing_array_rule_sets();
    135                
    136         if ($array_rule_sets && is_array( $array_rule_sets )){
     149
     150    /**
     151     * Shows the table view in a tab
     152     * Gets the dynamic pricing rules and send rules as args to bulk pricing table function.
     153     */
     154    public function codup_wc_pricing_table_show_pricing_table_in_a_tab() {
     155
     156        $array_rule_sets = $this->codup_wc_pricing_table_get_pricing_array_rule_sets();
     157
     158        if ( $array_rule_sets && is_array( $array_rule_sets ) ) {
    137159            global $product;
    138             $product_id= $product->get_id();
    139             $qty_label              = $this->codup_wc_pricing_table_quantity_label_meta($product_id);
    140             $discount_type_label    = $this->codup_wc_pricing_table_discount_type_label_meta($product_id);
    141             $qty_label              = !empty($qty_label) ?
     160            $product_id          = $product->get_id();
     161            $qty_label           = $this->codup_wc_pricing_table_quantity_label_meta( $product_id );
     162            $discount_type_label = $this->codup_wc_pricing_table_discount_type_label_meta( $product_id );
     163            $qty_label           = ! empty( $qty_label ) ?
    142164                                        $qty_label : CodupWcPricingTableLabels::DEFAULT_QUANTITY_LABEL;
    143             $discount_type_label    = !empty($discount_type_label) ?
     165            $discount_type_label = ! empty( $discount_type_label ) ?
    144166                                    $discount_type_label : CodupWcPricingTableLabels::DEFAULT_DISCOUNT_LABEL;
    145             __e( sprintf( __('<table class="wc-bulk-pricing-table"><th>%s</th><th>%s</th><th>Status</th>', 'wc-pricing-table' ), $qty_label, $discount_type_label) );
    146            
    147             foreach($array_rule_sets as $pricing_rule_sets){
    148                
    149                 if($pricing_rule_sets['mode'] == 'continuous'&& $pricing_rule_sets['collector']['type'] == 'product'){
    150            
    151                     if($pricing_rule_sets['conditions'][1]['args']['applies_to'] == 'everyone'){
    152                        
    153                         $this->codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets);   
    154                     }
    155                     else{
    156                         $roles= self::codup_wc_pricing_table_get_current_user_roles();
    157                        
    158                         if(is_array($roles)){
    159                        
    160                             foreach($roles as $role){
    161                        
    162                                 if (in_array($role, $pricing_rule_sets['conditions'][1]['args']['roles'])){
    163                                    
    164                                     self::codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets);
     167            echo wp_kses_post( sprintf( __( '<table class="wc-bulk-pricing-table"><th>%1$s</th><th>%2$s</th><th>Status</th>', 'wc-pricing-table' ), $qty_label, $discount_type_label ) );
     168
     169            foreach ( $array_rule_sets as $pricing_rule_sets ) {
     170
     171                if ( 'continuous' == $pricing_rule_sets['mode'] && 'product' == $pricing_rule_sets['collector']['type'] ) {
     172
     173                    if ( 'everyone' == $pricing_rule_sets['conditions'][1]['args']['applies_to'] ) {
     174
     175                        $this->codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets );
     176                    } else {
     177                        $roles = self::codup_wc_pricing_table_get_current_user_roles();
     178
     179                        if ( is_array( $roles ) ) {
     180
     181                            foreach ( $roles as $role ) {
     182
     183                                if ( in_array( $role, $pricing_rule_sets['conditions'][1]['args']['roles'] ) ) {
     184
     185                                    self::codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets );
    165186                                    break;
    166187                                }
    167188                            }
    168                         }
    169                         else if(in_array($roles, $pricing_rule_sets['conditions'][1]['args']['roles'])){
    170                            
    171                             self::codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets);
     189                        } elseif ( in_array( $roles, $pricing_rule_sets['conditions'][1]['args']['roles'] ) ) {
     190
     191                            self::codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets );
    172192                        }
    173193                    }
    174                 }   
     194                }
    175195            }
    176196            echo '</table>';
    177197        }
    178198    }
    179    
    180     /** 
    181      * Notify admin about expiration of pricing rules beside the dates 
     199
     200    /**
     201     * Notify admin about expiration of pricing rules beside the dates
    182202     * if the date is expired and send response to ajax
    183      * @since 1.0.0
    184      * @return
    185     */
    186     public function codup_wc_pricing_table_notify_rules_status_on_admin(){
    187 
    188         $iterator=0;
    189         $post_id = $_GET['postID'];
    190         $array_rule_sets= get_post_meta( $post_id, '_pricing_rules', true );
    191         $expiry_message='The date of this pricing rule is expired. Do you want to renew it?';
    192        
    193         foreach ($array_rule_sets as $pricing_rule_sets) {
    194             $is_date_valid=$this->codup_wc_pricing_table_is_time_duration_valid($pricing_rule_sets['date_from'], $pricing_rule_sets['date_to']);
    195            
    196             if (!$is_date_valid){
    197                
    198                 $date_array[$iterator]=$expiry_message;
    199                 $iterator++;           
    200             }
    201             else{
    202                
    203                 $date_array[$iterator]='';
     203     */
     204    public function codup_wc_pricing_table_notify_rules_status_on_admin() {
     205
     206        $iterator        = 0;
     207        $post_id         = isset( $_GET['postID'] ) ? sanitize_text_field( wp_unslash( $_GET['postID'] ) ) : '';
     208        $array_rule_sets = get_post_meta( $post_id, '_pricing_rules', true );
     209        $expiry_message  = 'The date of this pricing rule is expired. Do you want to renew it?';
     210
     211        foreach ( $array_rule_sets as $pricing_rule_sets ) {
     212            $is_date_valid = $this->codup_wc_pricing_table_is_time_duration_valid( $pricing_rule_sets['date_from'], $pricing_rule_sets['date_to'] );
     213
     214            if ( ! $is_date_valid ) {
     215
     216                $date_array[ $iterator ] = $expiry_message;
     217                $iterator++;
     218            } else {
     219
     220                $date_array[ $iterator ] = '';
    204221                $iterator++;
    205222            }
    206223        }
    207         wp_send_json($date_array);
     224        wp_send_json( $date_array );
    208225        die();
    209226    }
    210    
    211     /**
    212      * Notify expiration of pricing rules on the pricing table if the date is expired
    213     */
    214     public function codup_wc_pricing_table_notify_rules_on_pricing_table($is_date_valid){
    215        
    216         if(!$is_date_valid){
    217            
    218             $notify_expiration='<td><span>This offer has expired</span></td>';
     227
     228    /**
     229     * Notify expiration of pricing rules on the pricing table if the date is expired.
     230     *
     231     * @param boolean $is_date_valid is_date_valid.
     232     */
     233    public function codup_wc_pricing_table_notify_rules_on_pricing_table( $is_date_valid ) {
     234
     235        if ( ! $is_date_valid ) {
     236
     237            $notify_expiration = '<td><span>This offer has expired</span></td>';
    219238            return $notify_expiration;
    220         }
    221         else{
    222            
    223             $notify_expiration='<td><span>Available<span/></td>';
     239        } else {
     240
     241            $notify_expiration = '<td><span>Available<span/></td>';
    224242            return $notify_expiration;
    225243        }
    226244    }
    227245
    228     /** 
     246    /**
    229247     * Returns true if the current date is valid w.r.t. the time duration of pricing rule
    230      * @access public
    231      * @since  1.0.0
    232     */
    233     public function codup_wc_pricing_table_is_time_duration_valid($date_from, $date_to){
    234 
    235         $current_date=date('Y-m-d');
    236 
    237         if (empty($date_from) && empty($date_to)){
     248     *
     249     * @param string $date_from date_from.
     250     * @param string $date_to date_to.
     251     */
     252    public function codup_wc_pricing_table_is_time_duration_valid( $date_from, $date_to ) {
     253
     254        $current_date = date( 'Y-m-d' );
     255
     256        if ( empty( $date_from ) && empty( $date_to ) ) {
    238257            return true;
    239258        }
    240         if (!empty($date_from) && !empty($date_to) && $current_date >= $date_from && $current_date <= $date_to){
     259        if ( ! empty( $date_from ) && ! empty( $date_to ) && $current_date >= $date_from && $current_date <= $date_to ) {
    241260            return true;
    242261        }
    243         if (!empty($date_from) && empty($date_to) && $current_date >= $date_from){
     262        if ( ! empty( $date_from ) && empty( $date_to ) && $current_date >= $date_from ) {
    244263            return true;
    245264        }
    246         if (empty($date_from) && !empty($date_to) && $current_date <= $date_to){   
     265        if ( empty( $date_from ) && ! empty( $date_to ) && $current_date <= $date_to ) {
    247266            return true;
    248267        }
    249268        return false;
    250269    }
    251     /*
    252     * Returns roles or array of roles of the current logged in user
    253     * @access public
    254     * @since  1.0.0
    255     */
    256     public function codup_wc_pricing_table_get_current_user_roles(){
     270
     271    /**
     272     * Returns roles or array of roles of the current logged in user
     273     */
     274    public function codup_wc_pricing_table_get_current_user_roles() {
    257275        return wp_get_current_user()->roles;
    258276    }
    259    
     277
    260278    /**
    261279     * Shows table view with add to cart button
    262280     * Gets the dynamic pricing rules and send rules as args to bulk pricing table function.
    263      * @access  public
    264      * @since   1.0.0
    265      * @return  get_post_meta()
    266      */
    267     public function codup_wc_pricing_table_show_pricing_table(){
     281     */
     282    public function codup_wc_pricing_table_show_pricing_table() {
    268283        global $product;
    269         $product_id = $product->get_id();
    270         $is_price_table_shown   = $this->codup_wc_pricing_table_show_table_meta($product_id);
    271         $pricing_table_location = $this->codup_wc_pricing_table_location_meta($product_id);
    272        
    273         if($is_price_table_shown == CodupWcShowPricingTableEnum::CHECKED&& $pricing_table_location == CodupWcPricingTableLocationEnum::WITH_ADD_TO_CART_BUTTON){
    274            
     284        $product_id             = $product->get_id();
     285        $is_price_table_shown   = $this->codup_wc_pricing_table_show_table_meta( $product_id );
     286        $pricing_table_location = $this->codup_wc_pricing_table_location_meta( $product_id );
     287
     288        if ( CodupWcShowPricingTableEnum::CHECKED == $is_price_table_shown && CodupWcPricingTableLocationEnum::WITH_ADD_TO_CART_BUTTON == $pricing_table_location ) {
     289
    275290            $array_rule_sets = $this->codup_wc_pricing_table_get_pricing_array_rule_sets();
    276            
    277             if ($array_rule_sets && is_array( $array_rule_sets )){
    278                 $qty_label              = self::codup_wc_pricing_table_quantity_label_meta($product_id);
    279                 $discount_type_label    = self::codup_wc_pricing_table_discount_type_label_meta($product_id);
    280                 $qty_label              = !empty($qty_label) ?
     291
     292            if ( $array_rule_sets && is_array( $array_rule_sets ) ) {
     293                $qty_label           = self::codup_wc_pricing_table_quantity_label_meta( $product_id );
     294                $discount_type_label = self::codup_wc_pricing_table_discount_type_label_meta( $product_id );
     295                $qty_label           = ! empty( $qty_label ) ?
    281296                                            $qty_label : CodupWcPricingTableLabels::DEFAULT_QUANTITY_LABEL;
    282                 $discount_type_label    = !empty($discount_type_label) ?
     297                $discount_type_label = ! empty( $discount_type_label ) ?
    283298                                        $discount_type_label : CodupWcPricingTableLabels::DEFAULT_DISCOUNT_LABEL;
    284                 __e( sprintf( __('<table class="wc-bulk-pricing-table"><th>%s</th><th>%s</th><th>Status</th>', 'wc-pricing-table' ), $qty_label, $discount_type_label));
    285                
    286                 foreach($array_rule_sets as $pricing_rule_sets) {
    287                    
    288                     if($pricing_rule_sets['mode'] == 'continuous'&& $pricing_rule_sets['collector']['type'] == 'product'){
    289                
    290                         if($pricing_rule_sets['conditions'][1]['args']['applies_to'] == 'everyone'){
    291                            
    292                             $this->codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets);   
    293                         }
    294                         else{
    295                             $roles=$this-> codup_wc_pricing_table_get_current_user_roles();
    296                            
    297                             if(is_array($roles)){
    298                            
    299                                 foreach($roles as $role){
    300                            
    301                                     if (in_array($role, $pricing_rule_sets['conditions'][1]['args']['roles'])){
    302                                        
    303                                         $this->codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets);
     299                echo wp_kses_post( sprintf( __( '<table class="wc-bulk-pricing-table"><th>%1$s</th><th>%2$s</th><th>Status</th>', 'wc-pricing-table' ), $qty_label, $discount_type_label ) );
     300
     301                foreach ( $array_rule_sets as $pricing_rule_sets ) {
     302
     303                    if ( 'continuous' == $pricing_rule_sets['mode'] && 'product' == $pricing_rule_sets['collector']['type'] ) {
     304
     305                        if ( 'everyone' == $pricing_rule_sets['conditions'][1]['args']['applies_to'] ) {
     306
     307                            $this->codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets );
     308                        } else {
     309                            $roles = $this->codup_wc_pricing_table_get_current_user_roles();
     310
     311                            if ( is_array( $roles ) ) {
     312
     313                                foreach ( $roles as $role ) {
     314
     315                                    if ( in_array( $role, $pricing_rule_sets['conditions'][1]['args']['roles'] ) ) {
     316
     317                                        $this->codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets );
    304318                                        break;
    305319                                    }
    306320                                }
    307                             }
    308                             else if(in_array($roles, $pricing_rule_sets['conditions'][1]['args']['roles'])){
    309                                
    310                                 $this->codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets);
     321                            } elseif ( in_array( $roles, $pricing_rule_sets['conditions'][1]['args']['roles'] ) ) {
     322
     323                                $this->codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets );
    311324                            }
    312325                        }
    313                     }   
     326                    }
    314327                }
    315328                echo '</table>';
     
    317330        }
    318331    }
    319    
    320     /**
    321      * Outputs pricing table when 'Applies To' set on Everyone, 'Quantities' set to Product Quantity, 
     332
     333    /**
     334     * Outputs pricing table when 'Applies To' set on Everyone, 'Quantities' set to Product Quantity,
    322335     * 'Rule processing mode' set to Bulk and 'Type' is set to Price Discount.
    323      * @access  public
    324      * @since   1.0.0
    325      * @return  $output
    326      */
    327     public function codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets){
    328        
    329         $is_any_price_discount_item = current(array_filter($pricing_rule_sets['rules'], function($item){
    330             return isset($item['type']);
    331         }));
    332        
    333         if($is_any_price_discount_item){
    334            
    335             include(CODUP_WC_PRICING_TABLE_TEMPLATE_PATH. 'wc-pricing-table-template.php' );
    336         }
    337    
    338     }
    339    
     336     *
     337     * @param array $pricing_rule_sets pricing_rule_sets.
     338     */
     339    public function codup_wc_pricing_table_bulk_pricing_table_output( $pricing_rule_sets ) {
     340
     341        $is_any_price_discount_item = current(
     342            array_filter(
     343                $pricing_rule_sets['rules'],
     344                function( $item ) {
     345                    return isset( $item['type'] );
     346                }
     347            )
     348        );
     349
     350        if ( $is_any_price_discount_item ) {
     351
     352            include CODUP_WC_PRICING_TABLE_TEMPLATE_PATH . 'wc-pricing-table-template.php';
     353        }
     354
     355    }
     356
    340357}
    341358
  • codup-woocommerce-dynamic-pricing-table-view/trunk/includes/class-wc-pricing-table-settings.php

    r2715246 r2735659  
    11<?php
     2/**
     3 * CodupWcPricingTableSettings Class File.
     4 */
     5
    26if ( ! defined( 'ABSPATH' ) ) {
    37    exit;
    48}
    59
    6 class CodupWcPricingTableSettings{
    7    
     10/**
     11 * CodupWcPricingTableSettings Class.
     12 */
     13class CodupWcPricingTableSettings {
     14
    815    /** @var object Class Instance */
    916    private static $instance;
    10    
     17
    1118    /**
    1219     * Get the class instance
    1320     */
    14     public static function get_instance(){
    15         return null === self::$instance ? ( self::$instance = new self ) : self::$instance;
     21    public static function get_instance() {
     22        return null === self::$instance ? ( self::$instance = new self() ) : self::$instance;
    1623    }
    17    
    18     public function __construct(){
    19        
    20         //  Add admin scripts
     24
     25    /**
     26     * Construct.
     27     */
     28    public function __construct() {
     29
     30        // Add admin scripts.
    2131        add_action( 'admin_enqueue_scripts', array( $this, 'codup_wc_pricing_table_enqueue_scripts' ) );
    2232
    23         //  Add admin styles
     33        // Add admin styles.
    2434        add_action( 'admin_enqueue_scripts', array( $this, 'codup_wc_pricing_table_enqueue_styles' ) );
    25        
    26         //  Add Pricing Table Tab
    27         add_action('woocommerce_product_write_panel_tabs', array( $this, 'codup_wc_pricing_table_add_pricing_table_opt_tab') );
    28        
    29         //  Add options for Pricing table tab
    30         add_action('woocommerce_product_data_panels', array( $this, 'codup_wc_pricing_table_add_pricing_table_tab_options') );
    31        
    3235
    33         //  Process meta fields of pricing table tab
    34         add_action('woocommerce_process_product_meta', array( $this, 'codup_wc_pricing_table_get_settings_of_table') );
     36        // Add Pricing Table Tab.
     37        add_action( 'woocommerce_product_write_panel_tabs', array( $this, 'codup_wc_pricing_table_add_pricing_table_opt_tab' ) );
    3538
    36         //    Add Codup Ads Placement       
    37         add_action('admin_notices', array($this, 'codup_wc_pricing_table_ads_placement'));
     39        // Add options for Pricing table tab.
     40        add_action( 'woocommerce_product_data_panels', array( $this, 'codup_wc_pricing_table_add_pricing_table_tab_options' ) );
     41
     42        // Process meta fields of pricing table tab.
     43        add_action( 'woocommerce_process_product_meta', array( $this, 'codup_wc_pricing_table_get_settings_of_table' ) );
     44
     45        // Add Codup Ads Placement.
     46        add_action( 'admin_notices', array( $this, 'codup_wc_pricing_table_ads_placement' ) );
    3847    }
    39    
    40     public function codup_wc_pricing_table_ads_placement(){
     48
     49    /**
     50     * Placement Function.
     51     */
     52    public function codup_wc_pricing_table_ads_placement() {
    4153        $screen = get_current_screen();
    42         $p_id = $screen->id;
    43            
    44         if($p_id == 'product') {
    45             echo do_shortcode("[codup_ads_top]");
     54        $p_id   = $screen->id;
     55
     56        if ( 'product' == $p_id ) {
     57            echo do_shortcode( '[codup_ads_top]' );
    4658        }
    4759
    4860    }
    49     /**
     61
     62    /**
    5063     * Enqueues styles apllies on the table
    51     */
    52     public function codup_wc_pricing_table_enqueue_styles(){
    53         wp_enqueue_style( 'wc-pp-admin-css', CODUP_WC_PRICING_TABLE_PLUGIN_URL. '/assets/js/wc-pricing-table-admin-css.css');
     64     */
     65    public function codup_wc_pricing_table_enqueue_styles() {
     66        wp_enqueue_style( 'wc-pp-admin-css', CODUP_WC_PRICING_TABLE_PLUGIN_URL . '/assets/js/wc-pricing-table-admin-css.css', array(), rand() );
    5467    }
    55     /**
     68
     69    /**
    5670     * Enqueues scripts applies on the table
    57     */
    58     public function codup_wc_pricing_table_enqueue_scripts(){
    59         wp_enqueue_script( 'wc-pp-admin-js', CODUP_WC_PRICING_TABLE_PLUGIN_URL. '/assets/js/wc-pricing-table-admin.js', array( 'jquery' ), CODUP_WC_PRICING_TABLE_VERSION, false );
     71     */
     72    public function codup_wc_pricing_table_enqueue_scripts() {
     73        wp_enqueue_script( 'wc-pp-admin-js', CODUP_WC_PRICING_TABLE_PLUGIN_URL . '/assets/js/wc-pricing-table-admin.js', array( 'jquery' ), CODUP_WC_PRICING_TABLE_VERSION, false );
    6074    }
    61    
     75
    6276    /**
    6377     * Custom pricing table tab
     
    6579     * Outputs an extra tab to the default set of info tabs on the single product page.
    6680     */
    67     public function codup_wc_pricing_table_add_pricing_table_opt_tab(){
    68         include_once(CODUP_WC_PRICING_TABLE_TEMPLATE_PATH . 'wc-pricing-table-tab.php' );
     81    public function codup_wc_pricing_table_add_pricing_table_opt_tab() {
     82        include_once CODUP_WC_PRICING_TABLE_TEMPLATE_PATH . 'wc-pricing-table-tab.php';
    6983    }
    70    
     84
    7185    /**
    7286     * Pricing Table Tab Options
     
    7488     * Provides the input fields and add/remove buttons for custom tabs on the single product page.
    7589     */
    76     public function codup_wc_pricing_table_add_pricing_table_tab_options(){
    77         include_once(CODUP_WC_PRICING_TABLE_TEMPLATE_PATH . 'wc-pricing-table-tab-options.php' );
     90    public function codup_wc_pricing_table_add_pricing_table_tab_options() {
     91        include_once CODUP_WC_PRICING_TABLE_TEMPLATE_PATH . 'wc-pricing-table-tab-options.php';
    7892    }
    79    
     93
    8094    /**
    8195     * Gets the values of text boxes and radio button from front-end
    82      *
    8396     */
    84     public function codup_wc_pricing_table_get_settings_of_table(){
    85        
    86         $table_view_settings['_show_pricing_field']= (isset($_POST['_show_pricing_table']) && $_POST['_show_pricing_table'] )
    87                                     ? CodupWcShowPricingTableEnum::CHECKED : CodupWcShowPricingTableEnum::UNCHECKED;
    88         $table_view_settings['_pricing_table_loc']= (isset($_POST['_pricing_table_loc'])&& $_POST['_pricing_table_loc'])
    89                                     ? $_POST['_pricing_table_loc'] : CodupWcPricingTableLocationEnum::WITH_ADD_TO_CART_BUTTON;
    90         $table_view_settings['_tab_label']= ( $table_view_settings['_pricing_table_loc'] == CodupWcPricingTableLocationEnum::IN_A_TAB && !empty( $_POST['_tab_label'])) ? $_POST['_tab_label'] : '';
    91         $table_view_settings['_qty_label']= sanitize_text_field($_POST['_qty_label']);
    92         $table_view_settings['_discount_type_label']= sanitize_text_field($_POST['_discount_type_label']);
    93        
    94         $table_view_settings['price_discount_txt_loc']= ( isset($_POST['_price_discount_loc']) ) ? sanitize_text_field($_POST['_price_discount_loc']) : CodupWcPricingTableDiscountTypeLoc::SUFFIX;
    95         $table_view_settings['price_discount_txt']= ( isset($_POST['_price_discount_txt_field']) ) ? sanitize_text_field( $_POST['_price_discount_txt_field']) : '';
     97    public function codup_wc_pricing_table_get_settings_of_table() {
    9698
    97         $table_view_settings['percentage_discount_txt_loc']= ( isset($_POST['_percentage_discount_loc']) ) ? sanitize_text_field($_POST['_percentage_discount_loc']) : CodupWcPricingTableDiscountTypeLoc::SUFFIX;
    98         $table_view_settings['percentage_discount_txt']= ( isset($_POST['_percentage_discount_txt_field']) ) ? sanitize_text_field($_POST['_percentage_discount_txt_field']) : '';
     99        $table_view_settings['_show_pricing_field'] = isset( $_POST['_show_pricing_table'] ) ? sanitize_text_field( wp_unslash( $_POST['_show_pricing_table'] ) ) : wp_kses_post( CodupWcShowPricingTableEnum::UNCHECKED );
    99100
    100         $table_view_settings['fixed_price_txt_loc']= ( isset($_POST['_fixed_price_loc']) ) ? sanitize_text_field($_POST['_fixed_price_loc']) : CodupWcPricingTableDiscountTypeLoc::SUFFIX;
    101         $table_view_settings['fixed_price_txt']= ( isset($_POST['_fixed_price_txt_field']) ) ? sanitize_text_field($_POST['_fixed_price_txt_field']) : '';
    102        
    103         $this->codup_wc_pricing_table_save_config ($table_view_settings);
     101        $table_view_settings['_pricing_table_loc'] = isset( $_POST['_pricing_table_loc'] ) ? sanitize_text_field( wp_unslash( $_POST['_pricing_table_loc'] ) ) : wp_kses_post( CodupWcPricingTableLocationEnum::WITH_ADD_TO_CART_BUTTON );
     102
     103        $table_view_settings['_tab_label'] = ( $table_view_settings['_pricing_table_loc'] == wp_kses_post( CodupWcPricingTableLocationEnum::IN_A_TAB ) && ! empty( $_POST['_tab_label'] ) ) ? sanitize_text_field( wp_unslash( $_POST['_tab_label'] ) ) : '';
     104
     105        $table_view_settings['_qty_label'] = isset( $_POST['_qty_label'] ) ? sanitize_text_field( wp_unslash( $_POST['_qty_label'] ) ) : wp_kses_post( CodupWcPricingTableLabels::DEFAULT_QUANTITY_LABEL );
     106
     107        $table_view_settings['_discount_type_label'] = isset( $_POST['_discount_type_label'] ) ? sanitize_text_field( wp_unslash( $_POST['_discount_type_label'] ) ) : wp_kses_post( CodupWcPricingTableLabels::DEFAULT_DISCOUNT_LABEL );
     108
     109        $table_view_settings['price_discount_txt_loc'] = isset( $_POST['_price_discount_loc'] ) ? sanitize_text_field( wp_unslash( $_POST['_price_discount_loc'] ) ) : wp_kses_post( CodupWcPricingTableDiscountTypeLoc::SUFFIX );
     110
     111        $table_view_settings['price_discount_txt'] = isset( $_POST['_price_discount_txt_field'] ) ? sanitize_text_field( wp_unslash( $_POST['_price_discount_txt_field'] ) ) : '';
     112
     113        $table_view_settings['percentage_discount_txt_loc'] = isset( $_POST['_percentage_discount_loc'] ) ? sanitize_text_field( wp_unslash( $_POST['_percentage_discount_loc'] ) ) : wp_kses_post( CodupWcPricingTableDiscountTypeLoc::SUFFIX );
     114
     115        $table_view_settings['percentage_discount_txt'] = isset( $_POST['_percentage_discount_txt_field'] ) ? sanitize_text_field( wp_unslash( $_POST['_percentage_discount_txt_field'] ) ) : '';
     116
     117        $table_view_settings['fixed_price_txt_loc'] = isset( $_POST['_fixed_price_loc'] ) ? sanitize_text_field( wp_unslash( $_POST['_fixed_price_loc'] ) ) : wp_kses_post( CodupWcPricingTableDiscountTypeLoc::SUFFIX );
     118
     119        $table_view_settings['fixed_price_txt'] = isset( $_POST['_fixed_price_txt_field'] ) ? sanitize_text_field( wp_unslash( $_POST['_fixed_price_txt_field'] ) ) : '';
     120
     121        $this->codup_wc_pricing_table_save_config( $table_view_settings );
    104122
    105123    }
    106    
     124
    107125    /**
    108126     * Save pricing table settings
    109      * @param table_view_settings
     127     *
     128     * @param array $table_view_settings table_view_settings.
    110129     */
    111      public function codup_wc_pricing_table_save_config($table_view_settings){
     130    public function codup_wc_pricing_table_save_config( $table_view_settings ) {
    112131        global $post;
    113         update_post_meta( $post->ID, '_show_pricing_table', esc_attr($table_view_settings['_show_pricing_field']));
    114         update_post_meta( $post->ID, '_pricing_table_loc', esc_attr($table_view_settings['_pricing_table_loc']));
    115         update_post_meta( $post->ID, '_tab_label', esc_attr($table_view_settings['_tab_label']));
    116         update_post_meta( $post->ID, '_qty_label', esc_attr($table_view_settings['_qty_label'])) ;
    117         update_post_meta( $post->ID, '_discount_type_label', esc_attr($table_view_settings['_discount_type_label']));
    118        
    119         update_post_meta( $post->ID, '_price_discount_loc', esc_attr($table_view_settings['price_discount_txt_loc']));
    120         update_post_meta( $post->ID, '_price_discount_txt_field', esc_attr($table_view_settings['price_discount_txt']));
    121         update_post_meta( $post->ID, '_percentage_discount_loc', esc_attr($table_view_settings['percentage_discount_txt_loc']));
    122         update_post_meta( $post->ID, '_percentage_discount_txt_field', esc_attr($table_view_settings['percentage_discount_txt']));
    123         update_post_meta( $post->ID, '_fixed_price_loc', esc_attr($table_view_settings['fixed_price_txt_loc']));
    124         update_post_meta( $post->ID, '_fixed_price_txt_field', esc_attr($table_view_settings['fixed_price_txt']));
     132        update_post_meta( $post->ID, '_show_pricing_table', esc_attr( $table_view_settings['_show_pricing_field'] ) );
     133        update_post_meta( $post->ID, '_pricing_table_loc', esc_attr( $table_view_settings['_pricing_table_loc'] ) );
     134        update_post_meta( $post->ID, '_tab_label', esc_attr( $table_view_settings['_tab_label'] ) );
     135        update_post_meta( $post->ID, '_qty_label', esc_attr( $table_view_settings['_qty_label'] ) );
     136        update_post_meta( $post->ID, '_discount_type_label', esc_attr( $table_view_settings['_discount_type_label'] ) );
     137
     138        update_post_meta( $post->ID, '_price_discount_loc', esc_attr( $table_view_settings['price_discount_txt_loc'] ) );
     139        update_post_meta( $post->ID, '_price_discount_txt_field', esc_attr( $table_view_settings['price_discount_txt'] ) );
     140        update_post_meta( $post->ID, '_percentage_discount_loc', esc_attr( $table_view_settings['percentage_discount_txt_loc'] ) );
     141        update_post_meta( $post->ID, '_percentage_discount_txt_field', esc_attr( $table_view_settings['percentage_discount_txt'] ) );
     142        update_post_meta( $post->ID, '_fixed_price_loc', esc_attr( $table_view_settings['fixed_price_txt_loc'] ) );
     143        update_post_meta( $post->ID, '_fixed_price_txt_field', esc_attr( $table_view_settings['fixed_price_txt'] ) );
    125144
    126145    }
    127    
     146
    128147}
    129148
  • codup-woocommerce-dynamic-pricing-table-view/trunk/includes/wc-pricing-table-enums.php

    r2142532 r2735659  
    11<?php
     2/**
     3 * Class for defining Enums.
     4 *
     5 */
    26if ( ! defined( 'ABSPATH' ) ) {
    37    exit;
    48}
    59
    6 abstract class CodupWcPricingTableLocationEnum{
    7    
    8     const WITH_ADD_TO_CART_BUTTON= 1;
    9     const IN_A_TAB= 2;
     10abstract class CodupWcPricingTableLocationEnum {
     11
     12    const WITH_ADD_TO_CART_BUTTON = 1;
     13    const IN_A_TAB                = 2;
    1014}
    1115
    12 abstract class CodupWcShowPricingTableEnum{
    13    
    14     const CHECKED= 'yes';
    15     const UNCHECKED= 'no';
     16abstract class CodupWcShowPricingTableEnum {
     17
     18    const CHECKED   = 'yes';
     19    const UNCHECKED = 'no';
    1620}
    1721
    18 abstract class CodupWcPricingTableLabels{
    19    
    20     const DEFAULT_TAB_LABEL= 'Pricing Table';
    21     const DEFAULT_QUANTITY_LABEL= 'Quantity';
    22     const DEFAULT_DISCOUNT_LABEL= 'Discount';
     22abstract class CodupWcPricingTableLabels {
     23
     24    const DEFAULT_TAB_LABEL      = 'Pricing Table';
     25    const DEFAULT_QUANTITY_LABEL = 'Quantity';
     26    const DEFAULT_DISCOUNT_LABEL = 'Discount';
    2327}
    2428
    25 abstract class CodupWcPricingTableDiscountTypeLoc{
    26    
    27     const PREFIX= 1;
    28     const SUFFIX= 2;
     29abstract class CodupWcPricingTableDiscountTypeLoc {
     30
     31    const PREFIX = 1;
     32    const SUFFIX = 2;
    2933}
  • codup-woocommerce-dynamic-pricing-table-view/trunk/readme.txt

    r2715246 r2735659  
    22Contributors: Codup
    33Tags: WooCommerce, Dynamic Pricing Table, Discount Table
    4 Requires at least: 5.0.1
    5 Tested up to: 5.9.1
    6 WC requires at least: 3.0
    7 WC tested up to: 4.0.1
     4Requires at least: 5.0.0
     5Tested up to: 5.9.2
    86Stable tag: 1.2.1.5
     7WC requires at least: 4.0.0
     8WC tested up to: 6.3.1
    99License: GPLv2 or later
    1010
  • codup-woocommerce-dynamic-pricing-table-view/trunk/templates/wc-pricing-table-template.php

    r2142532 r2735659  
    7171    }
    7272}
    73  echo $output;
     73_e($output);
Note: See TracChangeset for help on using the changeset viewer.