level 2
新手自学代码求助,希望厉害的大佬能帮忙指点迷津。拜谢!
2022年06月11日 07点06分
1
level 2
//以下这段代码意图添加一种新的货币类别
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['HeartToken'] = __( 'Currency name', 'woocommerce' );
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 100, 2);
//以下这段代码意图为刚才添加的货币类别添加图标,通过引用本地png图片来展示新货币logo
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'HeartToken':
header('Content-Type:image/png;');
$img=imgcreatefrompng('/wp-content/uploads/2022/03/hearttoken.png');// 图片储存位置: 网站名/wp-content/uploads/2022/03/hearttoken.png
$currency_symbol = '$img';
imagedestroy($img);
break;
}
return $currency_symbol;
2022年06月11日 07点06分
2
level 2
//下面这段代码意图让所有的商品在网页中显示时不展示价格:
add_filter( 'woocommerce_get_price_html', 'alter_price_display', 100, 2 );
function alter_price_display( $price_html, $product ) {
global $woocommerce ;
if ( wc_current_user_has_role( 'vendor') || wc_current_user_has_role( 'subscriber' )|| wc_current_user_has_role( 'Superadmin' ) )
{
$orig_price = ''; //wc_get_price_to_display( $product );
$price_html = ''; //wc_price( $orig_price * 0.80 );
}
return $price_html;
}
//下面这段代码意图让所有的商品在以下情形价格为1 : 购物车内结算时
add_action( 'woocommerce_before_calculate_totals', 'alter_price_cart', 100 );
function alter_price_cart( $cart ) {
global $woocommerce ;
foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$price = 1;//$product->get_price();
$cart_item['data']->set_price(1); //set_price( $price * 0.80 );
}
}
2022年06月11日 07点06分
3