我是一个php初学者,我试图在一个php文件中指定3个文本输出,并给它们一个独特的类,这样我就可以通过css来设置它们的样式。

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

$customer_id = get_current_user_id();
if ( ! wc_ship_to_billing_address_only() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) {
$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __('My Addresses:', 'woocommerce') );
$get_addresses    = apply_filters( 'woocommerce_my_account_get_addresses', array(
    'billing' => __( 'Billing Address:', 'woocommerce' ),
    'shipping' => __( 'Shipping Address:', 'woocommerce' )
), $customer_id );
} else {
$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Address:', 'woocommerce' ) );
$get_addresses    = apply_filters( 'woocommerce_my_account_get_addresses', array(
    'billing' =>  __( 'Billing Address:', 'woocommerce' )
), $customer_id );
}
$col = 1;
?>

我正试图瞄准“我的地址:”以及“帐单地址:”和“送货地址:”。
我以前也做过这方面的工作,我从来没有在php代码中添加类,但肯定是有可能的,但是我似乎找不到任何关于在哪里添加div类、p类等的信息。
任何帮助都将不胜感激!
谢谢,
瓦亚

最佳答案

你可以使用Woomerce过滤器来包装你想要的东西。在functions.php中放入类似的内容:

function filter_woocommerce_my_account_my_address_title( $var ) {
    return '<span class="your-class-here">'.$var.'</span>';
};
add_filter( 'woocommerce_my_account_my_address_title', 'filter_woocommerce_my_account_my_address_title', 10, 1 );

function filter_woocommerce_my_account_get_addresses( $array, $customer_id ) {
    $array['billing'] = '<span class="class-name-here">'.$array['billing'].'</span>';
    $array['shipping'] = '<span class="another-class-name-here">'.$array['shipping'].'</span>';
    return $array;
};
add_filter( 'woocommerce_my_account_get_addresses', 'filter_woocommerce_my_account_get_addresses', 10, 2 );

请记住,如果这些元素是唯一的,那么id属性可能是更好的选择。
希望有帮助!

关于php - 在Woocommerce的PHP代码中插入类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36153109/

10-10 13:52
查看更多