简体   繁体   English

':'显示在移动设备上,而不显示在台式机上-woocommerce / wordpress / php

[英]':' shows up on mobile, but not on desktop - woocommerce/wordpress/php

Here is a picture of desktop and mobile, you can see there is a : in mobile that shouldn't be there. 这是台式机和移动设备的图片,您可以看到移动设备中不应有一个: Any idea what the cause of it could be? 你知道是什么原因吗?

在此处输入图片说明 在此处输入图片说明

Here is the template from the images - it uses code that falls outside of the scope of Wordpress because my client specifically requested I fix a problem this way, not because I think that it is a good idea to work outside of the scope of Wordpress :) 这是图像的模板-它使用的代码不在Wordpress范围内,因为我的客户明确要求我以这种方式解决问题,而不是因为我认为在Wordpress范围之外工作是个好主意: )

<?php
/**
 * Payment methods
 *
 * Shows customer payment methods on the account page.
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/payment-methods.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.6.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$current_user = wp_get_current_user();

$current_user_id = $current_user->ID;

$customer_id = get_user_meta( $current_user_id, '_stripe_customer_id', true );

\Stripe\Stripe::setApiKey("xxx");

$customer = \Stripe\Customer::retrieve((string)$customer_id);

$card_list = $customer->sources->all(["object" => "card"]);

$show_table = true;

if(isset($_POST['create_new_method'])) {
    $show_table = false;
}

$saved_methods = wc_get_customer_saved_methods_list( get_current_user_id() );
$has_methods   = (bool) $saved_methods;
$types         = wc_get_account_payment_methods_types();

/*echo " **saved_methods: ";
print_r($saved_methods);
echo " **saved_methods length: ";
count($saved_methods->cc);

echo " **card list: ";
print_r($card_list);

echo " **card list length: ".count($card_list->data);*/

$just_added_method = false;

if((empty($saved_methods) && count($card_list->data) > 0) || isset($_GET['added_card']) ) {
    $just_added_method = true;
}

do_action( 'woocommerce_before_account_payment_methods', $has_methods ); ?>

