Wordpress - Woocommerce remove "Added to Cart" 메시지
카트에 아이템을 추가한 후 "카트에 제품이 성공적으로 추가되었습니다"라는 문구와 영역을 삭제하려고 합니다.나는 그저 아무 것도, 메시지도, 메시지를 위한 공간도 없기를 바랄 뿐입니다.
다음은 사이트입니다. http://www.tinytreasurehunts.com 코드는 우커머 기능으로 되어있습니다.php
무슨 생각 있어요?
PHP 수준에서 이를 해결하려면 테마에 다음 템플릿 파일(및 구조)을 추가합니다.
/wp-content/themes/YOUR-THEME/woocommerce/shop/messages.php
:
<?php
/**
* Show messages
*
* @author brasofilo
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! $messages ) return;
foreach ( $messages as $message ) :
// The message does not contain the "add to cart" string, so print the message
// http://stackoverflow.com/q/4366730/1287812
if ( strpos( $message, 'added to your cart' ) === false ) :
?>
<div class="woocommerce-message"><?php echo wp_kses_post( $message ); ?></div>
<?php
endif;
endforeach;
참조: 템플릿 구조 + 테마를 통해 템플릿 재정의
다음 중 하나를 사용합니다.
구버전
$woocommerce->clear_messages();
버전 2.3
wc_clear_notices();
간단한 CSS만 사용하면 됩니다.
.single-product .woocommerce-message {
display: none !important;
}
또는 function.php를 잘 알고 있다면 다음과 같은 방법이 더 좋습니다.
add_filter( 'wc_add_to_cart_message_html', '__return_null' );
소스가 여기에 있습니다. 대신 자신의 버전을 인쇄하고자 할 경우 이러한 메시지를 편집할 수 있는 방법이 있습니다.
CSS를 사용하고 ID 또는 관련 클래스에 대해 디스플레이를 none으로 설정합니다.
.page-id-522 .woocommerce_message {
display: none;
}
이것은 페이지 ID 522에 해당합니다.이것이 신용카드 감소 등과 같은 다른 유용한 메시지를 숨기지 않도록 해야 합니다.
테마 함수에 이 코드를 추가합니다.php 파일.해당 메시지만 제거됩니다.발생 가능성이 높은 페이지에서만 트리거할 수 있습니다.
function remove_added_to_cart_notice()
{
$notices = WC()->session->get('wc_notices', array());
foreach( $notices['success'] as $key => &$notice){
if( strpos( $notice, 'has been added' ) !== false){
$added_to_cart_key = $key;
break;
}
}
unset( $notices['success'][$added_to_cart_key] );
WC()->session->set('wc_notices', $notices);
}
add_action('woocommerce_before_single_product','remove_added_to_cart_notice',1);
add_action('woocommerce_shortcode_before_product_cat_loop','remove_added_to_cart_notice',1);
add_action('woocommerce_before_shop_loop','remove_added_to_cart_notice',1);
Woocmerce 제거/숨기기 카트 메시지에 추가되지만 쿠폰 적용 메시지는 유지/표시할 때 제 답변을 붙여 넣었습니다.
WooCommerce 버전 2.1.6 업데이트
템플릿은 새 디렉토리와 파일에 있습니다.위와 같은 코드 및 솔루션.
/wp-content/플러그인/wocommerce/templates/notices/성공.
테마 파일의 끝이나 하위 테마에서 .post.woocmerce_message{display:none;}를 사용합니다.
언급URL : https://stackoverflow.com/questions/14024405/wordpress-woocommerece-remove-added-to-cart-message
'programing' 카테고리의 다른 글
mysql/mariadb에서 ID가 같은 여러 행을 WHERE로 쿼리하는 방법 (0) | 2023.09.24 |
---|---|
각도에서 ng-click not fireing in Angular클릭 시 JS가 실행됩니다. (0) | 2023.09.24 |
javascript에서 CSS 변수 접근 (0) | 2023.09.24 |
op 사용 시 성능에 미치는 영향 (0) | 2023.09.24 |
jQuery를 사용하여 데이터 속성 값 업데이트 (0) | 2023.09.24 |