WooCommerce在结帐中删除产品按钮
我们正在使用PHP字符串来启用在结帐中删除产品的选项。
以下代码:
/**
* Allows to remove products in checkout page.
*
* @param string $product_name
* @param array $cart_item
* @param string $cart_item_key
* @return string
*/
function lionplugins_woocommerce_checkout_remove_item( $product_name, $cart_item, $cart_item_key ) {
if ( is_checkout() ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
$remove_link = apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" rel="nofollow" class="remove-icon" style="float:left;">x</a>',
esc_url( WC()->cart->get_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'woocommerce' ),
esc_attr( $product_id ),
esc_attr( $_product->get_sku() )
), $cart_item_key );
return '<span>' . $remove_link . '</span> <span>' . $product_name . '</span>';
}
return $product_name;
}
但是布局有点混乱。
是否有一种方法可以强迫表结构使其总是向左/右浮动?就像强制浮子一样,或仅用于删除按钮的“单独”表列。我尝试对图标进行调整,并添加更多填充或更改图标类型,但没有成功。
对于PHP和编码仍然很不知,因此将不胜感激。
编辑: 我相信这是其他人的答案 - wooCommerce:删除结帐页面上的产品线?
但是,我们使用的是“ WooCommerce Composite产品”,该产品使A.eRemove按钮在不同位置浮动,如上图所示。
we're using a PHP string to enable the option to remove products in the checkout.
Following code:
/**
* Allows to remove products in checkout page.
*
* @param string $product_name
* @param array $cart_item
* @param string $cart_item_key
* @return string
*/
function lionplugins_woocommerce_checkout_remove_item( $product_name, $cart_item, $cart_item_key ) {
if ( is_checkout() ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
$remove_link = apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" rel="nofollow" class="remove-icon" style="float:left;">x</a>',
esc_url( WC()->cart->get_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'woocommerce' ),
esc_attr( $product_id ),
esc_attr( $_product->get_sku() )
), $cart_item_key );
return '<span>' . $remove_link . '</span> <span>' . $product_name . '</span>';
}
return $product_name;
}
But the layout is a bit messed up.
Is there a way to force the table structure to have it always float far left/right? Like a forced float, or a sort of "separate" table column just for the remove button. I tried tweaking the CSS for the icon and add more padding or change the icon type but with no success.
Still quite clueless to PHP and coding so any help or guidance would be greatly appreciated.
edit:
I believe this is the answer for other people - Woocommerce : How to remove product lines on Checkout page?
However we're using "WooCommerce Composite Products" which makes the a.remove button float in different location as shown in the image above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过以下 -
https://stackoverflow.com/a/46364755/17132682 ;代码>
并在删除CSS的情况下
简单地将删除图标添加到表的末端。
Solved by following - https://stackoverflow.com/a/46364755/17132682
Used this instead:
'<a href="%s" class="remove" title="%s" data-product_id="%s" data-product_sku="%s">×</a>',
and with CSS removed where the remove icon was
Then simple added the function at the very end of the table instead.