简体   繁体   English

更改WooCommerce产品列CSS仅适用于商店页面

[英]Change WooCommerce product column CSS for Shop page only

I am using the latest Wordpress with the Storefront Theme & Child Theme. 我正在将最新的Wordpress与店面主题和子主题一起使用。

I am wanting to change the height: and padding: of the columns for WooCommerce's products (actually categories but they use the same columns). 我想更改WooCommerce产品的列的height:padding:实际上是类别,但它们使用相同的列)。 On the shop page only the categories are displayed which do not require to be as tall as product columns (no price, no sale tag, no buy now or add to cart button etc are on categories) 在商店页面上, 显示类别,这些类别不需要与产品列一样高(类别中没有价格,没有销售标签,无需立即购买或添加到购物车按钮等)

I am using this small piece of PHP in my Child Theme Functions to try and implement this but it doesn't seem to change anything, nor are any errors given: 我在子主题函数中使用了这小段PHP来尝试实现这一点,但是它似乎并没有改变任何东西,也没有给出任何错误:

function dayles_custom_shop_columns()
{
    if (function_exists('is_shop') && is_shop()) {
        echo "<style type='text/css'>.storefront-full-width-content .site-main ul.products.columns-4 li.product, ul.products li.product {height:320px!important;padding:20px!important;min-height:320px!important;max-height:320px!important;}</style>";
    } else {
       //Do nothing.
    }
}

I have also tried this using !important to see if it had any difference. 我也使用!important尝试了一下,看是否有任何区别。 But nope. 但是不。

Any help is appreciated! 任何帮助表示赞赏!

You need to add a wp_head action hook in your functions: 您需要在函数中添加wp_head操作钩子:

Example: 例:

function my_custom_css() {
     if (function_exists('is_shop') && is_shop()) {
        echo "<style type='text/css'>.storefront-full-width-content .site-main ul.products.columns-4 li.product, ul.products li.product {height:320px!important;padding:20px!important;min-height:320px!important;max-height:320px!important;}</style>";
    }
}
add_action('wp_head', 'my_custom_css' );

More information on wp_head action here . 有关wp_head操作的更多信息,请参见here

To make the product loop on shop page of same height, please wrap all the loop items in your custom div and then write your style. 为了使产品循环在相同高度的商店页面上,请将所有循环项目包装在自定义div中,然后编写样式。

Paste the below code in current active theme functions.php file 将以下代码粘贴到当前活动主题的functions.php文件中

function start_before_shop_loop_item() {
   echo '<div class="custom_shop_loop_wrap">';
}
function end_after_shop_loop_item() {
  echo '</div>';
}
add_action( 'woocommerce_before_shop_loop_item', 'start_before_shop_loop_item', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'end_after_shop_loop_item', 10 );

Then using the class custom_shop_loop_wrap add your styling. 然后使用类custom_shop_loop_wrap添加您的样式。

function custom_css_add_wrap(){?>
<style>
    .custom_shop_loop_wrap{
      height:height:320px;
      max-height:320px;
}
</style>
   <?php }
add_action('wp_head', 'custom_css_add_wrap' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM