WP용 Woocommerce의 wc_add_to_cart_message 훅 대체 수단
Woocommerce에서 Add to Cart 메시지 훅을 사용하여 텍스트를 편집하고 특정 버튼에서 일부 클래스를 삭제했습니다.이 훅은 Woocommerce 2.1에서 폐지된 것으로 보여 대체품을 찾을 수 없습니다.
쇼핑 계속' 버튼에서 '버튼' 클래스를 제거하고 싶습니다.이 클래스는 Woocommerce 코어로 정의되며, 이후 적절한 업데이트를 위해 편집되지 않은 상태로 둡니다.
편집하려는 행은 woocommerce/includes/wc-cart-functions에 있습니다.php 행 94.
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
이 갈고리에 대한 적절한 대안을 찾은 사람 있나요?잘 부탁드립니다!
이건 내게 효과가 있었다.
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
$return_to = get_permalink(woocommerce_get_page_id('shop'));
$message = sprintf('<a href="%s" class="button wc-forwards">%s</a> %s', $return_to, __('Continue Shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
return $message;
}
편집 : Kaarel Kaspar 수정 감사합니다.
Woocommerce 2.3+,
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message( $message ){
global $woocommerce;
$added_text = __( 'Product was successfully added to your Network Kit.', 'woocommerce' );
// Output success messages
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
else :
$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', wc_get_page_permalink( 'cart' ), __( 'View your Network Kit', 'woocommerce' ), $added_text );
endif;
return $message;
}
이 스레드는 조금 오래된 것이지만, G 검색 엔진의 첫 번째 링크에서 버전 3.0 이후 사용되지 않는 것에 대한 동일한 질문에 대한 링크를 찾았습니다.이것이 오류를 수정한 것입니다.
오류:
주의: wc_add_to_cart_message 필터는 버전 3.0 이후 폐지되었습니다.대신 wc_add_to_cart_message_html을 사용하십시오./sitepath.com/wp-includes/functions.php의 4329번 줄에 있습니다.
주의: woocommerce_get_page_id는 버전 3.0부터 권장되지 않습니다.대신 wc_get_page_id를 사용하십시오./sitepath.com/wp-includes/functions.php의 4329번 줄에 있습니다.
보시는 바와 같이 문제(에러 메시지)에 해결 방법이 있습니다.
사용하다wc_add_to_cart_message_html
사용하다wc_get_page_id instead
2020년 현재 이 필터가 필요합니다.wc_add_to_cart_message는 폐지되었습니다.여기에서는, 메시지를 스팬으로 간단하게 정리합니다.
//New added to card message text
function filter_wc_add_to_cart_message_html( $message, $products ) {
return "<span>".$message."</span>";
};
add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );
이게 해결책이 될 수 있어더 나은 방법이나 아이디어가 있으면 변경해 주세요.
2.1 버전에서 filter-name이 "wc_add_to_message"로 변경되었습니다.
add_filter( 'wc_add_to_cart_message', 'foo' );
function foo() {
$product_id = $_REQUEST[ 'product_id' ];
if ( is_array( $product_id ) ) {
$titles = array();
foreach ( $product_id as $id ) {
$titles[] = get_the_title( $id );
}
$added_text = sprintf( __( 'Added "%s" to your cart.', 'woocommerce' ), join( __( '" and "', 'woocommerce' ), array_filter( array_merge( array( join( '", "', array_slice( $titles, 0, -1 ) ) ), array_slice( $titles, -1 ) ) ) ) );
} else {
$added_text = sprintf( __( '"%s" was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) );
}
// Output success messages
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
$message = sprintf(
'<a href="%s" class="alert-link">%s →</a> %s',
$return_to, __( 'Continue Shopping', 'woocommerce' ),
$added_text
);
else :
$message = sprintf(
'<a href="%s" class="alert-link">%s →</a> %s',
get_permalink( wc_get_page_id( 'cart' ) ),
__( 'View Cart', 'woocommerce' ),
$added_text );
endif;
return $message;
}
도움이 됐으면 좋겠네요건배.
언급URL : https://stackoverflow.com/questions/21832684/alternative-for-the-wc-add-to-cart-message-hook-in-woocommerce-for-wp
'programing' 카테고리의 다른 글
Typescript와 함께 스타일링된 컴포넌트를 사용하면 프로펠러가 존재하지 않습니까? (0) | 2023.03.07 |
---|---|
짧은 maxLifetime 값 - hikari 연결 풀 스프링 부트 사용을 고려해 보십시오. (0) | 2023.03.07 |
플러그인 활성화 후 리디렉션 (0) | 2023.03.07 |
Response' 개체가 구독 가능한 Python http post 요청이 아닙니다. (0) | 2023.03.07 |
" 아래의 속성을 com.zaxxer에 바인딩하지 못했습니다.hikari.Hikari Data Source 스프링 부트 (0) | 2023.03.07 |