【发布时间】:2017-09-11 14:18:28
【问题描述】:
我运营的网站上有很多免费产品,会员加入后可以访问这些产品。他们必须再次结帐才能得到它们(它们是必须为每个用户唯一生成的凭证,因此需要再次结帐)。
当用户将其中一种产品添加到购物车并结账时,我想显示一个超级简单的结账页面。我真的只是想添加一个横幅图片,然后将“下单”黄油中心对齐在图片下方。
我设法使用以下代码删除了大部分结帐字段:
function sv_free_checkout_fields() {
global $woocommerce ;
// Bail we're not at checkout, or if we're at checkout but payment is needed
if ( ! is_checkout() || ( is_checkout() && WC()->cart->needs_payment() ) ) {
return;
}
if ( $woocommerce->cart->total != 0 ) {
return;
}
if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
return;
}
// remove coupon forms since why would you want a coupon for a free cart??
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
// remove order review section
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
// Remove the "Additional Info" order notes
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
// Unset the fields we don't want in a free checkout
function unset_unwanted_checkout_fields( $fields ) {
// add or remove billing fields you do not want
// list of fields: http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2
$billing_keys = array(
'billing_first_name',
'billing_last_name',
'billing_company',
'billing_phone',
'billing_email',
'billing_address_1',
'billing_address_2',
'billing_city',
'billing_postcode',
'billing_country',
'billing_state',
);
// unset each of those unwanted fields
foreach( $billing_keys as $key ) {
unset( $fields['billing'][$key] );
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'unset_unwanted_checkout_fields' );
// A tiny CSS tweak for the account fields; this is optional
function print_custom_css() {
echo '<style>.create-account { margin-top: 6em; }</style>';
}
add_action( 'wp_head', 'print_custom_css' );
}
add_action( 'wp', 'sv_free_checkout_fields' );
所以到目前为止,只要将这些免费产品之一添加到购物车并且用户去结帐,它就会删除除“下订单”按钮(我想保留)之外的所有内容,以及围绕该按钮的一些样式, 左侧的“Billing Details”标题,以及围绕该标题的矩形边框,以及其正下方的另一个矩形框。我似乎无法弄清楚如何删除最后几件事。
这是我需要删除的创建按钮周围框的代码:
body.woocommerce-cart .cart-collaterals, form.checkout.woocommerce-checkout
#order_review {
width: 40%;
display: inline-block;
padding: 20px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
border: 1px solid #f1f1f1;
background-color: #fdfdfd;
}
这是我需要在左侧删除的 div:
<div class="woocommerce-billing-fields">
<h3>Billing details</h3>
<div class="woocommerce-billing-fields__field-wrapper">
</div>
</div>
我只需要在购物车总数为零时将它们移除。我还想将下单按钮居中,并在可能的情况下在其上方添加横幅。
【问题讨论】:
标签: php css wordpress woocommerce