2017-03-24 点击:1142
上次写了WooCommerce开发常见代码连载一,今天继续WooCommerce主题项目开发中遇到常见代码及问题解决,这里记录下来,方便以后查找。
WC()是woocommerce的一个全局对象,这行代码将返回当前购物车中的金额,不带货币单位,纯数字
WC()->cart->total;
在woccommerce中的wc-cart-functions.php中,重写wc_cart_totals_shipping_html()函数,返回当前订单的运费
function wc_cart_totals_shipping_html() {
$packages = WC()->shipping->get_packages();
echo $packages[0]['rates']['your_shipping_method']->cost;
}
在from-checkout.php中,找到下面的代码,删除即可
do_action( 'woocommerce_checkout_shipping' );
$cart_item["data"]->price;
$cart_item['line_subtotal'];
在wordpress中所有action,就是我们在页面看到的do_action()函数中的参数,都可以添加的自定义的filter
add_filter( 'woocommerce_checkout_fields' , 'custom_demo' );
function custom_demo( $fields ) {
}
在cart.php中找到下面的代码,这段代码是生成的购物车中商品数量的input,删除它
if ( $_product->is_sold_individually() ) {
$product_quantity = sprintf( '1 ', $cart_item_key );
} else {
$product_quantity = woocommerce_quantity_input( array(
'input_name' => "cart[{$cart_item_key}][qty]",
'input_value' => $cart_item['quantity'],
'max_value' => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(),
'min_value' => '0'
), $_product, false );
}
echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item );