<?php if ( ( ($has_methods || $just_added_method) && $show_table ) ) : ?>
    <?php if ( $has_methods && $show_table ) : ?>

        <table class="woocommerce-MyAccount-paymentMethods shop_table shop_table_responsive account-payment-methods-table">
            <thead>
                <tr>
                    <?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
                        <th class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $column_id ); ?> payment-method-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
                    <?php endforeach; ?>
                </tr>
            </thead>
            <?php foreach ( $saved_methods as $type => $methods ) : ?>
                <?php foreach ( $methods as $method ) : ?>
                    <tr class="payment-method<?php echo ! empty( $method['is_default'] ) ? ' default-payment-method' : '' ?>">
                        <?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
                            <td class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $column_id ); ?> payment-method-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
                                <?php
                                if ( has_action( 'woocommerce_account_payment_methods_column_' . $column_id ) ) {
                                    do_action( 'woocommerce_account_payment_methods_column_' . $column_id, $method );
                                } elseif ( 'method' === $column_id ) {
                                    if ( ! empty( $method['method']['last4'] ) ) {
                                        /* translators: 1: credit card type 2: last 4 digits */
                                        echo sprintf( __( '%1$s ending in %2$s', 'woocommerce' ), esc_html( wc_get_credit_card_type_label( $method['method']['brand'] ) ), esc_html( $method['method']['last4'] ) );
                                    } else {
                                        echo esc_html( wc_get_credit_card_type_label( $method['method']['brand'] ) );
                                    }
                                } elseif ( 'expires' === $column_id ) {
                                    echo esc_html( $method['expires'] );
                                } elseif ( 'actions' === $column_id ) {
                                    foreach ( $method['actions'] as $key => $action ) {
                                        echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>&nbsp;';
                                    }
                                }
                                ?>
                            </td>
                        <?php endforeach; ?>
                    </tr>
                <?php endforeach; ?>
            <?php endforeach; ?>
            <?php if ($just_added_method && $show_table && empty($saved_methods)) : ?>
                <?php foreach ( $card_list->data as $added_card ) : ?>
                    <tr class="payment-method">
                        <?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
                            <td class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $column_id ); ?> payment-method-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
                                <?php
                                if ( has_action( 'woocommerce_account_payment_methods_column_' . $column_id ) ) {
                                    do_action( 'woocommerce_account_payment_methods_column_' . $column_id, $method );
                                } elseif ( 'method' === $column_id ) {
                                    $last4 = $added_card->last4;
                                    $brand = $added_card->brand;
                                    if ( ! empty( $last4 ) ) {
                                        /* translators: 1: credit card type 2: last 4 digits */
                                        echo sprintf( __( '%1$s ending in %2$s', 'woocommerce' ), esc_html( wc_get_credit_card_type_label( $brand ) ), esc_html( $last4 ) );
                                    } else {
                                        echo esc_html( wc_get_credit_card_type_label( $brand ) );
                                    }
                                } elseif ( 'expires' === $column_id ) {
                                    echo esc_html( $added_card['exp_month']."/".substr($added_card['exp_year'], 2) );
                                } elseif ( 'actions' === $column_id ) { ?>
                                    <button class="woocommerce-Button woocommerce-Button--alt button alt" id="delete_card" style="color: white!important" name="delete_card" onClick="location.href='https://www.grahmlux.com/wp-content/themes/betheme/includes/delete_payment_method.php?id=<?php echo $added_card->id; ?>&user_id=<?php echo $current_user_id; ?>'">Delete</button>
                                    <?php if($customer->default_source != $added_card->id) { ?>
                                        <button class="woocommerce-Button woocommerce-Button--alt button alt" id="make_default" style="color: white!important" name="make_default" onClick="location.href='https://www.grahmlux.com/wp-content/themes/betheme/includes/make_default.php?id=<?php echo $added_card->id; ?>&user_id=<?php echo $current_user_id; ?>'">Make default</button>
                                    <?php } ?>
                                <?php } ?>
                            </td>
                        <?php endforeach; ?>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
            <?php if ($just_added_method && $show_table && !empty($saved_methods)) { 
                $added_card = $card_list->data[count($card_list) - 1] ?>
                <tr class="payment-method">
                    <?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
                        <td class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $column_id ); ?> payment-method-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
                            <?php
                            if ( has_action( 'woocommerce_account_payment_methods_column_' . $column_id ) ) {
                                do_action( 'woocommerce_account_payment_methods_column_' . $column_id, $method );
                            } elseif ( 'method' === $column_id ) {
                                $last4 = $added_card->last4;
                                $brand = $added_card->brand;
                                if ( ! empty( $last4 ) ) {
                                    /* translators: 1: credit card type 2: last 4 digits */
                                    echo sprintf( __( '%1$s ending in %2$s', 'woocommerce' ), esc_html( wc_get_credit_card_type_label( $brand ) ), esc_html( $last4 ) );
                                } else {
                                    echo esc_html( wc_get_credit_card_type_label( $brand ) );
                                }
                            } elseif ( 'expires' === $column_id ) {
                                echo esc_html( $added_card['exp_month']."/".substr($added_card['exp_year'], 2) );
                            } elseif ( 'actions' === $column_id ) { ?>
                                <button class="woocommerce-Button woocommerce-Button--alt button alt" id="delete_card" style="color: white!important" name="delete_card" onClick="location.href='https://www.grahmlux.com/wp-content/themes/betheme/includes/delete_payment_method.php?id=<?php echo $added_card->id; ?>&user_id=<?php echo $current_user_id; ?>'">Delete</button>
                                <?php if($customer->default_source != $added_card->id) { ?>
                                    <button class="woocommerce-Button woocommerce-Button--alt button alt" id="make_default" style="color: white!important" name="make_default" onClick="location.href='https://www.grahmlux.com/wp-content/themes/betheme/includes/make_default.php?id=<?php echo $added_card->id; ?>&user_id=<?php echo $current_user_id; ?>'">Make default</button>
                                <?php } ?>
                            <?php } ?>
                        </td>
                    <?php endforeach; ?>
                </tr>
            <?php } ?>
        </table>

        <form action="" method="post">
            <input class="woocommerce-Button woocommerce-Button--alt button alt" style="background-color: #88d651!important;" name="create_new_method" type="submit" value="Add payment method" />
        </form>

    <?php endif; ?>

