我想在我的前端模板文件中显示默认的产品属性表单值和常规价格.
在var_dump下面示出了在一个阵列的选项.我需要得到[default_attributes]价值观.
<?php
global $product;
echo var_dump( $product );
// Need to get the [default_attributes] values
?>
Run Code Online (Sandbox Code Playgroud)
我想向我的支付网关添加自定义图标。我已阅读 WOO 网关 API,但获得的帮助为零。这是我下面的代码。请帮助我找到一种包含该图标的实用方法,以便我的前端有一个图标。谢谢
\n\n<?php if ( ! defined( 'ABSPATH' ) ) { exit; }\n\nadd_filter( 'woocommerce_payment_gateways', 'init_wpuw_gateway' );\nfunction init_wpuw_gateway ( $methods ) \n{\n $methods[] = 'WC_Gateway_WPUW'; \n return $methods;\n}\n\n\nif( class_exists('WC_Payment_Gateway') ):\nclass WC_Gateway_WPUW extends WC_Payment_Gateway {\n\n /**\n * Constructor for the gateway.\n */\n public function __construct() {\n\n $plugin_dir = plugin_dir_url(__FILE__);\n\n $this->id = 'wpuw';\n\n //If you want to show an image next to the gateway\xe2\x80\x99s name on the frontend, enter a URL to an image.\n $this->icon = apply_filters( 'woocommerce_gateway_icon', ''.$plugin_dir.'/assets/paysecure.png' );\n …Run Code Online (Sandbox Code Playgroud) 这是一个有关如何为我的WooCommerce订单添加添加购物车项目元和订单项目元的插件。最初,我的以下代码在输入type = text上运行良好。它返回值的标签和输入的值。
转换为type=checkbox代码后,将返回label并value="on"检查代码。
我想返回已检查值的唯一值名称(忽略未检查的值)。
重构以帮助包括更多复选框选项将有助于减少书面代码。
我的代码:
<?php
global $woocommerce, $product, $post;
add_action( 'woocommerce_before_add_to_cart_button', 'add_fields_before_add_to_cart' );
function add_fields_before_add_to_cart( ) {
?>
<div class="simple-selects">
<div class="col-md-6">
<h3>Main meals</h3>
<p><input type="checkbox" name="mm_chicken_cutlet_bento" id="mm_chicken_cutlet_bento"><?php _e( "Chicken Cutlet Bento", "aoim"); ?></p>
<p><input type="checkbox" name="mm_roasted_pork_rib_bento" id="mm_roasted_pork_rib_bento"><?php _e( "Roasted Pork Rib Bento", "aoim"); ?></p>
</div>
</div>
<?php
}
/**
* Add data to cart item
*/
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 25, 2 );
function add_cart_item_data( $cart_item_meta, $product_id …Run Code Online (Sandbox Code Playgroud)