为了让WooCommerce产品图像以正确的方式"显示",我使用了uSig the wp_footer钩子的css.这样,产品缩略图就可以正确地显示在带有margin等的收银台上.

Code:

add_action( 'wp_footer', 'ls_product_image_css_checkout', 900 );
function ls_product_image_css_checkout() {

    // run only on checkout
    if ( is_checkout() ) { ?>

        <style>
        .product-item-thumbnail{ float:left; padding-right:20px; }
        .product-item-thumbnail img{ margin:0!important; }
        </style>

    <?php
    }
}

现在,这是我真正的问题,是的,我已经try 了各种CSS解决方案,因为产品移除有<a class="",然而,无论我做什么-从 checkout 中移除产品的X显示在缩略图的右侧,紧挨着Product Name.

我需要把拆卸的X放在thumbnailLEFT上.

This is the code I am using:

add_filter( 'woocommerce_cart_item_name', 'ls_product_removal_on_the_left_of_product_image_on_checkout', 20, 3 );
function ls_product_removal_on_the_left_of_product_image_on_checkout( $product_name, $cart_item, $cart_item_key ) {

    // only on checkout, of course
    if ( is_checkout() ) {

    // get cart
    $cart = WC()->cart->get_cart();

        // loop through cart
        foreach ( $cart as $cart_key => $cart_value ) {

            if ( $cart_key == $cart_item_key ) {

                $product_id = $cart_item[ 'product_id' ];
                $_product = $cart_item[ 'data' ];

                // this is part of what I cannot figure out
                $remove_product = sprintf(
                '<a class="rpfc" href="%s" title="%s" data-product_id="%s" data-product_sku="%s" data-cart_item_key="%s">&#10005;</a>',
                esc_url(wc_get_cart_remove_url( $cart_key)), __( 'Delete this product from my order', 'woocommerce' ),
                esc_attr( $product_id ),
                esc_attr( $_product->get_sku()),
                esc_attr( $cart_item_key ));
            }
        }

        // get product data
        $product = $cart_item[ 'data' ];

        // display the iamge on checkout, 40*40 px
        $thumbnail = $product->get_image( array( 40, 40 ) );

        // the HTML
        $image_html = '<div class="product-item-thumbnail">' . $thumbnail . '</div>';

        // get the product name and link it. If clicked, re-directed to the product page
        $product_name_link = '<a href="' . $product->get_permalink() . '">' . $product_name . '</a>';

        // the removal of the product BEFORE the image
        // REMOVAL (on the left of the image) IMAGE PRODUCT NAME
        $product_name = $remove_product . $image_html . $product_name_link;
    }

    return $product_name;
}

推荐答案

对于样式(Css),永远不要使用页脚,因为css将永远不会被应用,始终使用页眉.因此,您需要将'wp_footer'钩改为'wp_head'钩.它应该能解决这个问题.

挂钩'wp_footer'有时被用来添加一些JavaScript(JQuery)代码.


要仅在结帐页面中运行此代码,请替换:

if ( is_checkout() ) {

有:

if ( is_checkout() && ! is_wc_endpoint_url() ) {

这样,代码将只在 checkout 页面有效,而不是在"订单收到"(thankyou)和"订单付款"页面有效.


如果某些CSS规则不起作用,您可能需要(或try ):

  • 提高挂钩优先级,如下所示:

    add_action( 'wp_head', 'ls_product_image_css_checkout', 999999 );
    
  • 对每条不起作用的规则加!important,如:float:none !important;

Php相关问答推荐

为WooCommerce中的特定用户角色指定促销价格

如何在Livewire中验证多个 Select 字段

Symfony Monolog:使用多个格式化程序

使用PHP和WebSockets或SSE实现实时通知

将购买限制在WooCommerce中具有相同产品属性的项目

将一个情态形式放在细丝v3中的形式中间

PHP -将字符串拆分为两个相等的部分,但第二个字符串中的单词更多

基于服务器的不同地平线配置

在php中,方法之间的属性链接是如何工作的

Regex:高级删除单行PHP注释

在WooCommerce中以编程方式添加特定产品后,将价格设置为零

Shopware 6插件:由于删除了配置密钥,更新后配置值不正确

有没有办法像引用枚举一样引用注册表中的对象?

需要以一种形式执行两个操作

如何在 PHP laravel 中将图像的透明背景转换为白色?

PHP文件如何从CSS执行

如何通过额外的属性和本地化来使用 laravel 枚举

在 Laravel、Vuejs 和 Inertia 中配置 TypeScript 的问题

Laravel 测试 assertJsonMissing 不适用于唯一的键.为什么?

PHP 中的 curl 验证失败(openssh 连接正常)