get_option() публичный статический Метод

Get a setting from the settings API.
public static get_option ( mixed $option_name, $default = '' ) : string
$option_name mixed
Результат string
Пример #1
0
    /**
     * Outputs a custom textarea template in plugin options panel
     *
     * @since   1.0.0
     * @return  void
     * @author  Alberto Ruggiero
     */
    public static function output($option)
    {
        $custom_attributes = array();
        if (!empty($option['custom_attributes']) && is_array($option['custom_attributes'])) {
            foreach ($option['custom_attributes'] as $attribute => $attribute_value) {
                $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"';
            }
        }
        $option_value = WC_Admin_Settings::get_option($option['id'], $option['default']);
        ?>
        <tr valign="top">
            <th scope="row" class="titledesc">
                <label for="<?php 
        echo esc_attr($option['id']);
        ?>
"><?php 
        echo esc_html($option['title']);
        ?>
</label>
            </th>
            <td class="forminp forminp-<?php 
        echo sanitize_title($option['type']);
        ?>
">

                <textarea
                    name="<?php 
        echo esc_attr($option['id']);
        ?>
"
                    id="<?php 
        echo esc_attr($option['id']);
        ?>
"
                    style="<?php 
        echo esc_attr($option['css']);
        ?>
"
                    class="<?php 
        echo esc_attr($option['class']);
        ?>
"
                    <?php 
        echo implode(' ', $custom_attributes);
        ?>
                    ><?php 
        echo esc_textarea($option_value);
        ?>
</textarea><br /><br />
                <span class="description"><?php 
        echo $option['desc'];
        ?>
</span>
            </td>
        </tr>
    <?php 
    }
 /**
  * Load user options into class
  *
  * @return void
  */
 protected function load_options()
 {
     $this->enabled = $this->get_option('enabled');
     $this->registration_enabled = WC_Admin_Settings::get_option('woocommerce_enable_signup_and_login_from_checkout') === 'yes' ? true : false;
     $this->profiles_enabled = $this->registration_enabled && $this->get_option('enable_profiles') === 'yes';
     $this->title = $this->get_option('title');
     $this->description = $this->get_option('description');
     $this->card_types = $this->get_option('card_types');
     $this->mode = $this->get_option('mode', 'capture');
     $this->sandbox = $this->get_option('sandbox');
     $this->site = $this->get_option('site');
     $this->env_key = $this->sandbox == 'no' ? 'production' : 'sandbox';
     $port = $this->cc_ports[$this->env_key];
     $this->api_credentials = array('url' => "https://{$this->site}.{$this->domain}:{$port}{$this->rest_path}", 'mid' => $this->get_option("{$this->env_key}_mid"), 'user' => $this->get_option("{$this->env_key}_user"), 'pass' => $this->get_option("{$this->env_key}_password"));
     $this->verification = array('void_cvv' => $this->get_option('void_cvv'), 'void_avs' => $this->get_option('void_avs'));
 }
        public function hidden_field($value)
        {
            $option_value = WC_Admin_Settings::get_option($value['id'], $value['default']);
            ?>
		<tr valign="top" style="display: none">
			<th class="forminp forminp-image">
				 <input type="hidden" id="<?php 
            echo esc_attr($value['id']);
            ?>
" value="<?php 
            echo esc_attr($option_value);
            ?>
" name="<?php 
            echo esc_attr($value['id']);
            ?>
" />
			</th>
		</tr>
		<?php 
        }
        /**
         * Create new Woocommerce admin field: yith_ywzm_image_width
         *
         * @access public
         * @param array $value
         * @return void
         * @since 1.1.3
         */
        public function admin_fields_yith_ywzm_image_width($value)
        {
            $width = WC_Admin_Settings::get_option($value['id'] . '[width]', $value['default']['width']);
            $height = WC_Admin_Settings::get_option($value['id'] . '[height]', $value['default']['height']);
            $crop = WC_Admin_Settings::get_option($value['id'] . '[crop]');
            $crop = $crop == 'on' || $crop == '1' ? 1 : 0;
            $crop = checked(1, $crop, false);
            ?>
<tr valign="top">
			<th scope="row" class="titledesc"><?php 
            echo esc_html($value['title']);
            ?>
</th>
			<td class="forminp image_width_settings">
				<input name="<?php 
            echo esc_attr($value['id']);
            ?>
[width]" id="<?php 
            echo esc_attr($value['id']);
            ?>
-width" type="text" size="3" value="<?php 
            echo $width;
            ?>
" /> &times; <input name="<?php 
            echo esc_attr($value['id']);
            ?>
[height]" id="<?php 
            echo esc_attr($value['id']);
            ?>
-height" type="text" size="3" value="<?php 
            echo $height;
            ?>
" />px <span class="description"><?php 
            echo $value['desc'];
            ?>
</span>
<br>
				<label><input name="<?php 
            echo esc_attr($value['id']);
            ?>
[crop]" id="<?php 
            echo esc_attr($value['id']);
            ?>
-crop" type="checkbox" <?php 
            echo $crop;
            ?>
 /> <?php 
            _e('Do you want to hard crop the image?', 'woocommerce');
            ?>
</label>

			</td>
			</tr><?php 
        }
