워드프레스 우커머스 – 장바구니 버튼 이름 변경 방법

오늘은 워드프레스(WordPress) 온라인 쇼핑몰 플러그인(Plugin)인 우커머스(WooCommerce)의 장바구니(카트) 버튼 이름을 변경하는 방법을 설명하겠습니다.

상품 아카이브 페이지의 장바구니 버튼명 변경 방법

활성화된 테마 폴더 밑의 functions.php 파일을 사용하시는 에디터툴로 엽니다.

우커머스(WooCommerce) 버전 2.1 이하

add_filter( 'add_to_cart_text', 'my_archive_custom_cart_button_text' );
function my_archive_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

우커머스(WooCommerce) 버전 2.1 이상

add_filter( 'woocommerce_product_add_to_cart_text', 'my_archive_custom_cart_button_text' );
function my_archive_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

상품 디테일(싱글) 페이지의 장바구니 버튼이름 변경 방법

활성화된 테마 폴더 밑의 functions.php 파일을 사용하시는 에디터툴로 엽니다.

우커머스(WooCommerce) 버전 2.1 이하

add_filter( 'add_to_cart_text', 'my_custom_cart_button_text' );    // < 2.1
function my_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

우커머스(WooCommerce) 버전 2.1 이상

add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_custom_cart_button_text' );    // 2.1 +
function my_custom_cart_button_text() {
 
        return __( 'My Button Text', 'woocommerce' );
 
}

상품 아카이브 페이지의 장바구니 상품타입에 따라 버튼이름 변경 방법

활성화된 테마 폴더 밑의 functions.php 파일을 사용하시는 에디터툴로 엽니다.

add_filter( 'woocommerce_product_add_to_cart_text' , 'my_woocommerce_product_add_to_cart_text' );
function my_woocommerce_product_add_to_cart_text() {
	global $product;
	
	$product_type = $product->product_type;
	
	switch ( $product_type ) {
		case 'external':
			return __( 'Buy product', 'woocommerce' );
		break;
		case 'grouped':
			return __( 'View products', 'woocommerce' );
		break;
		case 'simple':
			return __( 'Add to cart', 'woocommerce' );
		break;
		case 'variable':
			return __( 'Select options', 'woocommerce' );
		break;
		default:
			return __( 'Read more', 'woocommerce' );
	}
	
}

오늘은 워드프레스(WordPress)의 장점이라 할 수 있는 기능중의 하나인 필터기능으로 우커머스(WooCommerce)의 장바구니 버튼명을 변경하는 방법에 대해 소개하였습니다. 다음번에도 유용한 팁을 좋은 포스팅으로 찾아뵙겠습니다 ^-^

연관글: 우커머스(WooCommerce) – 페이팔 결제 버튼 텍스트 변경 방법

우커머스, WooCommerce, WordPress – 페이팔 결제 버튼 텍스트 변경

워드프레스(WordPress)는 CMS(Contents Management System)으로 개인 블로그를 쉽게 만들고 컨텐츠를 작성하기 쉽게 사용하기 위해 태어났다. 하지만 근 몇년 동안 우커머스(WooCommerce) 플러그인(plugin)을 설치해서 소규모의 온라인 쇼핑몰을 제작하기 쉽게 되었다.

오늘은 워드프레스(WordPress)에서 제공하는 filter를 이용하는 방법을 소개하려고 한다. 물론 플러그인(plugin) 또는 워드프레스(WordPress)에서 후킹이나 필터링을 제공하지 않는다면 플러그인(plugin) 또는 워드프레스(WordPress) 코어파일을 직접 수정해야만 한다. 이는 플러그인(plugin) 또는 워드프레스(WordPress)가 업데이트가 되었을때 직접 수정한 코드가 지워지기 때문에 플러그인(plugin) 또는 워드프레스(WordPress)를 직접 수정하는 것은 좋지 않은 방법이다.

현재 활성화된 theme 폴더 밑에 functions.php 파일은 연다.

제일 밑에 아래 코드를 삽입하면 끝이다. 물론 위치는 상관없다.

add_filter( 'gettext', 'custom_paypal_button_text', 20, 3 );
function custom_paypal_button_text( $translated_text, $text, $domain ) {
	switch ( $translated_text ) {
		case 'Proceed to PayPal' :
			$translated_text = __( 'NEW BUTTON TEXT', $domain );
			break;
	}
	return $translated_text;
}

하이라이트 된 5번라인에서 NEW BUTTON TEXT를 변경 원하는 내용으로 바꿔주고 저장하면 끝!

연관글: 워드프레스(WordPress) 우커머스(WooCommerce) – 장바구니 버튼 이름 변경 방법