本文整理汇总了PHP中WC_Payment_Gateways::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Payment_Gateways::instance方法的具体用法?PHP WC_Payment_Gateways::instance怎么用?PHP WC_Payment_Gateways::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Payment_Gateways
的用法示例。
在下文中一共展示了WC_Payment_Gateways::instance方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_gateways
public function load_gateways()
{
$gateways = WC_Payment_Gateways::instance()->payment_gateways;
$order = $this->get('gateway_order');
// some poorly written plugins will init WC_Payment_Gateways before WP init
// check to see if POS Cash Gateway is present, if not: re-init WC_Payment_Gateways
if (!in_array('WC_POS_Gateways_Cash', array_map('get_class', $gateways))) {
WC_Payment_Gateways::instance()->init();
$gateways = WC_Payment_Gateways::instance()->payment_gateways;
}
// reorder
$i = count($gateways);
foreach ($gateways as $gateway) {
if (isset($order[$gateway->id])) {
$ordered_gateways[$order[$gateway->id]] = $gateway;
} else {
$ordered_gateways[++$i] = $gateway;
}
$settings = new WC_POS_Admin_Settings_Gateways($gateway->id);
$settings->merge_settings($gateway);
apply_filters('woocommerce_pos_load_gateway', $gateway);
}
ksort($ordered_gateways, SORT_NUMERIC);
return $ordered_gateways;
}
示例2: getEnabledPaymentGateways
/**
* Get enabled payment gateways.
*
* @return array Array of enabled gateways
*/
public function getEnabledPaymentGateways()
{
$_enabledGateways = array();
$gateways = \WC_Payment_Gateways::instance();
if (sizeof($gateways->payment_gateways) > 0) {
foreach ($gateways->payment_gateways() as $gateway) {
if ($this->isEnabled($gateway)) {
$_enabledGateways[$gateway->id] = $gateway;
}
}
}
return $_enabledGateways;
}
示例3: load_gateways
public function load_gateways()
{
$gateways = WC_Payment_Gateways::instance()->payment_gateways;
$order = $this->get_data('gateway_order');
// reorder
$i = count($gateways);
foreach ($gateways as $gateway) {
if (isset($order[$gateway->id])) {
$ordered_gateways[$order[$gateway->id]] = $gateway;
} else {
$ordered_gateways[++$i] = $gateway;
}
$settings = new WC_POS_Admin_Settings_Gateways($gateway->id);
$settings->merge_settings($gateway);
apply_filters('woocommerce_pos_load_gateway', $gateway);
}
ksort($ordered_gateways, SORT_NUMERIC);
return $ordered_gateways;
}
示例4: __construct
public function __construct($options)
{
global $wpdb;
$this->wpdb = $wpdb;
$this->import = $options['import'];
$this->count = $options['count'];
$this->xml = $options['xml'];
$this->logger = $options['logger'];
$this->chunk = $options['chunk'];
$this->xpath = $options['xpath_prefix'];
$this->prices_include_tax = 'yes' === get_option('woocommerce_prices_include_tax', 'no');
$this->payment_gateways = WC_Payment_Gateways::instance()->get_available_payment_gateways();
$this->shipping_methods = WC()->shipping->get_shipping_methods();
if (class_exists('WC_Shipping_Zones')) {
$zones = WC_Shipping_Zones::get_zones();
if (!empty($zones)) {
foreach ($zones as $zone_id => $zone) {
if (!empty($zone['shipping_methods'])) {
foreach ($zone['shipping_methods'] as $method) {
$this->shipping_zone_methods[] = $method;
}
}
}
} else {
$zone = new WC_Shipping_Zone(0);
$this->shipping_zone_methods = $zone->get_shipping_methods();
}
}
$tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes'))));
if ($tax_classes) {
// Add Standard tax class
if (!in_array('', $tax_classes)) {
$tax_classes[] = '';
}
foreach ($tax_classes as $class) {
foreach (WC_Tax::get_rates_for_tax_class(sanitize_title($class)) as $rate_key => $rate) {
$this->tax_rates[$rate->tax_rate_id] = $rate;
}
}
}
add_filter('wp_all_import_is_post_to_skip', array(&$this, 'wp_all_import_is_post_to_skip'), 10, 5);
add_filter('wp_all_import_combine_article_data', array(&$this, 'wp_all_import_combine_article_data'), 10, 4);
}
示例5: get_tokens
/**
* Gets valid tokens from the database based on user defined criteria.
* @param array $args
* @return array
*/
public static function get_tokens($args)
{
global $wpdb;
$args = wp_parse_args($args, array('token_id' => '', 'user_id' => '', 'gateway_id' => '', 'type' => ''));
$sql = "SELECT * FROM {$wpdb->prefix}woocommerce_payment_tokens";
$where = array('1=1');
if ($args['token_id']) {
$token_ids = array_map('absint', is_array($args['token_id']) ? $args['token_id'] : array($args['token_id']));
$where[] = "token_id IN ('" . implode("','", array_map('esc_sql', $token_ids)) . "')";
}
if ($args['user_id']) {
$where[] = 'user_id = ' . absint($args['user_id']);
}
if ($args['gateway_id']) {
$gateway_ids = array($args['gateway_id']);
} else {
$gateways = WC_Payment_Gateways::instance();
$gateway_ids = $gateways->get_payment_gateway_ids();
}
$gateway_ids[] = '';
$where[] = "gateway_id IN ('" . implode("','", array_map('esc_sql', $gateway_ids)) . "')";
if ($args['type']) {
$where[] = 'type = ' . esc_sql($args['type']);
}
$token_results = $wpdb->get_results($sql . ' WHERE ' . implode(' AND ', $where));
$tokens = array();
if (!empty($token_results)) {
foreach ($token_results as $token_result) {
$_token = self::get($token_result->token_id, $token_result);
if (!empty($_token)) {
$tokens[$token_result->token_id] = $_token;
}
}
}
return $tokens;
}
示例6: payment_gateways
/**
* Get gateways class
* @return WC_Payment_Gateways
*/
public function payment_gateways()
{
return WC_Payment_Gateways::instance();
}
示例7: save
/**
* Save settings.
*/
public function save()
{
global $current_section;
$wc_payment_gateways = WC_Payment_Gateways::instance();
if (!$current_section) {
WC_Admin_Settings::save_fields($this->get_settings());
$wc_payment_gateways->process_admin_options();
} else {
foreach ($wc_payment_gateways->payment_gateways() as $gateway) {
if (in_array($current_section, array($gateway->id, sanitize_title(get_class($gateway))))) {
do_action('woocommerce_update_options_payment_gateways_' . $gateway->id);
$wc_payment_gateways->init();
}
}
}
}
示例8: translate_payment_instructions
function translate_payment_instructions($id)
{
if (function_exists('icl_translate')) {
$gateways = WC()->payment_gateways();
foreach ($gateways->payment_gateways as $key => $gateway) {
if ($gateway->id == $id) {
WC_Payment_Gateways::instance()->payment_gateways[$key]->instructions = icl_translate('woocommerce', $gateway->id . '_gateway_instructions', $gateway->instructions);
break;
}
}
}
}
示例9: translate_payment_instructions
function translate_payment_instructions($id)
{
$gateways = WC()->payment_gateways();
foreach ($gateways->payment_gateways as $key => $gateway) {
if ($gateway->id == $id && isset(WC_Payment_Gateways::instance()->payment_gateways[$key]->instructions)) {
do_action('wpml_register_single_string', 'woocommerce', $gateway->id . '_gateway_instructions', $gateway->instructions);
WC_Payment_Gateways::instance()->payment_gateways[$key]->instructions = apply_filters('wpml_translate_single_string', $gateway->instructions, 'woocommerce', $gateway->id . '_gateway_instructions');
break;
}
}
}
示例10: register_gateway_strings
function register_gateway_strings($fields)
{
$wc_payment_gateways = WC_Payment_Gateways::instance();
foreach ($wc_payment_gateways->payment_gateways() as $gateway) {
if (isset($_POST['woocommerce_' . $gateway->id . '_enabled'])) {
$gateway_id = $gateway->id;
break;
}
}
if (isset($gateway_id)) {
do_action('wpml_register_single_string', 'woocommerce', $gateway_id . '_gateway_title', $fields['title']);
if (isset($fields['description'])) {
do_action('wpml_register_single_string', 'woocommerce', $gateway_id . '_gateway_description', $fields['description']);
}
if (isset($fields['instructions'])) {
do_action('wpml_register_single_string', 'woocommerce', $gateway_id . '_gateway_instructions', $fields['instructions']);
}
}
return $fields;
}
示例11: _e
<div class="panel woocommerce_options_panel" id="payment_order_data" style="display:none;">
<div class="options_group hide_if_grouped">
<table class="form-table" style="max-width:none;">
<tr>
<td>
<!-- Payment Method -->
<div class="form-field">
<p class="form-field"><?php
_e('Payment Method', 'wpai_woocommerce_addon_plugin');
?>
</p>
<div class="form-field">
<select id="payment_method" name="pmwi_order[payment_method]" style="width: 200px; font-size: 14px !important;" class="switcher rad4">
<?php
$payment_gateways = WC_Payment_Gateways::instance()->get_available_payment_gateways();
$payment_gateways_for_tooltip = array();
foreach ($payment_gateways as $id => $gateway) {
echo '<option value="' . esc_attr($id) . '" ' . selected($id, $post['pmwi_order']['payment_method'], false) . '>' . esc_html($gateway->title) . '</option>';
$payment_gateways_for_tooltip[] = esc_attr($id);
}
?>
<option value="xpath" <?php
if ("xpath" == $post['pmwi_order']['payment_method']) {
echo 'selected="selected"';
}
?>
><?php
_e("Set with XPath", "wpai_woocommerce_addon_plugin");
?>
</option>
</select>
示例12: hocwp_wc_insert_order
function hocwp_wc_insert_order($data)
{
$post_id = hocwp_get_value_by_key($data, 'post_id');
if (hocwp_id_number_valid($post_id)) {
$post = get_post($post_id);
if (is_a($post, 'WP_Post') && 'product' == $post->post_type) {
$product = wc_get_product($post_id);
$variable_product = new WC_Product_Variable($product);
$variations = $variable_product->get_available_variations();
$variation_args = array();
$variation_id = null;
foreach ($variations as $variation) {
$variation_id = $variation['variation_id'];
$variation_args['variation'] = $variation['attributes'];
}
$name = hocwp_get_value_by_key($data, 'name');
$phone = hocwp_get_value_by_key($data, 'phone');
$email = hocwp_get_value_by_key($data, 'email');
$address = hocwp_get_value_by_key($data, 'address');
$message = hocwp_get_value_by_key($data, 'message');
$name = hocwp_sanitize_first_and_last_name($name);
$attributes = hocwp_get_value_by_key($data, 'attributes');
$addresses = array('first_name' => $name['first_name'], 'last_name' => $name['last_name'], 'email' => $email, 'phone' => $phone, 'address_1' => $address);
$args = array('customer_note' => $message, 'created_via' => 'programmatically');
if (is_user_logged_in()) {
$current = wp_get_current_user();
$args['customer_id'] = $current->ID;
}
$order = wc_create_order($args);
$gateway = WC_Payment_Gateways::instance();
$gateways = $gateway->get_available_payment_gateways();
if (hocwp_array_has_value($gateways)) {
$gateway = current($gateways);
$order->set_payment_method($gateway);
}
$order->set_address($addresses);
$order->set_address($addresses, 'shipping');
if (hocwp_array_has_value($attributes) && hocwp_id_number_valid($variation_id)) {
foreach ($attributes as $attribute) {
$attribute_name = hocwp_get_value_by_key($attribute, 'name');
$attribute_value = hocwp_get_value_by_key($attribute, 'value');
if (!empty($attribute_name) && !empty($attribute_value)) {
if (isset($variation_args['variation'][$attribute_name])) {
$variation_args['variation'][$attribute_name] = $attribute_value;
}
}
}
$variation_product = new WC_Product_Variation($variation_id);
$order->add_product($variation_product, 1, $variation_args);
} else {
$order->add_product($product);
}
$order->record_product_sales();
$order->calculate_totals();
$order->payment_complete();
return $order;
}
}
return false;
}
示例13: sr_query_sales
function sr_query_sales($cumm_dates, $date_series, $post)
{
$params = !empty($post['params']) ? $post['params'] : array();
if (!wp_verify_nonce($params['security'], 'smart-reporter-security')) {
die('Security check');
}
global $wpdb, $sr_text_domain;
$returns = array();
// Initialize the return data
$returns['chart'] = $returns['kpi'] = array();
$returns['meta'] = array('start_date' => $cumm_dates['cp_start_date'], 'end_date' => $cumm_dates['cp_end_date'], 's_link' => admin_url() . 'edit.php?post_type=shop_order&source=sr&sdate=' . $cumm_dates['cp_start_date'] . '&edate=' . $cumm_dates['cp_end_date']);
$returns['chart']['period'] = $date_series;
$periods_count = count($returns['chart']['period']);
$p2i = array_flip($returns['chart']['period']);
$time_str = $cumm_dates['format'] == '%H' ? ':00:00' : '';
if (!empty($post['cmd']) && ($post['cmd'] == 'cumm_sales' || $post['cmd'] == 'sr_summary')) {
$date_col = $cumm_dates['format'] == '%H' ? 'created_time' : 'created_date';
$chart_keys = array('sales', 'orders', 'discount');
$payment_methods = $shipping_methods = array();
// For each payment and shipping method...
foreach ((array) WC_Payment_Gateways::instance()->get_available_payment_gateways() as $key => $value) {
$chart_keys[] = 'pm_' . $key . '_sales';
$chart_keys[] = 'pm_' . $key . '_orders';
$returns['kpi']['pm'][$key] = array('title' => __($value->get_title(), $sr_text_domain), 'sales' => 0, 'orders' => 0, 's_link' => '&s=' . $value->get_title() . '&s_col=payment_method&s_val=' . $key);
}
foreach ((array) WC_Shipping::instance()->get_shipping_methods() as $key => $value) {
$chart_keys[] = 'sm_' . $key . '_sales';
$chart_keys[] = 'sm_' . $key . '_orders';
$returns['kpi']['sm'][$key] = array('title' => __($value->get_title(), $sr_text_domain), 'sales' => 0, 'orders' => 0, 's_link' => '&s=' . $value->get_title() . '&s_col=shipping_method&s_val=' . $key);
}
// Initialize chart data to 0
foreach ($chart_keys as $value) {
$returns['chart'][$value] = array_fill(0, $periods_count, 0);
}
// KPIs are single item stats.. init for current and last period (lp_)
$kpis = array('sales', 'refunds', 'orders', 'qty', 'discount', 'tax', 'shipping', 'shipping_tax');
foreach ($kpis as $value) {
$returns['kpi'][$value] = 0;
$returns['kpi']['lp_' . $value] = 0;
}
// Bring in grouped results for sales, discounts etc - then loop and process
// LAST_PERIOD is special 'period' value for comparing current period data
// with previous period
$query = $wpdb->prepare("SELECT 'LAST_PERIOD' as period, \n\t\t\t\t\t\t\t\t\t\t\tSUM( CASE WHEN type = 'shop_order' AND status != 'wc-refunded' THEN 1 ELSE 0 END ) as orders, \n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE total END), 0) AS sales,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN total \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHEN type = 'shop_order_refund' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE 0 END), 0) AS refunds,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE qty END), 0) AS qty,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE discount+cart_discount END), 0) AS discount,\n\t\t\t\t\t\t\t\t\t\t0 AS tax,\n\t\t\t\t\t\t\t\t\t\t0 AS shipping,\n\t\t\t\t\t\t\t\t\t\t0 AS shipping_tax,\n\t\t\t\t\t\t\t\t\t '' AS payment_method, \n\t\t\t\t\t\t\t\t\t '' AS shipping_method \n\t\t\t\t\t\t\t\t\tFROM `{$wpdb->prefix}woo_sr_orders` \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tcreated_date BETWEEN '%s' AND '%s'\n\t\t\t\t\t\t\t\t\t\tAND status in ('wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded')\n\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\tSELECT concat(DATE_FORMAT(" . $date_col . ", '%s'), '" . $time_str . "') AS period,\n\t\t\t\t\t\t\t\t\t\t\tSUM( CASE WHEN type = 'shop_order' AND status != 'wc-refunded' THEN 1 ELSE 0 END ) as orders, \n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE total END), 0) AS sales,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN total \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHEN type = 'shop_order_refund' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE 0 END), 0) AS refunds,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE qty END), 0) AS qty,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE discount+cart_discount END), 0) AS discount,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE tax END), 0) AS tax,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE shipping END), 0) AS shipping,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE shipping_tax END), 0) AS shipping_tax,\n\t\t\t\t\t\t\t\t\t payment_method, \n\t\t\t\t\t\t\t\t\t shipping_method \n\t\t\t\t\t\t\t\t\tFROM `{$wpdb->prefix}woo_sr_orders` \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tcreated_date BETWEEN '%s' AND '%s'\n\t\t\t\t\t\t\t\t\tAND status in ('wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded') \n\t\t\t\t\t\t\t\t\tGROUP BY period, payment_method, shipping_method", $cumm_dates['lp_start_date'], $cumm_dates['lp_end_date'], $cumm_dates['format'], $cumm_dates['cp_start_date'], $cumm_dates['cp_end_date']);
$results = $wpdb->get_results($query, 'ARRAY_A');
if (count($results) > 0) {
// The first row will always be last period data
$row = array_shift($results);
foreach ($kpis as $value) {
$returns['kpi']['lp_' . $value] = $row[$value];
}
// Loop and total up values now
foreach ($results as $row) {
if (!array_key_exists($row['period'], $p2i)) {
error_log('Smart Reporter: Invalid value for "period" in DB results - ' . $row['period']);
continue;
}
// Total up sales, refunds, qty etc...
foreach ($kpis as $key) {
$returns['kpi'][$key] += $row[$key];
}
// Index of this period - this will be used to position different chart data at this period's index
$i = $p2i[$row['period']];
// Set values in charts - for data other than payment / shipping methods
foreach ($chart_keys as $key) {
if (substr($key, 1, 2) != 'm_') {
// will match pm_ and sm_ both in single condition
$returns['chart'][$key][$i] += $row[$key];
}
}
// Set values for shipping and payment methods
foreach (array('pm' => $row['payment_method'], 'sm' => $row['shipping_method']) as $type => $method) {
foreach (array('sales', 'orders') as $f) {
$key = $type . '_' . $method . '_' . $f;
if (array_key_exists($key, $returns['chart'])) {
$row[$f] = $type == 'sm' && $f == 'sales' ? $row['shipping'] : $row[$f];
$returns['chart'][$key][$i] += $row[$f];
$returns['kpi'][$type][$method][$f] += $row[$f];
}
}
}
}
// sorting the pm and sm by sales
$returns['kpi']['pm'] = array_slice(sr_multidimensional_array_sort($returns['kpi']['pm'], 'sales', 'DESC'), 0, 5);
$returns['kpi']['sm'] = array_slice(sr_multidimensional_array_sort($returns['kpi']['sm'], 'sales', 'DESC'), 0, 5);
}
}
if (!empty($post['cmd']) && ($post['cmd'] == 'cumm_cust_prod' || $post['cmd'] == 'sr_summary')) {
$chart_keys = array();
$date_col = $cumm_dates['format'] == '%H' ? 'order_time' : 'order_date';
// KPIs are single item stats.. init for current and last period (lp_)
$kpis = array('car', 'carts', 'carts_prod', 'orders', 'orders_prod', 'corders', 'corders_prod', 'aipc', 'swc');
foreach ($kpis as $value) {
$returns['kpi'][$value] = 0;
if ($value == 'car' || $value == 'aipc' || $value == 'swc') {
$returns['kpi']['lp_' . $value] = 0;
}
}
// ###############################
// Top Customers
//.........这里部分代码省略.........