Пример #5
0
/**
 * Get a setting from the settings API.
 *
 * @param mixed $option
 * @return string
 */
function woocommerce_settings_get_option($option_name, $default = '')
{
    if (!class_exists('WC_Admin_Settings')) {
        include 'class-wc-admin-settings.php';
    }
    return WC_Admin_Settings::get_option($option_name, $default);
}
    /**
     * SendinBlue templates on Email options section
     */
    public function ws_sendinblue_templates()
    {
        $email_templates = array('ws_new_order_template' => '', 'ws_processing_order_template' => '', 'ws_refunded_order_template' => '', 'ws_cancelled_order_template' => '', 'ws_completed_order_template' => '', 'ws_new_account_template' => '');
        $templates = WC_Sendinblue::$templates;
        foreach ($email_templates as $key => $content) {
            $option_value = WC_Admin_Settings::get_option($key, '0');
            $email_templates[$key] = '<select name="' . $key . '" id="' . $key . '">';
            $email_templates[$key] .= '<option value="0" > - Choose Template - </option>';
            foreach ($templates as $id => $val) {
                $email_templates[$key] .= '<option value="' . $id . '" ' . selected($option_value, $id, false) . '>' . $val['name'] . '</option>';
            }
            $email_templates[$key] .= '</select>';
        }
        ?>

        <table class="form-table">
            <tbody><tr valign="top">
                <th scope="row" class="titledesc">
                    <label for=""><?php 
        _e('SendinBlue Templates', 'wc_sendinblue');
        ?>
</label>
                </th>
                <td class="forminp">
                    <table class="form-ws-table">
                        <tr>
                            <td><label for="ws_new_order_template"><?php 
        _e('New order', 'wc_sendinblue');
        ?>
</label></td><td><?php 
        echo $email_templates['ws_new_order_template'];
        ?>
</td>
                            <td><label for="ws_processing_order_template"><?php 
        _e('Processing order', 'wc_sendinblue');
        ?>
</label></td><td><?php 
        echo $email_templates['ws_processing_order_template'];
        ?>
</td>
                        </tr>
                        <tr>
                            <td><label for="ws_refunded_order_template"><?php 
        _e('Refunded order', 'wc_sendinblue');
        ?>
</label></td><td><?php 
        echo $email_templates['ws_refunded_order_template'];
        ?>
</td>
                            <td><label for="ws_cancelled_order_template"><?php 
        _e('Cancelled order', 'wc_sendinblue');
        ?>
</label></td><td><?php 
        echo $email_templates['ws_cancelled_order_template'];
        ?>
</td>
                        </tr>
                        <tr>
                            <td><label for="ws_completed_order_template"><?php 
        _e('Completed order', 'wc_sendinblue');
        ?>
</label></td><td><?php 
        echo $email_templates['ws_completed_order_template'];
        ?>
</td>
                            <td><label for="ws_new_account_template"><?php 
        _e('New account', 'wc_sendinblue');
        ?>
</label></td><td><?php 
        echo $email_templates['ws_new_account_template'];
        ?>
</td>
                        </tr>
                    </table>
                </td>
            </tr>
            </tbody>
        </table>
    <?php 
    }
