WordPress WooCommerce不显示价格 不显示购物车按钮

来源: 老季博客
日期: 2021-8-21
作者: 腾讯云/服务器VPS推荐评测/Vultr
阅读数: 51

不显示价格

不显示价格,去掉价格字段即可 把代码放在主题的functions.php下

//Hide price
add_filter( 'woocommerce_get_price_html', 'woocommerce_hide_price' );
function woocommerce_hide_price( $price ){
    return '';
}

去掉购买按钮

//Hide buy button
add_action( 'init', 'woocommerce_hide_buy_button' );
function woocommerce_hide_buy_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}

wc-ajax

没有购买按钮,就无法向购物车中添加任何产品,购物车页面可有可无。
如果完全不需要购物功能,将WooCommerce的购物车、结账等页面删除即可(此项未亲测)。

在实际的使用过程中,会发现”wc-ajax = get_refreshed_fragments”的加载时间为1.5秒,然后这并不是必须的。并且延缓了网站的加载速度。可以加入代码:

add_action( 'wp_print_scripts', 'de_script', 100 );
function de_script() {
    wp_dequeue_script( 'wc-cart-fragments' );
    return true;
}

删除产品架构标记

/**
 * 从“产品类别”和“商店”页面中删除生成的产品架构标记。
 */
function wc_remove_product_schema_product_archive() {
	remove_action( 'woocommerce_shop_loop', array( WC()->structured_data, 'generate_product_data' ), 10, 0 );
}
add_action( 'woocommerce_init', 'wc_remove_product_schema_product_archive' );
链接到文章: https://jiloc.com/47335.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注