我正在 WooCommerce 中自定义订单电子邮件模板,并且需要在订单详细信息中将“发货”排在倒数第二,就在“总计”上方。
我知道这个循环在 woocommerce>templates>emails 的“email-order-details.php”页面的第 52 行,所以在我的孩子主题中设置它,但我不确定从那里去哪里。这是我正在尝试的:
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
if($total['label'] === "Shipping"){
//make second-last above total somehow
}
else{
?><tr>
<th class="td" scope="row" colspan="3" style="text-align:<?php echo $text_align; ?>; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo $total['label']; ?></th>
<td class="td" style="text-align:left; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>" colspan="1"><?php echo $total['value']; …
Run Code Online (Sandbox Code Playgroud) 你如何通过它的名字获得产品?我知道你可以通过ID和SKU来做到这一点,但对于我目前的情况,我需要按标题获取产品.我一直在查找,似乎无法找到功能.
我的功能发生在单个产品页面上,但我需要从中获取数据的产品将不是用户正在查看的当前产品.相反,它将与当前产品具有相同的名称,仅以不同的符号结尾.(用户将看到的产品以"-r"结尾,而我需要搜索的产品以" - $$$"结尾)
到目前为止在我的Functions.php中:
function fill_refurbished_addon_selectbox(){
//get id of current product
global $product;
$id= $product->get_id();
//get name of product
$currentName = get_the_title($id);
//remove -r, add -$$$ and store in var
$searchFor = substr($currentName, 0, -2) . "-$$$";
echo $searchFor;
//find $$$ product by title
$coreCharge = ***GET PRODUCT BY TITLE ($searchFOr)***;
//get price of $$$ product, store in var
//populate dropbox
}
add_action('woocommerce_before_add_to_cart_button', 'fill_refurbished_addon_selectbox', 20);
Run Code Online (Sandbox Code Playgroud)
原因是,我需要在 - $$$产品中填写一个包含信息的选择框.
如果选中结帐字段中的复选框,我会尝试将运费价格设置为 0.00 美元。
当前尝试:
function no_shipping_for_own_ups($rates,$package) {
foreach ($rates as $rate) {
//Set the price
$rate->cost = 0;
}
return $rates;
}
function woo_add_cart_ups_y_n_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['billing_ups_yn'])) {
add_filter( 'woocommerce_package_rates','no_shipping_for_own_ups', 99, 2 );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_ups_y_n_fee', 43, 1 );
Run Code Online (Sandbox Code Playgroud)
作为$post_data['billing_ups_yn']
我设置为在触发时更新结帐的复选框。
只需选中复选框,然后应用过滤器将运费设置为 0。 …
我需要通过产品的 id 检查产品的可见性状态。不仅仅是它是否可见,而是它是否被搜索、隐藏或可见。
我已经尝试过get_post_meta($id, '_visibility', true);
,但是只有我的旧产品在数据库中具有该帖子元,所以我假设它不再使用。
这样做的总体原因是因为我试图用产品短代码显示产品,但没有选项可以在可见性内“显示全部”。例如,
echo do_shortcode('[products ids="' . $id . '" visibility="all"]');
Run Code Online (Sandbox Code Playgroud)
所以现在我必须检查产品的可见性并回显适当的短代码来显示它。除非我弄错了,并且有一种方法可以显示带有短代码的产品,无论它们的可见性如何......