Пример #7
0
        /**
         * Output image select field
         */
        public function output_image_select($value)
        {
            // Define the defaults
            if (!isset($value['title_select'])) {
                $value['title_select'] = __('Select', 'woocommerce-delivery-notes');
            }
            if (!isset($value['title_remove'])) {
                $value['title_remove'] = __('Remove', 'woocommerce-delivery-notes');
            }
            // Get additional data fields
            $field = WC_Admin_Settings::get_field_description($value);
            $description = $field['description'];
            $tooltip_html = $field['tooltip_html'];
            $option_value = WC_Admin_Settings::get_option($value['id'], $value['default']);
            $class_name = 'wcdn-image-select';
            ?>
<tr valign="top">
				<th scope="row" class="titledesc">
					<label for="<?php 
            echo esc_attr($value['id']);
            ?>
"><?php 
            echo esc_html($value['title']);
            ?>
 <?php 
            echo $tooltip_html;
            ?>
</label>
				</th>
				<td class="forminp image_width_settings">
					<input name="<?php 
            echo esc_attr($value['id']);
            ?>
" id="<?php 
            echo esc_attr($value['id']);
            ?>
" type="hidden" value="<?php 
            echo esc_attr($option_value);
            ?>
" class="<?php 
            echo $class_name;
            ?>
-image-id <?php 
            echo esc_attr($value['class']);
            ?>
" />
					
					<div id="<?php 
            echo esc_attr($value['id']);
            ?>
_field" class="<?php 
            echo $class_name;
            ?>
-field <?php 
            echo esc_attr($value['class']);
            ?>
" style="<?php 
            echo esc_attr($value['css']);
            ?>
">
						<span id="<?php 
            echo esc_attr($value['id']);
            ?>
_spinner" class="<?php 
            echo $class_name;
            ?>
-spinner spinner"></span>
						<div id="<?php 
            echo esc_attr($value['id']);
            ?>
_attachment" class="<?php 
            echo $class_name;
            ?>
-attachment <?php 
            echo esc_attr($value['class']);
            ?>
 ">
							<div class="thumbnail">
								<div class="centered">
								<?php 
            if (!empty($option_value)) {
                ?>
									<?php 
                $this->create_image($option_value);
                ?>
								<?php 
            }
            ?>
								</div>
							</div>
						</div>
						
						<div id="<?php 
            echo esc_attr($value['id']);
            ?>
_buttons" class="<?php 
            echo $class_name;
            ?>
-buttons <?php 
            echo esc_attr($value['class']);
            ?>
">
							<a href="#" id="<?php 
            echo esc_attr($value['id']);
            ?>
_remove_button" class="<?php 
            echo $class_name;
            ?>
-remove-button <?php 
            if (empty($option_value)) {
                ?>
hidden<?php 
            }
            ?>
 button">
								<?php 
            echo esc_html($value['title_remove']);
            ?>
							</a>
							<a href="#" id="<?php 
            echo esc_attr($value['id']);
            ?>
_add_button" class="<?php 
            echo $class_name;
            ?>
-add-button <?php 
            if (!empty($option_value)) {
                ?>
hidden<?php 
            }
            ?>
 button" data-uploader-title="<?php 
            echo esc_attr($value['title']);
            ?>
" data-uploader-button-title="<?php 
            echo esc_attr($value['title_select']);
            ?>
">
								<?php 
            echo esc_html($value['title_select']);
            ?>
							</a>
						</div>					
					</div>
					
					<?php 
            echo $description;
            ?>
				</td>
			</tr><?php 
        }
 public function generate_iframe_src($order_id = 0, $query_args = array())
 {
     /**
      * If we do not have a valid array, make it so.
      */
     if (!is_array($query_args)) {
         $query_args = array();
     }
     /**
      * Set the PROGRAM_ID, ORDER_ID, and INT args which are required for the URL
      */
     $query_args['PROGRAM_ID'] = WC_Admin_Settings::get_option('woocommerce_ebay_affiliate_pid', '');
     $query_args['ORDER_ID'] = $order_id;
     $query_args['INT'] = 'DYNAMIC';
     return add_query_arg($query_args, $this->endpoint);
 }
Пример #9
0
 public function get_sql($account_customer_emails = '')
 {
     global $wpdb;
     $identifier = get_option('woocommerce_crm_unique_identifier');
     $display_name = get_option('woocommerce_crm_customer_name');
     $woocommerce_crm_user_roles = get_option('woocommerce_crm_user_roles');
     if (!$woocommerce_crm_user_roles || empty($woocommerce_crm_user_roles)) {
         $woocommerce_crm_user_roles[] = 'customer';
     }
     $add_guest_customers = WC_Admin_Settings::get_option('woocommerce_crm_guest_customers', 'yes');
     $user_role_filter = '';
     foreach ($woocommerce_crm_user_roles as $value) {
         if (!empty($user_role_filter)) {
             $user_role_filter .= ' OR ';
         }
         $user_role_filter .= "customer.capabilities LIKE '%{$value}%'";
     }
     /******************/
     $filter = '';
     $join = '';
     $inner = '';
     $select = '';
     /******************/
     $select .= ', total_value.o_total as order_value';
     $orders_status = get_option('woocommerce_crm_total_value');
     if (!$orders_status || empty($orders_status)) {
         $orders_status[] = 'wc-completed';
     }
     $orders_statuses = "'" . implode("','", $orders_status) . "'";
     $order_types = "'" . implode("','", wc_get_order_types('order-count')) . "'";
     if ($identifier == 'username_email') {
         $new_sql = "SELECT IF( pmc.meta_value = 0, CONCAT(pmc.meta_value, '-', pmc_email.meta_value), pmc.meta_value)  AS userUniqueID, pmc.meta_value as user_id, pmc_email.meta_value as user_email, SUM(pmc_total.meta_value) as o_total\n            FROM {$wpdb->postmeta} as pmc\n            LEFT JOIN {$wpdb->postmeta} pmc_email\n              ON ( pmc.meta_key = '_customer_user' AND pmc_email.meta_key = '_billing_email' AND pmc.post_id = pmc_email.post_id)\n\n            LEFT JOIN {$wpdb->postmeta} pmc_total\n              ON ( pmc_total.meta_key = '_order_total' AND pmc.post_id = pmc_total.post_id) \n\n            LEFT JOIN {$wpdb->posts} ps\n              ON ( ps.ID = pmc.post_id) \n\n            WHERE pmc.meta_key = '_customer_user'\n            AND IF(pmc.meta_value = 0, pmc_email.meta_value, pmc.meta_value) != ''\n            AND ps.post_status IN({$orders_statuses})\n            AND ps.post_type   IN ({$order_types})\n\n            GROUP BY userUniqueID\n          ";
         $join .= "LEFT JOIN ({$new_sql}) total_value ON ( ( total_value.user_id != 0 AND total_value.user_id = customer.user_id) OR (total_value.user_email = customer.email AND (total_value.user_id = 0 OR total_value.user_id = '' ) ) )";
     } else {
         $new_sql = "SELECT pmc.meta_value as user_id, pmc_email.meta_value as user_email, SUM(pmc_total.meta_value) as o_total\n            FROM {$wpdb->postmeta} as pmc_email\n            LEFT JOIN {$wpdb->postmeta} pmc\n              ON ( pmc.meta_key = '_customer_user' AND pmc_email.meta_key = '_billing_email' AND pmc.post_id = pmc_email.post_id)\n\n            LEFT JOIN {$wpdb->postmeta} pmc_total\n              ON ( pmc_total.meta_key = '_order_total' AND pmc.post_id = pmc_total.post_id) \n\n            LEFT JOIN {$wpdb->posts} ps\n              ON ( ps.ID = pmc.post_id) \n\n            WHERE pmc_email.meta_key = '_billing_email'\n            AND pmc_email.meta_value != ''\n            AND pmc_email.meta_value IS NOT NULL\n            AND ps.post_status IN({$orders_statuses})\n            AND ps.post_type   IN ({$order_types})\n\n            GROUP BY user_email\n          ";
         $join .= "LEFT JOIN {$wpdb->usermeta} wp_users ON ( wp_users.user_id = customer.user_id AND wp_users.meta_key = 'billing_email')";
         $join .= "LEFT JOIN ({$new_sql}) total_value ON ( (total_value.user_email = wp_users.meta_value AND wp_users.user_id = customer.user_id ) OR (total_value.user_email = customer.email AND (total_value.user_id = 0 OR total_value.user_id = '' ) ) )";
     }
     #echo '<textarea>'.$new_sql.'</textarea>'; die;
     /******************/
     if (!empty($account_customer_emails)) {
         $emails = implode("','", $account_customer_emails);
         $filter .= " AND customer.email IN ('{$emails}')";
     }
     /*****************/
     if (isset($_REQUEST['group']) && !empty($_REQUEST['group'])) {
         $group_id = $_REQUEST['group'];
         $group_data = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wc_crm_groups WHERE ID = {$group_id}");
         if ($group_data[0]->group_type == 'static') {
             $inner .= "\n        inner join {$wpdb->prefix}wc_crm_groups_relationships groups_rel on (groups_rel.customer_email = customer.email AND groups_rel.group_id = {$group_id} )\n        ";
         } else {
             if (isset($_REQUEST['group']) && !empty($_REQUEST['group'])) {
                 $group_id = $_REQUEST['group'];
                 $group_data = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wc_crm_groups WHERE ID = {$group_id}");
                 if ($group_data[0]->group_type == 'dynamic') {
                     if (!empty($group_data[0]->group_total_spent)) {
                         $spent = $group_data[0]->group_total_spent;
                         $mark = $group_data[0]->group_total_spent_mark;
                         switch ($mark) {
                             case 'greater':
                                 $mark = '>';
                                 break;
                             case 'less':
                                 $mark = '<';
                                 break;
                             case 'greater_or_equal':
                                 $mark = '>=';
                                 break;
                             case 'less_or_equal':
                                 $mark = '<=';
                                 break;
                             default:
                                 $mark = '=';
                                 break;
                         }
                         #$filter .= " AND {$wpdb->prefix}wc_crm_customers.total_spent $mark $spent
                         #";
                     }
                     if (!empty($group_data[0]->group_user_role)) {
                         $group_user_role = $group_data[0]->group_user_role;
                         if ($group_user_role != 'any') {
                             if ($group_user_role == 'guest') {
                                 $filter .= "AND user_id = 0\n                    ";
                             } else {
                                 $filter .= "AND capabilities LIKE '%" . $group_user_role . "%'\n                    ";
                             }
                         }
                     }
                     if (!empty($group_data[0]->group_customer_status)) {
                         $group_customer_status = unserialize($group_data[0]->group_customer_status);
                         if (!empty($group_customer_status)) {
                             if (count($group_customer_status) > 1 || !empty($group_customer_status[0])) {
                                 $filter .= "AND  status IN( '" . implode("', '", $group_customer_status) . "' )\n                ";
                             }
                         }
                     }
                     if (!empty($group_data[0]->group_order_status)) {
                         $group_order_status = unserialize($group_data[0]->group_order_status);
                         if (!empty($group_order_status)) {
                             if (count($group_order_status) > 1 || !empty($group_order_status[0])) {
                                 $_REQUEST['_order_status'] = $group_order_status;
                             }
                         }
                     }
                     $d_from = false;
                     if (!empty($group_data[0]->group_last_order_from) && strtotime($group_data[0]->group_last_order_from) !== false) {
                         $d_from = strtotime($group_data[0]->group_last_order_from);
                     }
                     $d_to = false;
                     if (!empty($group_data[0]->group_last_order_to) && strtotime($group_data[0]->group_last_order_to) !== false) {
                         $d_to = strtotime($group_data[0]->group_last_order_to);
                     }
                     if ($d_to || $d_from) {
                         $mark = $group_data[0]->group_last_order;
                         switch ($mark) {
                             case 'before':
                                 $filter .= "AND  DATE(posts.post_date) <= '" . date('Y-m-d', $d_from) . "'\n                  ";
                                 break;
                             case 'after':
                                 $filter .= "AND  DATE(posts.post_date) >= '" . date('Y-m-d', $d_from) . "'\n                  ";
                                 break;
                             case 'between':
                                 $filter .= "AND  DATE(posts.post_date) >= '" . date('Y-m-d', $d_from) . "' AND  DATE(posts.post_date) <= '" . date('Y-m-d', $d_to) . "'\n                  ";
                                 break;
                         }
                     }
                     /****************/
                 }
             }
         }
     }
     /*****************/
     if (isset($_REQUEST['_customer_product']) && !empty($_REQUEST['_customer_product']) || isset($_REQUEST['_products_variations']) && !empty($_REQUEST['_products_variations']) || isset($_REQUEST['_order_status']) && !empty($_REQUEST['_order_status']) || isset($_REQUEST['_products_categories']) && !empty($_REQUEST['_products_categories']) || isset($_REQUEST['_products_brands']) && !empty($_REQUEST['_products_brands'])) {
         $inner .= "\n      inner join {$wpdb->postmeta} on ({$wpdb->postmeta}.meta_value = total_value.user_email AND {$wpdb->postmeta}.meta_key = '_billing_email' AND total_value.user_email != '' )\n      ";
     }
     if (isset($_REQUEST['_customer_product']) && !empty($_REQUEST['_customer_product']) || isset($_REQUEST['_products_variations']) && !empty($_REQUEST['_products_variations']) || isset($_REQUEST['_products_categories']) && !empty($_REQUEST['_products_categories']) || isset($_REQUEST['_products_brands']) && !empty($_REQUEST['_products_brands'])) {
         $inner .= "\n      inner join {$wpdb->prefix}woocommerce_order_items on {$wpdb->prefix}woocommerce_order_items.order_id = {$wpdb->postmeta}.post_id\n      ";
     }
     if (isset($_REQUEST['_customer_product']) && !empty($_REQUEST['_customer_product']) || isset($_REQUEST['_products_categories']) && !empty($_REQUEST['_products_categories']) || isset($_REQUEST['_products_brands']) && !empty($_REQUEST['_products_brands'])) {
         $inner .= "     \n      inner join  {$wpdb->prefix}woocommerce_order_itemmeta as product on ( product.order_item_id = {$wpdb->prefix}woocommerce_order_items.order_item_id and product.meta_key = '_product_id' ) ";
     }
     if (isset($_REQUEST['_products_categories']) && !empty($_REQUEST['_products_categories']) || isset($_REQUEST['_products_brands']) && !empty($_REQUEST['_products_brands'])) {
         $tax = '';
         if (isset($_REQUEST['_products_categories'])) {
             $tax .= "taxonomy.taxonomy = 'product_cat'";
         }
         if (isset($_REQUEST['_products_brands'])) {
             if (!empty($tax)) {
                 $tax .= ' OR ';
             }
             $tax .= "taxonomy.taxonomy = 'product_brand'";
         }
         $inner .= "\n          inner join  {$wpdb->prefix}term_relationships as relationships on (relationships.object_id =  product.meta_value ) \n          inner join  {$wpdb->prefix}term_taxonomy as taxonomy on (relationships.term_taxonomy_id = taxonomy.term_taxonomy_id AND ({$tax}) ) \n          ";
     }
     if (isset($_REQUEST['_order_status']) && !empty($_REQUEST['_order_status'])) {
         $request = $_REQUEST['_order_status'];
         if (is_array($request)) {
             $inner .= "\n              inner JOIN {$wpdb->posts} posts_status\n              ON ({$wpdb->postmeta}.post_id= posts_status.ID AND posts_status.post_status IN( '" . implode("', '", $request) . "') AND posts_status.post_type =  'shop_order' )\n        ";
         } else {
             if (is_string($request)) {
                 $inner .= "\n              inner JOIN {$wpdb->posts} posts_status\n              ON ({$wpdb->postmeta}.post_id= posts_status.ID AND posts_status.post_status = '{$request}'  AND posts_status.post_type =  'shop_order' )\n          ";
             }
         }
     }
     if (isset($_REQUEST['_products_categories']) && !empty($_REQUEST['_products_categories'])) {
         $y = '';
         foreach ($_REQUEST['_products_categories'] as $v) {
             if ($y) {
                 $ff .= ' OR ';
             } else {
                 $y = 'OR';
                 $ff = '
         AND (';
             }
             $ff .= " (taxonomy.term_id = " . $v . " AND taxonomy.taxonomy = 'product_cat' )";
         }
         $filter .= $ff . ')';
     }
     if (isset($_REQUEST['_products_brands']) && !empty($_REQUEST['_products_brands'])) {
         $y = '';
         foreach ($_REQUEST['_products_brands'] as $v) {
             if ($y) {
                 $ff .= ' OR ';
             } else {
                 $y = 'OR';
                 $ff = '
         AND (';
             }
             $ff .= " (taxonomy.term_id = " . $v . " AND taxonomy.taxonomy = 'product_brand' )";
         }
         $filter .= $ff . ')';
     }
     if (isset($_REQUEST['_customer_product']) && !empty($_REQUEST['_customer_product'])) {
         $filter .= " AND product.meta_value = " . $_REQUEST['_customer_product'];
     }
     if (isset($_REQUEST['_products_variations']) && !empty($_REQUEST['_products_variations'])) {
         $y = '';
         $products_variations = $_REQUEST['_products_variations'];
         if (!is_array($products_variations)) {
             $products_variations = explode(',', $products_variations);
         }
         foreach ($products_variations as $v) {
             if ($y) {
                 $ff .= ' OR ';
             } else {
                 $y = ' OR ';
                 $ff = ' AND (';
             }
             $ff .= 'variation.meta_value = ' . $v;
         }
         $filter .= $ff . ')';
         $inner .= "\n        inner join  {$wpdb->prefix}woocommerce_order_itemmeta as variation on (variation.order_item_id =  {$wpdb->prefix}woocommerce_order_items.order_item_id and variation.meta_key = '_variation_id' ) \n        ";
     }
     /*****************/
     if (isset($_REQUEST['_customer_date_from']) && !empty($_REQUEST['_customer_date_from'])) {
         $filter .= " AND  DATE(posts.post_date) >= '" . date('Y-m-d', strtotime($_REQUEST['_customer_date_from'])) . "'\n            ";
     }
     if (isset($_REQUEST['_customer_state']) && !empty($_REQUEST['_customer_state'])) {
         $filter .= " AND customer.state = '" . $_REQUEST['_customer_state'] . "'\n      ";
     }
     if (isset($_REQUEST['_customer_city']) && !empty($_REQUEST['_customer_city'])) {
         $filter .= " AND customer.city = '" . $_REQUEST['_customer_city'] . "'\n        ";
     }
     if (isset($_REQUEST['_customer_country']) && !empty($_REQUEST['_customer_country'])) {
         $filter .= " AND customer.country = '" . $_REQUEST['_customer_country'] . "'\n        ";
     }
     if (isset($_REQUEST['_customer_status']) && !empty($_REQUEST['_customer_status'])) {
         $filter .= " AND  customer.status LIKE '" . $_REQUEST['_customer_status'] . "'\n          ";
     }
     if (isset($_REQUEST['_customer_user']) && !empty($_REQUEST['_customer_user'])) {
         $term = $_REQUEST['_customer_user'];
         $filter .= " AND (customer.email = '{$term}' OR customer.user_id = {$term})\n        ";
     }
     $join .= " LEFT JOIN {$wpdb->usermeta} fname  ON (customer.user_id = fname.user_id AND fname.meta_key = 'first_name')";
     $join .= " LEFT JOIN {$wpdb->usermeta} lname  ON (customer.user_id = lname.user_id AND lname.meta_key = 'last_name')";
     $join .= " LEFT JOIN {$wpdb->usermeta} bemail ON (customer.user_id = bemail.user_id AND bemail.meta_key = 'billing_email')";
     $join .= " LEFT JOIN {$wpdb->postmeta} pfname ON (customer.order_id = pfname.post_id AND pfname.meta_key = '_billing_first_name')";
     $join .= " LEFT JOIN {$wpdb->postmeta} plname ON (customer.order_id = plname.post_id AND plname.meta_key = '_billing_last_name')";
     if ($display_name == 'fl') {
         $select .= ', IF(customer.user_id > 0 AND customer.user_id IS NOT NULL, CONCAT(fname.meta_value, " ", lname.meta_value), CONCAT(pfname.meta_value, " ", plname.meta_value) )  as customer_name';
     } else {
         $select .= ', IF(customer.user_id > 0 AND customer.user_id IS NOT NULL, CONCAT(lname.meta_value, ", ", fname.meta_value), CONCAT(plname.meta_value, ", ", pfname.meta_value) ) as customer_name';
     }
     if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {
         $term = $_REQUEST['s'];
         $filter .= " AND (\n        (\n          LOWER(fname.meta_value) LIKE LOWER('%{$term}%') \n          OR LOWER(lname.meta_value) LIKE LOWER('%{$term}%') \n          OR LOWER(bemail.meta_value) LIKE LOWER('%{$term}%') \n          OR LOWER(customer.email) LIKE LOWER('%{$term}%') \n          OR concat_ws(' ',fname.meta_value,lname.meta_value) LIKE '%{$term}%'\n        )\n        OR\n        (\n          LOWER(pfname.meta_value) LIKE LOWER('%{$term}%') \n          OR LOWER(plname.meta_value) LIKE LOWER('%{$term}%') \n          OR concat_ws(' ',pfname.meta_value,plname.meta_value) LIKE '%{$term}%' \n        )\n      )";
     }
     /******************/
     if (!empty($user_role_filter)) {
         if ($add_guest_customers == 'yes') {
             $user_role_filter = ' AND (' . $user_role_filter . ' OR customer.user_id IS NULL OR customer.user_id = 0 ) ';
         } else {
             $user_role_filter = ' AND (' . $user_role_filter . ') ';
         }
     }
     if (isset($_REQUEST['_user_type']) && !empty($_REQUEST['_user_type'])) {
         if ($_REQUEST['_user_type'] == 'guest_user') {
             $user_role_filter = " AND ( customer.user_id IS NULL  OR customer.user_id = 0 )\n        ";
         } else {
             $user_role_filter = " AND (customer.capabilities LIKE '%" . $_REQUEST['_user_type'] . "%') ";
         }
     }
     $filter .= $user_role_filter;
     $sql = "SELECT customer.*, posts.post_date as last_purchase {$select} FROM {$wpdb->prefix}wc_crm_customer_list as customer\n      LEFT JOIN {$wpdb->posts} posts ON (customer.order_id = posts.ID)\n\t\t\t{$join}\n      {$inner}\n\n\t\t\tWHERE 1=1\n\t\t\t{$filter}\n\n      GROUP BY customer.email\n\n\t\t ";
     #echo '<textarea name="" id="" style="width: 100%; height: 200px; ">'.$sql.'</textarea>';die;
     return $sql;
 }
        public static function user_roles_filter()
        {
            global $wp_roles;
            ?>
      <select name='_user_type' id='dropdown_user_type'>
        <option value=""><?php 
            _e('Show all user roles', 'wc_crm');
            ?>
</option>
          <?php 
            $woocommerce_crm_user_roles = get_option('wc_crm_user_roles');
            if (!$woocommerce_crm_user_roles || empty($woocommerce_crm_user_roles)) {
                $woocommerce_crm_user_roles[] = 'customer';
            }
            $_user_type = isset($_REQUEST['_user_type']) ? $_REQUEST['_user_type'] : '';
            foreach ($wp_roles->role_names as $role => $name) {
                $slug_name = strtolower($name);
                if (!in_array($slug_name, $woocommerce_crm_user_roles)) {
                    continue;
                }
                ?>
            <option value="<?php 
                echo $slug_name;
                ?>
" <?php 
                selected($slug_name, $_user_type, true);
                ?>
 ><?php 
                echo $name;
                ?>
</option>
            <?php 
            }
            $add_guest_customers = WC_Admin_Settings::get_option('wc_crm_guest_customers', 'no');
            if ($add_guest_customers == 'yes') {
                ?>
            <option value="guest_user" <?php 
                selected('guest_user', $_user_type, true);
                ?>
 >
              <?php 
                _e('Guest', 'wc_crm');
                ?>
            </option>
          <?php 
            }
            ?>
        </select>
      <?php 
        }
 /**
  * Get all settings in a group.
  *
  * @since  2.7.0
  * @param string $group_id Group ID.
  * @return array|WP_Error
  */
 public function get_group_settings($group_id)
 {
     if (empty($group_id)) {
         return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404));
     }
     $settings = apply_filters('woocommerce_settings-' . $group_id, array());
     if (empty($settings)) {
         return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404));
     }
     $filtered_settings = array();
     foreach ($settings as $setting) {
         $option_key = $setting['option_key'];
         $setting = $this->filter_setting($setting);
         $default = isset($setting['default']) ? $setting['default'] : '';
         // Get the option value
         if (is_array($option_key)) {
             $option = get_option($option_key[0]);
             $setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default;
         } else {
             $admin_setting_value = WC_Admin_Settings::get_option($option_key);
             $setting['value'] = empty($admin_setting_value) ? $default : $admin_setting_value;
         }
         if ('multi_select_countries' === $setting['type']) {
             $setting['options'] = WC()->countries->get_countries();
             $setting['type'] = 'multiselect';
         }
         $filtered_settings[] = $setting;
     }
     return $filtered_settings;
 }
Пример #12
0
    public function select_page_field($value)
    {
        $args = array('name' => $value['id'], 'id' => $value['id'], 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => $value['class'], 'echo' => false, 'selected' => absint(WC_Admin_Settings::get_option($value['id'])));
        if (isset($value['args'])) {
            $args = wp_parse_args($value['args'], $args);
        }
        if ($value['desc_tip']) {
            $value['desc_tip'] = $value['desc'];
        }
        // Custom attribute handling
        $custom_attributes = array();
        if (!empty($value['custom_attributes']) && is_array($value['custom_attributes'])) {
            foreach ($value['custom_attributes'] as $attribute => $attribute_value) {
                $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"';
            }
        }
        ?>
<tr valign="top" class="single_select_page">
			<th scope="row" class="titledesc"><?php 
        echo esc_html($value['title']);
        ?>
			<?php 
        if (!empty($value['desc_tip'])) {
            ?>
				<img class="help_tip" data-tip="<?php 
            echo esc_attr(wp_kses_post($value['desc_tip']));
            ?>
" src="<?php 
            echo WC()->plugin_url();
            ?>
/assets/images/help.png" height="16" width="16" />
			<?php 
        }
        ?>
			</th>
			<td class="forminp">
				<?php 
        echo str_replace(' id=', " data-placeholder='" . __('Select a page&hellip;', 'woocommerce') . "' " . implode(" ", $custom_attributes) . " style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages($args));
        ?>
			</td>
		</tr>
		<?php 
    }
 /**
  * Prepare a single setting object for response.
  *
  * @since  2.7.0
  * @param object $item Setting object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response $response Response data.
  */
 public function prepare_item_for_response($item, $request)
 {
     $data = $this->filter_setting($item);
     $data['value'] = WC_Admin_Settings::get_option($data['id']);
     $context = empty($request['context']) ? 'view' : $request['context'];
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($data['id'], $request['group']));
     return $response;
 }
Пример #14
0
?>
	</a>
</h3>

<table class="wp-list widefat fixed striped">
	<thead>
		<tr>
			<th><?php 
_e('Name', 'woorule');
?>
</th>
			<th colspan="2"><?php 
_e('Enabled', 'woorule');
?>
</th>
		</tr>
	</thead>
	<tbody>
		<?php 
foreach ($rules as $id => $value) {
    echo '<tr>';
    echo '<td>' . WC_Admin_Settings::get_option($value['name']['id'], 'Unnamed') . '</td>';
    echo '<td>' . WC_Admin_Settings::get_option($value['enabled']['id'], 'no') . '</td>';
    echo '<td><a href="' . $edit_url . $id . '">' . __('Edit', 'woorule') . '</a></td>';
    echo '</tr>';
}
?>
	</tbody>
</table>