<?php else :

    $current_user = wp_get_current_user();

    $current_user_id = $current_user->ID;

    $customer_id = get_user_meta( $current_user_id, '_stripe_customer_id', true );

    \Stripe\Stripe::setApiKey("xxx");

    if($customer_id == NULL) {
        echo 'Make your first purchase to activate this feature - <a href="https://www.grahmlux.com/jewelry" style="font-weight: 700; text-decoration: underline; color: #ffffff">Shop Now</a>';
        //die();
    }
    else {
        $customer = \Stripe\Customer::retrieve((string)$customer_id);
    } ?>

    <?php if(count($card_list->data) == 0) { ?>
        <p class="woocommerce-Message woocommerce-Message--info woocommerce-info"><?php esc_html_e( 'No saved methods found.', 'woocommerce' ); ?></p>
    <?php } ?>

    <!--<form action="https://www.grahmlux.com/wp-content/themes/betheme/includes/add_payment_method.php" method="post" id="add_payment_method">-->
    <form action="https://www.grahmlux.com/wp-content/themes/betheme/includes/add_payment_method.php" method="post" id="add_payment_method">
      <div class="form-row">
        <label for="card-element">
          Credit or Debit Card (Secured By Stripe)
        </label>

        <div id="card-number" style="display: inline-block; width: 180px"></div>
        <div id="card-expiry" style="display: inline-block; width: 60px"></div>
        <div id="card-cvc" style="display: inline-block; width: 50px"></div>

        <!-- Used to display Element errors. -->
        <div id="card-errors" role="alert"></div>

        <button type="submit" class="woocommerce-Button woocommerce-Button--alt button alt" id="place_order" style="color: white!important" value="<?php esc_attr_e( 'Add payment method', 'woocommerce' ); ?>"><?php esc_html_e( 'Add payment method', 'woocommerce' ); ?></button>
      </div>
    </form>

    <script>
        var style = {
          base: {
            color: '#ffffff',
            fontSize: '14px',
            fontSmoothing: 'antialiased',
            '::placeholder': {
              color: '#ccc',
            },
            iconColor: "#fff"
          },
          invalid: {
            color: '#e5424d',
            ':focus': {
              color: '#303238',
            },
          },
        };
        var stripe = Stripe('pk_test_TpmyYk1TnhrxPqNpImYwjyap');
        var elements = stripe.elements();

        var cardNumber = elements.create('cardNumber', {
          placeholder: 'Add Card Number Here',
          style: style
        });
        var cardExpiry = elements.create('cardExpiry', {
          style: style
        });
        var cardCvc = elements.create('cardCvc', {
          style: style
        });

        window.mobilecheck = function() {
          var check = false;
          (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
          return check;
        };

        if(mobilecheck()) {
            cardNumber.mount('#Content > div > div > div > div.section.mcb-section.hide-desktop > div > div > div > div > div > div > div > form > div.form-row >div#card-number');
            cardExpiry.mount('#Content > div > div > div > div.section.mcb-section.hide-desktop > div > div > div > div > div > div > div > form > div.form-row >div#card-expiry');
            cardCvc.mount('#Content > div > div > div > div.section.mcb-section.hide-desktop > div > div > div > div > div > div > div > form > div.form-row >div#card-cvc');
        }
        else {
            cardNumber.mount('#Content > div > div > div > div.section.mcb-section.hide-tablet.hide-mobile > div > div > div > div > div > div > div > form > div.form-row > div#card-number');
            cardExpiry.mount('#Content > div > div > div > div.section.mcb-section.hide-tablet.hide-mobile > div > div > div > div > div > div > div > form > div.form-row > div#card-expiry');
            cardCvc.mount('#Content > div > div > div > div.section.mcb-section.hide-tablet.hide-mobile > div > div > div > div > div > div > div > form > div.form-row > div#card-cvc');
        }

        cardNumber.addEventListener('change', function(event) {
          var displayError = document.getElementById('card-errors');
          if (event.error) {
            displayError.textContent = event.error.message;
          } else {
            displayError.textContent = '';
          }
        });

        var stop = 0;

        // Create a token or display an error when the form is submitted.
        var form = document.getElementById('add_payment_method');
        form.addEventListener('submit', function(event) {

          event.preventDefault();

          stripe.createToken(cardNumber).then(function(result) {
            if (result.error) {
              // Inform the customer that there was an error.
              var errorElement = document.getElementById('card-errors');
              errorElement.textContent = result.error.message;
            } else {
                if(stop == 0) {
                  console.log("inside stop token from being stored");
                  // Send the token to your server.
                  stripeTokenHandler(result.token);
                  stop = 1;
                }
                else {
                  stop = 0
                }
            }
          });

        });

        function delete_cookie( name ) {
          document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
        }

        function createCookie(name,value) {

            delete_cookie("stripe_token");

            var date = new Date();
            date.setTime(date.getTime()+1000);
            var expires = "; expires="+date.toGMTString();

            document.cookie = name+"="+value+expires+"; path=/; domain=.grahmlux.com";
            //document.cookie = name+"="+value+expires+"; path=/";
        }

        function createUserIDCookie(name,value) {
            document.cookie = name+"="+value+""+"; path=/; domain=.grahmlux.com";
            //document.cookie = name+"="+value+""+"; path=/";
        }

        function stripeTokenHandler(token) {
            var current_user_id = <?php echo $current_user_id; ?>

            console.log("current_user_id:", current_user_id);

            //MUST BE THIS ORDER BECAUSE OF DELETE_COOKIE
            createUserIDCookie("user_id", current_user_id);
            createCookie("stripe_token", token);

            var form = document.getElementById('add_payment_method');
            form.submit();
        }
    </script>

<?php endif; ?>

<?php do_action( 'woocommerce_after_account_payment_methods', $has_methods ); ?>

Anyone see any typos/anything that could be causing this to happen on mobile and not on desktop? 有人看到错别字/任何可能导致这种情况发生在移动设备上而不是台式机上吗?

我需要编辑css:在一个::before标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM