我购买了Porto Wordpress主题,并创建并激活了子主题。
在子主题中,我放置了一个functions.php文件,以使Woocommerce电话计费字段为可选。
没有结束标记?>可能会导致任何问题。
//make billing fields not required in checkout
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
return $address_fields;
}
我也放了exit();在文件中查看会发生什么,但是什么也没发生。
如何确保完全调用functions.php文件。
全功能。php内容
(某些代码片段可能已经过时,但是它们都不起作用,这很奇怪)。
add_action( 'wp_enqueue_scripts', 'porto_child_css', 1001 );
// Load CSS
function porto_child_css() {
// porto child theme styles
wp_deregister_style( 'styles-child' );
wp_register_style( 'styles-child', esc_url( get_stylesheet_directory_uri() ) . '/style.css' );
wp_enqueue_style( 'styles-child' );
}
// Pre-populate Woocommerce checkout fields
add_filter('woocommerce_checkout_get_value', function($input, $key ) {
global $current_user;
switch ($key) :
case 'billing_first_name':
case 'shipping_first_name':
return "HEEEY".$current_user->first_name;
break;
case 'billing_last_name':
case 'shipping_last_name':
return $current_user->last_name;
break;
case 'billing_email':
return $current_user->user_email;
break;
case 'billing_phone':
return $current_user->phone;
break;
endswitch;
}, 10, 2);
// Remove some fields from Woocommerce
add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );
function custom_remove_woo_checkout_fields( $fields ) {
// remove billing fields
//unset($fields['billing']['billing_first_name']);
//unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_phone']);
unset($fields['billing']['billing_email']);
// remove shipping fields
unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_company']);
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_city']);
unset($fields['shipping']['shipping_postcode']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_state']);
// remove order comment fields
unset($fields['order']['order_comments']);
return $fields;
}
//make billing fields not required in checkout
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
return $address_fields;
}
//make shipping fields not required in checkout
add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_shipping_fields', 10, 1 );
function wc_npr_filter_shipping_fields( $address_fields ) {
$address_fields['shipping_first_name']['required'] = false;
$address_fields['shipping_last_name']['required'] = false;
$address_fields['shipping_address_1']['required'] = false;
$address_fields['shipping_city']['required'] = false;
$address_fields['shipping_postcode']['required'] = false;
return $address_fields;
}
// Hide the "Expires" and "Downloads Remaining" columns from emails and My Account
add_action( 'woocommerce_account_downloads_columns', 'custom_downloads_columns', 10, 1 ); // Orders and account
add_action( 'woocommerce_email_downloads_columns', 'custom_downloads_columns', 10, 1 ); // Email notifications
function custom_downloads_columns( $columns ){
// Removing "Download expires" column
if(isset($columns['download-expires']))
unset($columns['download-expires']);
// Removing "Download remaining" column
if(isset($columns['download-remaining']))
unset($columns['download-remaining']);
return $columns;
}
答案 0 :(得分:1)
只要您的子主题处于活动状态,就应调用它(转到外观>主题,并确保您的子主题处于活动状态)。您无需在functions.php末尾使用结束标记即可使该文件正常工作。但是,进行测试的一种好方法是调用位于子主题文件夹中的style.css文件。在您的functions.php顶部,您应该能够看到wp_enqueue_style。
还尝试通过使用get_stylesheet_directory_uri()使子主题style.css入队(Parent style.css使用get_template_directory_uri)。
它应该看起来像这样:
// enqueue styles for child theme
function example_enqueue_styles() {
// enqueue parent styles
wp_enqueue_style('parent-theme', get_template_directory_uri() .'/style.css');
// enqueue child styles
wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/style.css', array('parent-theme'));
}
add_action('wp_enqueue_scripts', 'example_enqueue_styles');
现在重新加载您的站点->检查站点并选择“网络选项卡”。从这里您可以看到站点上加载的所有文件。尝试找到子主题style.css文件。如果您在“网络”标签中看到该文件,则表示该文件正在被调用。
答案 1 :(得分:0)
由于它是高级主题,因此仅应从主题支持团队获得支持和“正确的解决方案”。但是,您可以尝试增加过滤器挂钩的priority。
distinct