问题描述
我一直在尝试创建自己的woocommerce主题,现在我正在配置结帐表单。
在购物车页面上,我修改了cart-shipping.PHP使其可折叠,并根据其位置显示了估算的金额。
当他们单击“运输选项”时,将打开这样的表单-
现在,当他们结帐时,我希望扩大运输字段,而没有两个运输字段。我不明白为什么我有两个运输领域。但是,当我单击选项按钮时,它同时打开了两个字段(因为它们具有相同的ID,并且它们是从相同的PHP文件中调用的...
这是代码查找checkout / form-checkout.PHP的方式
<?PHP
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.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/
* @package WooCommerce\Templates
* @version 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_before_checkout_form',$checkout );
// If checkout registration is disabled and not logged in,the user cannot checkout.
if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message',__( 'You must be logged in to checkout.','woocommerce' ) ) );
return;
}
add_filter( 'woocommerce_billing_fields','custom_print_all_fields' );
?>
<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?PHP echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
<?PHP if ( $checkout->get_checkout_fields() ) : ?>
<?PHP do_action( 'woocommerce_checkout_before_customer_details' ); ?>
<div class="col2-set" id="customer_details">
<div class="card p-4">
<div class="">
<?PHP do_action( 'woocommerce_checkout_billing'); ?>
</div>
</div>
<div class="col-2">
<?PHP do_action( 'woocommerce_checkout_shipping' ); ?>
</div>
</div>
<?PHP do_action( 'woocommerce_checkout_after_customer_details' ); ?>
<?PHP endif; ?>
<?PHP do_action( 'woocommerce_checkout_before_order_review_heading' ); ?>
<h3 id="order_review_heading"><?PHP esc_html_e( 'Your order','woocommerce' ); ?></h3>
<?PHP do_action( 'woocommerce_checkout_before_order_review' ); ?>
<div id="order_review" class="woocommerce-checkout-review-order">
<?PHP do_action( 'woocommerce_checkout_order_review' ); ?>
</div>
<?PHP do_action( 'woocommerce_checkout_after_order_review' ); ?>
</form>
<?PHP do_action( 'woocommerce_after_checkout_form',$checkout ); ?>
这是我为更改购物车外观而更改的cart / cart-shipping.PHP页面代码
defined( 'ABSPATH' ) || exit;
$formatted_destination = isset( $formatted_destination ) ? $formatted_destination : WC()->countries->get_formatted_address( $package['destination'],',' );
$has_calculated_shipping = ! empty( $has_calculated_shipping );
$show_shipping_calculator = ! empty( $show_shipping_calculator );
$calculator_text = esc_html__( 'Change Address','woocommerce' );
?>
<tr class="woocommerce-shipping-totals shipping ">
<div class="d-flex justify-content-between">
<div class="text-left"><?PHP echo wp_kses_post( $package_name ); ?>:</div>
<div class="text-right">
<?PHP
foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){
if( WC()->session->get('chosen_shipping_methods')[0] == $method_id ){
$rate_label = $rate->label; // The shipping method label name
$rate_cost_excl_tax = floatval($rate->cost); // The cost excluding tax
// The taxes cost
$rate_taxes = 0;
foreach ($rate->taxes as $rate_tax)
$rate_taxes += floatval($rate_tax);
// The cost including tax
$rate_cost_incl_tax = $rate_cost_excl_tax + $rate_taxes;
echo '
<span class="totals">'. WC()->cart->get_cart_shipping_total() .'</span>';
break;
}
}
?>
<br/>
<a class="shipping-calculator-button" href="#" type="button" data-toggle="collapse" data-target="#shippingCollapse" aria-expanded="false" aria-controls="shippingCollapse">
Shipping options
</a>
<div class="collapse" id="shippingCollapse">
<div data-title="<?PHP echo esc_attr( $package_name ); ?>">
<?PHP if ( $available_methods ) : ?>
<ul id="shipping_method" class="woocommerce-shipping-methods">
<?PHP foreach ( $available_methods as $method ) : ?>
<li>
<?PHP
if ( 1 < count( $available_methods ) ) {
printf( '<input type="radio" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" %4$s />',$index,esc_attr( sanitize_title( $method->id ) ),esc_attr( $method->id ),checked( $method->id,$chosen_method,false ) ); // WPCS: XSS ok.
} else {
printf( '<input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d_%2$s" value="%3$s" class="shipping_method" />',esc_attr( $method->id ) ); // WPCS: XSS ok.
}
printf( '<label for="shipping_method_%1$s_%2$s">%3$s</label>',wc_cart_totals_shipping_method_label( $method ) ); // WPCS: XSS ok.
do_action( 'woocommerce_after_shipping_rate',$method,$index );
?>
</li>
<?PHP endforeach; ?>
</ul>
<?PHP if ( is_cart() ) : ?>
<p class="woocommerce-shipping-destination">
<?PHP
if ( $formatted_destination ) {
// Translators: $s shipping destination.
printf( esc_html__( 'Shipping to %s.','woocommerce' ) . ' ','<strong>' . esc_html( $formatted_destination ) . '</strong>' );
// $calculator_text = esc_html__( 'Change Address','woocommerce' );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_shipping_estimate_html',__( 'Shipping options will be updated during checkout.','woocommerce' ) ) );
}
?>
</p>
<?PHP endif; ?>
<?PHP
elseif ( ! $has_calculated_shipping || ! $formatted_destination ) :
if ( is_cart() && 'no' === get_option( 'woocommerce_enable_shipping_calc' ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_shipping_not_enabled_on_cart_html',__( 'Shipping costs are calculated during checkout.','woocommerce' ) ) );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_shipping_may_be_available_html',__( 'Enter your address to view shipping options.','woocommerce' ) ) );
}
elseif ( ! is_cart() ) :
echo wp_kses_post( apply_filters( 'woocommerce_no_shipping_available_html',__( 'There are no shipping options available. Please ensure that your address has been entered correctly,or contact us if you need any help.','woocommerce' ) ) );
else :
// Translators: $s shipping destination.
echo wp_kses_post( apply_filters( 'woocommerce_cart_no_shipping_available_html',sprintf( esc_html__( 'No shipping options were found for %s.','<strong>' . esc_html( $formatted_destination ) . '</strong>' ) ) );
$calculator_text = esc_html__( 'Enter a different address','woocommerce' );
endif;
?>
<?PHP if ( $show_package_details ) : ?>
<?PHP echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
<?PHP endif; ?>
<?PHP woocommerce_shipping_calculator( $calculator_text ); ?>
<!-- --><?PHP //if ( $show_shipping_calculator ) : ?>
<!-- --><?PHP //endif; ?>
</div>
</div>
</div>
</div>
</tr>
我已经研究这个问题了几个小时,但似乎找不到重复的原因。 我觉得这就是我的问题所在。
<h3 id="order_review_heading"><?PHP esc_html_e( 'Your order','woocommerce' ); ?></h3>
<?PHP do_action( 'woocommerce_checkout_before_order_review' ); ?>
我不知道如何编辑此钩子。
摘要:
更新1:
当我注释掉<?PHP do_action( 'woocommerce_checkout_order_review' ); ?>
时,它删除了出厂选项,因此我假设这是需要编辑的文件/挂钩。
当我在速度较慢的3G上加载页面时,我可以看到页面最初加载时只添加了一个运送字段,但是我感觉javascript在页面加载后会创建一个额外的页面。
更新2: 发现了问题!当我将表格转换为div时,它将使其重复。 (与woocommerce的默认设置进行比较时。引导显示类还会破坏代码,并在不应该在结帐页面上显示内容。因此,最好通过CSS而不是引导HTML来调用display flex。
新问题: 如何将wordpress中的表格转换为div?为什么我的div导致我的运输选项重复?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)