添加一个features选项卡,内容可以用custom field来写。


//Add custom tab
add_filter( 'woocommerce_product_tabs', 'wc_add_features_tab' );
function wc_add_features_tab( $tabs ){
global $product;
$content = get_post_meta( $product->id, 'product_features', true );
if( !empty($content) ) {
$tabs[ 'features' ] = array(
'title' => 'Features',
'priority' => 1,
'callback' => 'wc_features_tabs_panel_content',
'content' => $content, // custom field
);
}
return $tabs;
}
function wc_features_tabs_panel_content( $key, $tab ){
echo '<h2>' . $tab['title'] . '</h2>';
echo $tab['content'];
}

修改Shop base页面的浏览器标题


// Change the browser title of shop base page
add_filter('post_type_archive_title', 'theme_wc_shop_browser_title' );
function theme_wc_shop_browser_title( $title ){
if( $title == __('Products', 'woocommerce')){
$shop_page_id = woocommerce_get_page_id( 'shop' );
$page_title = get_the_title( $shop_page_id );
return $page_title;
}
return $title;
}

商店页面默认的浏览器标题(Browser Title)是Products,这个页面其实是一个custom post type archive页面,虽然内容区域的标题跟随该页面的标题,但浏览器标题却是WordPress默认的,Products是一个custom post type,所以它的archive页面标题就是它的label名称。
上面这段代码可以让页面的标题成为browser title。

用户访问时将产品自动添加到购物车


/ /add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if (!is_admin()) {
global $woocommerce;
$product_id = 64;
$found = false;
//check if product already in cart
if (sizeof($woocommerce->cart->get_cart()) > 0) {
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ($_product->id == $product_id)
$found = true;
}
// if product not found, add it
if (!$found)
$woocommerce->cart->add_to_cart($product_id);
} else {
// if no products in cart, add it
$woocommerce->cart->add_to_cart($product_id);
}
}
}

虚拟产品:付款成功后订单状态立即变为complete
add_filter( 'woocommerce_payment_complete_order_status', 'virtual_order_payment_complete_order_status', 10, 2 );

function virtual_order_payment_complete_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );

if ( 'processing' == $order_status &&
( 'on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status ) ) {

$virtual_order = null;

if ( count( $order->get_items() ) > 0 ) {

foreach( $order->get_items() as $item ) {

if ( 'line_item' == $item['type'] ) {

$_product = $order->get_product_from_item( $item );

if ( ! $_product->is_virtual() ) {
// once we've found one non-virtual product we know we're done, break out of the loop
$virtual_order = false;
break;
} else {
$virtual_order = true;
}
}
}
}

// virtual order, mark as completed
if ( $virtual_order ) {
return 'completed';
}
}

// non-virtual order, return original status
return $order_status;
}