【发布时间】:2015-01-06 04:45:11
【问题描述】:
我正在尝试覆盖 Woocommerce Stripe 插件的输出 HTML。我该怎么做呢?我已经阅读了一些关于动作钩子和过滤器的文章和文档,但我相信这些仅适用于 Woocommerce 插件,而不适用于 Woo/Stripe 扩展插件。如果钩子或过滤器是解决方案,那会是什么样子?我可以修改核心文件或使用 JS,但这些都不是真正可行的解决方案......
我要修改的文件位于:
plugins/woocommerce-gateway-stripe/includes/class-wc-gateway-stripe.php
这是我要在该文件中修改的标记块:
/**
* Payment form on checkout page
*/
public function payment_fields() {
$checked = 1;
?>
<fieldset>
<?php
if ( $this->description ) {
echo wpautop( esc_html( $this->description ) );
}
if ( $this->saved_cards && is_user_logged_in() && ( $customer_id = get_user_meta( get_current_user_id(), '_stripe_customer_id', true ) ) && is_string( $customer_id ) && ( $cards = $this->get_saved_cards( $customer_id ) ) ) {
?>
<p class="form-row form-row-wide">
<a class="button" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php _e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a>
<?php if ( $cards ) : ?>
<?php foreach ( (array) $cards as $card ) : ?>
<label for="stripe_card_<?php echo $card->id; ?>">
<input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="stripe_card_id" value="<?php echo $card->id; ?>" <?php checked( $checked, 1 ) ?> />
<?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), (isset( $card->type ) ? $card->type : $card->brand ), $card->last4, $card->exp_month, $card->exp_year ); ?>
</label>
<?php $checked = 0; endforeach; ?>
<?php endif; ?>
<label for="new">
<input type="radio" id="new" name="stripe_card_id" <?php checked( $checked, 1 ) ?> value="new" />
<?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?>
</label>
</p>
<?php
}
?>
<div class="stripe_new_card" <?php if ( $checked === 0 ) : ?>style="display:none;"<?php endif; ?>
data-description=""
data-amount="<?php echo $this->get_stripe_amount( WC()->cart->total ); ?>"
data-name="<?php echo sprintf( __( '%s', 'woocommerce-gateway-stripe' ), get_bloginfo( 'name' ) ); ?>"
data-label="<?php _e( 'Confirm and Pay', 'woocommerce-gateway-stripe' ); ?>"
data-currency="<?php echo strtolower( get_woocommerce_currency() ); ?>"
data-image="<?php echo $this->stripe_checkout_image; ?>"
>
<?php if ( ! $this->stripe_checkout ) : ?>
<?php $this->credit_card_form( array( 'fields_have_names' => false ) ); ?>
<?php endif; ?>
</div>
</fieldset>
<?php
}
【问题讨论】:
标签: php wordpress woocommerce payment-gateway stripe-payments