本文整理汇总了PHP中wc_clean函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_clean函数的具体用法?PHP wc_clean怎么用?PHP wc_clean使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_clean函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle_api_requests
/**
* API request - Trigger any API requests.
*
* @since 2.0
* @version 2.4
*/
public function handle_api_requests()
{
global $wp;
if (!empty($_GET['wc-api'])) {
$wp->query_vars['wc-api'] = $_GET['wc-api'];
}
// wc-api endpoint requests.
if (!empty($wp->query_vars['wc-api'])) {
// Buffer, we won't want any output here.
ob_start();
// No cache headers.
nocache_headers();
// Clean the API request.
$api_request = strtolower(wc_clean($wp->query_vars['wc-api']));
// Trigger generic action before request hook.
do_action('woocommerce_api_request', $api_request);
// Is there actually something hooked into this API request? If not trigger 400 - Bad request.
status_header(has_action('woocommerce_api_' . $api_request) ? 200 : 400);
// Trigger an action which plugins can hook into to fulfill the request.
do_action('woocommerce_api_' . $api_request);
// Done, clear buffer and exit.
ob_end_clean();
die('-1');
}
}
示例2: output
/**
* Output the calendar view
*/
public function output()
{
wp_enqueue_script('chosen');
$product_filter = isset($_REQUEST['filter_bookings']) ? absint($_REQUEST['filter_bookings']) : '';
$view = isset($_REQUEST['view']) && $_REQUEST['view'] == 'day' ? 'day' : 'month';
if ($view == 'day') {
$day = isset($_REQUEST['calendar_day']) ? wc_clean($_REQUEST['calendar_day']) : date('Y-m-d');
$this->bookings = WC_Bookings_Controller::get_bookings_in_date_range(strtotime('midnight', strtotime($day)), strtotime('midnight +1 day', strtotime($day)), $product_filter);
} else {
$month = isset($_REQUEST['calendar_month']) ? absint($_REQUEST['calendar_month']) : date('n');
$year = isset($_REQUEST['calendar_year']) ? absint($_REQUEST['calendar_year']) : date('Y');
if ($year < date('Y') - 10 || $year > 2100) {
$year = date('Y');
}
if ($month > 12) {
$month = 1;
$year++;
}
if ($month < 1) {
$month = 1;
$year--;
}
$start_week = (int) date('W', strtotime("first day of {$year}-{$month}"));
$end_week = (int) date('W', strtotime("last day of {$year}-{$month}"));
if ($end_week == 1) {
$end_week = 53;
}
$this->bookings = WC_Bookings_Controller::get_bookings_in_date_range(strtotime($year . 'W' . str_pad($start_week, 2, '0', STR_PAD_LEFT)), strtotime($year . 'W' . str_pad($end_week + 1, 2, '0', STR_PAD_LEFT)), $product_filter);
}
include 'views/html-calendar-' . $view . '.php';
wc_enqueue_js('$( "select#calendar-bookings-filter" ).chosen();');
}
示例3: save_meta
/**
* Get the new payment data from POST and check the new payment method supports
* the new admin change hook.
*
* @since 2.0
* @param $subscription WC_Subscription
*/
public static function save_meta($subscription)
{
if (empty($_POST['_wcsnonce']) || !wp_verify_nonce($_POST['_wcsnonce'], 'wcs_change_payment_method_admin')) {
return;
}
$payment_gateways = WC()->payment_gateways->payment_gateways();
$payment_method = isset($_POST['_payment_method']) ? wc_clean($_POST['_payment_method']) : '';
$payment_method_meta = apply_filters('woocommerce_subscription_payment_meta', array(), $subscription);
$payment_method_meta = !empty($payment_method_meta[$payment_method]) ? $payment_method_meta[$payment_method] : array();
$valid_payment_methods = self::get_valid_payment_methods($subscription);
if (!isset($valid_payment_methods[$payment_method])) {
throw new Exception(__('Please choose a valid payment gateway to change to.', 'woocommerce-subscriptions'));
}
if (!empty($payment_method_meta)) {
foreach ($payment_method_meta as $meta_table => &$meta) {
if (!is_array($meta)) {
continue;
}
foreach ($meta as $meta_key => &$meta_data) {
$meta_data['value'] = isset($_POST['_payment_method_meta'][$meta_table][$meta_key]) ? $_POST['_payment_method_meta'][$meta_table][$meta_key] : '';
}
}
}
$payment_gateway = 'manual' != $payment_method ? $payment_gateways[$payment_method] : '';
if (!$subscription->is_manual() && property_exists($subscription->payment_gateway, 'id') && ('' == $payment_gateway || $subscription->payment_gateway->id != $payment_gateway->id)) {
// Before updating to a new payment gateway make sure the subscription status is updated with the current gateway
$gateway_status = apply_filters('wcs_gateway_status_payment_changed', 'cancelled', $subscription, $payment_gateway);
WC_Subscriptions_Payment_Gateways::trigger_gateway_status_updated_hook($subscription, $gateway_status);
}
$subscription->set_payment_method($payment_gateway, $payment_method_meta);
}
示例4: check_response
/**
* Check Response for PDT
*/
public function check_response()
{
if (empty($_REQUEST['cm']) || empty($_REQUEST['tx']) || empty($_REQUEST['st'])) {
return;
}
$order_id = wc_clean(stripslashes($_REQUEST['cm']));
$status = wc_clean(strtolower(stripslashes($_REQUEST['st'])));
$amount = wc_clean(stripslashes($_REQUEST['amt']));
$transaction = wc_clean(stripslashes($_REQUEST['tx']));
if (!($order = $this->get_paypal_order($order_id)) || !$order->has_status('pending')) {
return false;
}
if ($this->validate_transaction($transaction) && 'completed' === $status) {
if ($order->get_total() != $amount) {
WC_Gateway_Paypal::log('Payment error: Amounts do not match (amt ' . $amount . ')');
$this->payment_on_hold($order, sprintf(__('Validation error: PayPal amounts do not match (amt %s).', 'woocommerce'), $amount));
} else {
$this->payment_complete($order, $transaction, __('PDT payment completed', 'woocommerce'));
if (!empty($_REQUEST['mc_fee'])) {
// log paypal transaction fee
update_post_meta($order->id, 'PayPal Transaction Fee', wc_clean($_REQUEST['mc_fee']));
}
}
}
}
示例5: calculate_shipping
/**
* Calculate shipping for the cart
*/
public static function calculate_shipping()
{
try {
WC()->shipping->reset_shipping();
$country = wc_clean($_POST['calc_shipping_country']);
$state = wc_clean(isset($_POST['calc_shipping_state']) ? $_POST['calc_shipping_state'] : '');
$postcode = apply_filters('woocommerce_shipping_calculator_enable_postcode', true) ? wc_clean($_POST['calc_shipping_postcode']) : '';
$city = apply_filters('woocommerce_shipping_calculator_enable_city', false) ? wc_clean($_POST['calc_shipping_city']) : '';
if ($postcode && !WC_Validation::is_postcode($postcode, $country)) {
throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce'));
} elseif ($postcode) {
$postcode = wc_format_postcode($postcode, $country);
}
if ($country) {
WC()->customer->set_location($country, $state, $postcode, $city);
WC()->customer->set_shipping_location($country, $state, $postcode, $city);
} else {
WC()->customer->set_to_base();
WC()->customer->set_shipping_to_base();
}
WC()->customer->calculated_shipping(true);
wc_add_notice(__('Shipping costs updated.', 'woocommerce'), 'notice');
do_action('woocommerce_calculated_shipping');
} catch (Exception $e) {
if (!empty($e)) {
wc_add_notice($e->getMessage(), 'error');
}
}
}
示例6: __construct
/**
* Constructor.
*
* @return \YITH_WCStripe_Gateway
* @since 1.0.0
*/
public function __construct()
{
$this->id = YITH_WCStripe::$gateway_id;
$this->has_fields = true;
$this->method_title = apply_filters('yith_stripe_method_title', __('Stripe', 'yith-stripe'));
$this->method_description = apply_filters('yith_stripe_method_description', __('Take payments via Stripe - uses stripe.js to create card tokens and the Stripe SDK. Requires SSL when sandbox is disabled.', 'yith-stripe'));
$this->supports = array('products');
$this->instance = preg_replace('/http(s)?:\\/\\//', '', site_url());
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
$this->env = $this->get_option('enabled_test_mode') == 'yes' ? 'test' : 'live';
$this->private_key = $this->get_option($this->env . '_secrect_key');
$this->public_key = $this->get_option($this->env . '_publishable_key');
$this->modal_image = $this->get_option('modal_image');
$this->mode = 'hosted';
// post data
$this->token = isset($_POST['stripe_token']) ? wc_clean($_POST['stripe_token']) : '';
// save
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
// others
add_action('admin_notices', array($this, 'admin_notices'));
add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'return_handler'));
}
示例7: save_meta
/**
* Get the new payment data from POST and check the new payment method supports
* the new admin change hook.
*
* @since 2.0
* @param $subscription WC_Subscription
*/
public static function save_meta($subscription)
{
if (empty($_POST['_wcsnonce']) || !wp_verify_nonce($_POST['_wcsnonce'], 'wcs_change_payment_method_admin')) {
return;
}
$payment_gateways = WC()->payment_gateways->payment_gateways();
$payment_method = isset($_POST['_payment_method']) ? wc_clean($_POST['_payment_method']) : '';
$payment_method_meta = apply_filters('woocommerce_subscription_payment_meta', array(), $subscription);
$payment_method_meta = !empty($payment_method_meta[$payment_method]) ? $payment_method_meta[$payment_method] : array();
$valid_payment_methods = self::get_valid_payment_methods($subscription);
if (!isset($valid_payment_methods[$payment_method])) {
throw new Exception(__('Please choose a valid payment gateway to change to.', 'woocommerce-subscriptions'));
}
if (!empty($payment_method_meta)) {
foreach ($payment_method_meta as $meta_table => &$meta) {
if (!is_array($meta)) {
continue;
}
foreach ($meta as $meta_key => &$meta_data) {
$meta_data['value'] = isset($_POST['_payment_method_meta'][$meta_table][$meta_key]) ? $_POST['_payment_method_meta'][$meta_table][$meta_key] : '';
}
}
}
$payment_gateway = 'manual' != $payment_method ? $payment_gateways[$payment_method] : '';
$subscription->set_payment_method($payment_gateway, $payment_method_meta);
}
示例8: gzd_json_search_delivery_time
public static function gzd_json_search_delivery_time()
{
ob_start();
check_ajax_referer('search-products', 'security');
$term = (string) wc_clean(stripslashes($_GET['term']));
$terms = array();
if (empty($term)) {
die;
}
$args = array('hide_empty' => false);
if (is_numeric($term)) {
$args['include'] = array(absint($term));
} else {
$args['name__like'] = (string) $term;
}
$query = get_terms('product_delivery_time', $args);
if (!empty($query)) {
foreach ($query as $term) {
$terms[$term->term_id] = rawurldecode($term->name);
}
} else {
$terms[rawurldecode($term)] = rawurldecode(sprintf(__("%s [new]", "woocommerce-germanized"), $term));
}
wp_send_json($terms);
}
示例9: sundaysea_update_cart2
function sundaysea_update_cart2($cart_totals)
{
// Add Discount
if (!empty($_POST['coupon_code'])) {
WC()->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
} elseif (isset($_GET['remove_coupon'])) {
WC()->cart->remove_coupon(wc_clean($_GET['remove_coupon']));
}
global $woocommerce;
if (sizeof($woocommerce->cart->get_cart()) > 0) {
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
// Skip product if no updated quantity was posted
if (!isset($cart_totals[$cart_item_key]['qty'])) {
continue;
}
// Sanitize
$quantity = apply_filters('woocommerce_stock_amount_cart_item', apply_filters('woocommerce_stock_amount', preg_replace("/[^0-9\\.]/", "", $cart_totals[$cart_item_key]['qty'])), $cart_item_key);
if ("" === $quantity || $quantity == $values['quantity']) {
continue;
}
// Update cart validation
$passed_validation = apply_filters('woocommerce_update_cart_validation', true, $cart_item_key, $values, $quantity);
$_product = $values['data'];
// is_sold_individually
if ($_product->is_sold_individually() && $quantity > 1) {
$woocommerce->add_error(sprintf(__('You can only have 1 %s in your cart.', 'woocommerce'), $_product->get_title()));
$passed_validation = false;
}
if ($passed_validation) {
$woocommerce->cart->set_quantity($cart_item_key, $quantity, false);
}
}
$woocommerce->cart->calculate_totals();
}
}
开发者ID:vphat28,项目名称:horizontal-slide-out-cart-for-woocommerce,代码行数:35,代码来源:woocommerce-slide-out-cart.php
示例10: download_product
/**
* Check if we need to download a file and check validity.
*/
public static function download_product()
{
$product_id = absint($_GET['download_file']);
$product = wc_get_product($product_id);
$data_store = WC_Data_Store::load('customer-download');
if (!$product || !isset($_GET['key'], $_GET['order'])) {
self::download_error(__('Invalid download link.', 'woocommerce'));
}
$download_ids = $data_store->get_downloads(array('user_email' => sanitize_email(str_replace(' ', '+', $_GET['email'])), 'order_key' => wc_clean($_GET['order']), 'product_id' => $product_id, 'download_id' => wc_clean(preg_replace('/\\s+/', ' ', $_GET['key'])), 'orderby' => 'downloads_remaining', 'order' => 'DESC', 'limit' => 1, 'return' => 'ids'));
if (empty($download_ids)) {
self::download_error(__('Invalid download link.', 'woocommerce'));
}
$download = new WC_Customer_Download(current($download_ids));
self::check_order_is_valid($download);
self::check_downloads_remaining($download);
self::check_download_expiry($download);
self::check_download_login_required($download);
do_action('woocommerce_download_product', $download->get_user_email(), $download->get_order_key(), $download->get_product_id(), $download->get_user_id(), $download->get_download_id(), $download->get_order_id());
$count = $download->get_download_count();
$remaining = $download->get_downloads_remaining();
$download->set_download_count($count++);
$download->set_downloads_remaining($remaining--);
$download->save();
self::download($product->get_file_download_path($download->get_download_id()), $download->get_product_id());
}
示例11: product_search_sku
function product_search_sku($where)
{
global $pagenow, $wpdb, $wp;
//VAR_DUMP(http_build_query(array('post_type' => array('product','boobs'))));die();
$type = array('product', 'jam');
//var_dump(in_array('product', $wp->query_vars['post_type']));
if (is_admin() && 'edit.php' != $pagenow || !is_search() || !isset($wp->query_vars['s']) || isset($wp->query_vars['post_type']) && 'product' != $wp->query_vars['post_type'] || isset($wp->query_vars['post_type']) && is_array($wp->query_vars['post_type']) && !in_array('product', $wp->query_vars['post_type'])) {
return $where;
}
$search_ids = array();
$terms = explode(',', $wp->query_vars['s']);
foreach ($terms as $term) {
//Include the search by id if admin area.
if (is_admin() && is_numeric($term)) {
$search_ids[] = $term;
}
// search for variations with a matching sku and return the parent.
$sku_to_parent_id = $wpdb->get_col($wpdb->prepare("SELECT p.post_parent as post_id FROM {$wpdb->posts} as p join {$wpdb->postmeta} pm on p.ID = pm.post_id and pm.meta_key='_sku' and pm.meta_value LIKE '%%%s%%' where p.post_parent <> 0 group by p.post_parent", wc_clean($term)));
//Search for a regular product that matches the sku.
$sku_to_id = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_sku' AND meta_value LIKE '%%%s%%';", wc_clean($term)));
$search_ids = array_merge($search_ids, $sku_to_id, $sku_to_parent_id);
}
$search_ids = array_filter(array_map('absint', $search_ids));
if (sizeof($search_ids) > 0) {
$where = str_replace(')))', ") OR ({$wpdb->posts}.ID IN (" . implode(',', $search_ids) . "))))", $where);
}
remove_filters_for_anonymous_class('posts_search', 'WC_Admin_Post_Types', 'product_search', 10);
return $where;
}
示例12: gzd_revocation
/**
* Checks revocation form and sends Email to customer and Admin
*/
public static function gzd_revocation()
{
check_ajax_referer('woocommerce-revocation', 'security');
wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-revocation');
$data = array();
$fields = WC_GZD_Revocation::get_fields();
if (!empty($fields)) {
foreach ($fields as $key => $field) {
if ('sep' !== $key) {
if ($key == 'address_mail') {
if (!is_email($_POST[$key])) {
wc_add_notice('<strong>' . $field['label'] . '</strong> ' . _x('is not a valid email address.', 'revocation-form', 'woocommerce-germanized'), 'error');
}
} elseif ($key == 'address_postal') {
if (!WC_Validation::is_postcode($_POST[$key], $_POST['address_country']) || empty($_POST[$key])) {
wc_add_notice(_x('Please enter a valid postcode/ZIP', 'revocation-form', 'woocommerce-germanized'), 'error');
}
} else {
if (isset($field['required']) && empty($_POST[$key])) {
wc_add_notice('<strong>' . $field['label'] . '</strong> ' . _x('is not valid.', 'revocation-form', 'woocommerce-germanized'), 'error');
}
}
if (!empty($_POST[$key])) {
if ($field['type'] == 'country') {
$countries = WC()->countries->get_countries();
$country = wc_clean($_POST[$key]);
$data[$key] = isset($countries[$country]) ? $countries[$country] : '';
} else {
$data[$key] = wc_clean($_POST[$key]);
}
}
}
}
}
$error = false;
if (wc_notice_count('error') == 0) {
wc_add_notice(_x('Thank you. We have received your Revocation Request. You will receive a conformation email within a few minutes.', 'revocation-form', 'woocommerce-germanized'), 'success');
// Send Mail
if ($mail = WC_germanized()->emails->get_email_instance_by_id('customer_revocation')) {
$mail->trigger($data);
// Send to Admin
$data['mail'] = get_bloginfo('admin_email');
$mail->trigger($data);
}
} else {
$error = true;
}
ob_start();
wc_print_notices();
$messages = ob_get_clean();
if ($error) {
echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => isset($messages) ? $messages : '')) . '<!--WC_END-->';
} else {
if (is_ajax()) {
echo '<!--WC_START-->' . json_encode(array('result' => 'success', 'messages' => isset($messages) ? $messages : '')) . '<!--WC_END-->';
}
}
exit;
}
示例13: edit_coupon
/**
* Edit a coupon.
* @param int $id
* @param array $data
*/
public static function edit_coupon($id, $data)
{
if (isset($data['billing_countries'])) {
update_post_meta($id, 'billing_countries', wc_clean($data['billing_countries']));
}
if (isset($data['shipping_countries'])) {
update_post_meta($id, 'shipping_countries', wc_clean($data['shipping_countries']));
}
}
示例14: add_method
/**
* Add shipping method to zone
*/
public static function add_method($zone)
{
if (!empty($_GET['add_method']) && !empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce_add_method')) {
$type = wc_clean($_GET['method_type']);
if ($type && ($method_id = $zone->add_shipping_method($type))) {
echo '<div class="updated fade"><p>' . sprintf(__('Shipping method successfully created. <a href="%s">View method.</a>', SHIPPING_ZONES_TEXTDOMAIN), esc_url(add_query_arg('method', $method_id, add_query_arg('zone', $zone->zone_id, admin_url('admin.php?page=shipping_zones'))))) . '</p></div>';
} else {
echo '<div class="error"><p>' . __('Invalid shipping method', SHIPPING_ZONES_TEXTDOMAIN) . '</p></div>';
}
}
}
示例15: save_customer_meta_fields
/**
* Save Dolibarr ID field on edit user pages
*
* @param mixed $user_id User ID of the user being saved
*
* @return void
*/
public function save_customer_meta_fields($user_id)
{
$save_fields = $this->get_customer_meta_fields();
foreach ($save_fields as $fieldset) {
foreach ($fieldset['fields'] as $key => $field) {
if (isset($_POST[$key])) {
update_user_meta($user_id, $key, wc_clean($_POST[$key]));
}
}
}
}