워드프레스(우커머스)의 속도 변화

워드프레스(우커머스)의 속도 변화

리눅스환경에서 워드프레스의 속도가 빠르게 향상되고 있습니다.

PHP는 5.2, 5.3 거쳐 5.5, 5,6 ( 6.x은 개발 실패 ) 7.0, 7.1, 7.2 ~ 곧 8.0으로 진화 하고 있습니다.
5.6 만으로도 서버의 리소스가 충분할 경우 PC버전의 워드프레스는 빠른속도를 보여줍니다.
모바일 앱으로서의 속도는 많이 부족한 퍼포먼스였습니다.

7.0 이상 7.2에서는 어떨까요? 5.6에서의 환경보다 최소 2.5배 이상은 빨라졌습니다.
조만간 출시될 8.0에서는 7.0대비 2~3배 빠를거라는군요.
진정한 하이브리드앱으로서의 저작툴이 되지 않을까 싶네요.

 

PHP 란 무엇입니까?

PHP는 Hypertext Preprocessor의 약자입니다. 오늘날 웹에서 가장 인기있는 스크립팅 언어 중 하나입니다. W3Techs에 따르면 PHP는 서버 측 프로그래밍 언어를 사용하는 모든 웹 사이트 중 83 % 이상에서 사용됩니다.

PHP 버전별  워드프레스 벤치마킹

Benchmark Results

  • WordPress 4.9.4 PHP 5.6 benchmark results: 49.18 req/sec
  • WordPress 4.9.4 PHP 7.0 benchmark results: 133.55 req/sec
  • WordPress 4.9.4 PHP 7.1 benchmark results: 134.24 req/sec
  • WordPress 4.9.4 PHP 7.2 benchmark results148.80 req/sec 🏆
  • WordPress 4.9.4 HHVM benchmark results: 144.76 req/sec

PHP 버전별 우커머스 벤치마킹

Benchmark Results

  • WordPress 4.9.4 + WooCommerce 3.3.1 PHP 5.6 benchmark results: 34.47 req/sec
  • WordPress 4.9.4 + WooCommerce 3.3.1 PHP 7.0 benchmark results: 84.89 req/sec
  • WordPress 4.9.4 + WooCommerce 3.3.1 PHP 7.1 benchmark results: 86.04 req/sec
  • WordPress 4.9.4 + WooCommerce 3.3.1 PHP 7.2 benchmark results: 92.60 req/sec 🏆
  • WordPress 4.9.4 + WooCommerce 3.3.1 HHVM benchmark results: 69.58 req/sec

WooCommerce struggled with HHVM, and PHP 7.2 beat out PHP 7.1 by a small margin.

우커머스-카트 확인후 조건부 체크아웃

우커머스-카트 확인후 조건부 체크아웃

Product Specific Conditional

/** * Check if a specific product ID is in the cart */ function wc_ninja_product_is_in_the_cart() { // Add your special product IDs here $ids = array( ’45’, ’70’, ’75’ );; // Products currently in the cart $cart_ids = array(); // Find each product in the cart and add it to the $cart_ids array foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $cart_product = $values[‘data’]; $cart_ids[] = $cart_product->id; } // If one of the special products are in the cart, return true. if ( ! empty( array_intersect( $ids, $cart_ids ) ) ) { return true; } else { return false; } }

 

/**
* Conditionally remove a checkout field based on products in the cart
*/
function wc_ninja_remove_checkout_field( $fields ) {
if ( ! wc_ninja_product_is_in_the_cart() ) {
unset( $fields[‘billing’][‘billing_company’] );
}

return $fields;
}
add_filter( ‘woocommerce_checkout_fields’ , ‘wc_ninja_remove_checkout_field’ );

 

Product Category Conditional

 

/**
* Check if a specific product category is in the cart
*/
function wc_ninja_category_is_in_the_cart() {
// Add your special category slugs here
$categories = array( ‘clothing’, ‘posters’ );

// Products currently in the cart
$cart_ids = array();

// Categories currently in the cart
$cart_categories = array();

// Find each product in the cart and add it to the $cart_ids array
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$cart_product = $values[‘data’];
$cart_ids[] = $cart_product->id;
}

// Connect the products in the cart w/ their categories
foreach( $cart_ids as $id ) {
$products_categories = get_the_terms( $id, ‘product_cat’ );

// Loop through each product category and add it to our $cart_categories array
foreach ( $products_categories as $products_category ) {
$cart_categories[] = $products_category->slug;
}
}

// If one of the special categories are in the cart, return true.
if ( ! empty( array_intersect( $categories, $cart_categories ) ) ) {
return true;
} else {
return false;
}
}

 

Coupon Conditional

 

/**
* Check if a specific coupon was used
*/
function wc_ninja_coupon_was_used() {
// Add a list of coupons to check for here.
$coupons = array( ‘percent_coupon’, ‘free_shipping’ );

// Coupons Used
$coupons_used = WC()->cart->applied_coupons;

// If ones of our special coupons were used, return true.
if ( in_array( $coupons, $coupons_used ) ) {
return true;
} else {
return false;
}
}

우커머스-제품이 카트에 이미 담겨졌습니다.

제품이 카트에 이미 담겨졌는지 확인해서 카트명을 변경합니다.

비슷한 제품이 많은 쇼핑몰인경우 효율적인 기능입니다.

<?php /** * Change the add to cart text on single product pages */ add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’); function woo_custom_cart_button_text() { foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values[‘data’]; if( get_the_ID() == $_product->id ) { return __(‘Already in cart – Add Again?’, ‘woocommerce’); } } return __(‘Add to cart’, ‘woocommerce’); } /** * Change the add to cart text on product archives */ add_filter( ‘woocommerce_product_add_to_cart_text’, ‘woo_archive_custom_cart_button_text’ ); function woo_archive_custom_cart_button_text() { foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { $_product = $values[‘data’]; if( get_the_ID() == $_product->id ) { return __(‘Already in cart’, ‘woocommerce’); } } return __(‘Add to cart’, ‘woocommerce’); }

주문완료 페이지 만들기

add_filter( 'the_content', 'wc_custom_thankyou' );
function wc_custom_thankyou( $content ) {
	// Check if is the correct page
	if ( ! is_page( {PAGE_ID} ) ) {
		return $content;
	}

	// check if the order ID exists
	if ( ! isset( $_GET['order'] ) ) {
		return $content;
	}

	// intval() ensures that we use an integer value for the order ID
	$order = wc_get_order( intval( $_GET['order'] ) );

	ob_start();

	// Check that the order is valid
	if ( ! $order ) {
		// The order can't be returned by WooCommerce - Just say thank you
		?><p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p><?php
	} else {
		if ( $order->has_status( 'failed' ) ) {
			// Order failed - Print error messages and ask to pay again

			/**
			 * @hooked wc_custom_thankyou_failed - 10
			 */
			do_action( 'wc_custom_thankyou_failed', $order );
		} else {
			// The order is successfull - print the complete order review

			/**
			 * @hooked wc_custom_thankyou_header - 10
			 * @hooked wc_custom_thankyou_table - 20
			 * @hooked wc_custom_thankyou_customer_details - 30
			 */
			do_action( 'wc_custom_thankyou_successful', $order );
		}
	}

	$content .= ob_get_contents();
	ob_end_clean();

	return $content;
}