我正在使用 WooCommerce 3.4.4 版本,当您按“X”按钮从购物车页面删除产品时,我正在尝试编辑通知消息。
目前的通知是"<product name>" removed. Undo?
我想删除报价并将消息更改为Product name has been removed. [Undo button]
我已设法通过写入删除产品名称中的引号
add_filter( 'woocommerce_cart_item_removed_title', 'removed_from_cart', 10, 2);
function removed_from_cart( $message, $product_data ) {
$product = get_the_title($product_data['product_id']);
$message = $product;
return $message;
}
Run Code Online (Sandbox Code Playgroud)
但我对如何进行其余的编辑有点困惑。任何帮助表示赞赏。
我正在尝试使 url.com/my-account 或短代码 [woocommerce_my_account] 显示订单,而不是显示“您好用户(不是用户)?”的仪表板。
我唯一拥有的是登录后重定向到订单而不是仪表板,但我然后转到 /my-account 仍然显示我不想要的仪表板。
我发现的最接近我想要的代码是......
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
Run Code Online (Sandbox Code Playgroud)
但是,如果没有下订单,则显示为空白(不显示“尚未下订单。”带有商店按钮)并且我的帐户导航侧栏不显示。我是否必须为此创建一个自定义页面模板才能添加到 woocommerce 帐户导航侧栏中?
编辑:如果我使用 orders.php 而不是 my-orders.php 那么我能够得到“尚未下订单”。但仍然没有侧边栏导航
在 Woocommerce 结帐部分,我尝试添加一个复选框来添加其他产品。
我有一段工作代码,它会增加费用并在单击复选框时更新购物车,但我希望它添加产品而不是附加费:
function cart_custom_fee( $cart ) {
if( !$_POST || ( is_admin() && ! is_ajax() ) ) {
return;
}
if( isset( $_POST['post_data'] ) ) {
parse_str( $_POST['post_data'], $post_data );
} else {
$post_data = $_POST;
}
if( isset( $post_data['add_test_item'] ) ) { // This is the checkbox name
WC()->cart->add_fee('Test Item', 35);
}
}
add_action( 'woocommerce_cart_calculate_fees', 'cart_custom_fee' );
Run Code Online (Sandbox Code Playgroud)
这是复选框的代码
<script>
jQuery(document).ready(function(){
jQuery('#cp-checkbox').click(function() {
jQuery('body').trigger('update_checkout');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
代码有效……
现在,我尝试更改代码以添加产品:
function add_item_checkout( $cart ) {
if( !$_POST || ( …Run Code Online (Sandbox Code Playgroud)