我创建了一些短代码元素。现在我想在后端编辑器中自定义元素的外观。
从VC-Pagebuilder wiki的描述中,我发现我可以为此使用“custom_markup”参数。
对于简单的 html,它工作正常。但是我无法在简码后端元素中显示用户输入。
<?php
add_shortcode('simpletext', 'simpletext_shortcode');
add_action('vc_before_init', 'simpletext_vc');
// Frontend output
function simpletext_shortcode($atts, $content = '') {
ob_start();
set_query_var('content', $content);
get_template_part('components/content', 'simpletext');
return ob_get_clean();
}
// Backend
function simpletext_vc() {
vc_map(array(
"name" => "Einfacher Text",
"base" => "simpletext",
"class" => "",
"icon" => get_template_directory_uri() ."/images/vc_icons/simpletext_icon.png",
"custom_markup" => '{{ content }}', // try to display the user input
"category" => "Text",
"params" => array(
array(
"param_name" => "content",
"heading" => "Inhalt",
"description" => "Inhalt des Elements.",
"holder" …Run Code Online (Sandbox Code Playgroud) php wordpress wordpress-theming custom-wordpress-pages shortcode
在我的自定义插件中,我需要捕获每次订单状态从 变为 的情况,wc_on_hold因此wc_completed我尝试写下:
function so_status_completed( $order_id, $old_status, $new_status ) {
// if user is active , then get order amount and do all other personal calculations
global $wpdb;
$order = wc_get_order( $order_id );
//$payment_method = $order->get_payment_method(); //returns payment method bacs,cheque,cod etc
$user_id = $order->get_user_id();
$total = $order->get_total();
$order_data = $order->get_data();
//$order_total = $order->get_formatted_order_total();
$order_total = $order->get_total();
echo '<script>console.log("Debug Objects: Check order_total ' . $order_total. '");</script>';
}
add_action('woocommerce_order_payment_status_changed','so_status_completed',10,1);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将订单测试从暂停更改为完成时,我无法在 Chrome 控制台上回显给我订单价格......也许使用 add_action 不是将侦听器置于该事件的正确方法?
另外,由于我就在这里,我正在使用 $order-get_total() ,我在网上搜索了它的功能,但没有找到深入的文档,所以我想问你该方法是否是免费检索订单金额的正确方法应用?
谢谢!干杯!!!
wordpress orders woocommerce hook-woocommerce woocommerce-theming
所以我遇到了一个twig/timber问题,我很难获得地点图像集,这是我到目前为止所遇到的问题:
{% set defaultimg = site.theme.link ~ '/images/placeimage.png' %}
Run Code Online (Sandbox Code Playgroud)
然后在我的代码中我有:
<img src="{{ post.thumbnail.src | default(defaultimg) | resize(360, 240)}}" class="card-img-top">
Run Code Online (Sandbox Code Playgroud)
post.thumbnail.src 可以很好地提取图像,但如果帖子中没有附加特色 Img,我希望defaultimg从我的自定义主题图像文件夹中提取图像。但目前这输出了一个非常错误的网址:
<img src="https://toolcart.local/wp-contentC:\Users\User\Local Sites\toolcart\app\public\wp-content\themes\toolcart-theme\images/placeimage-360x240-c-default.png" class="card-img-top">
Run Code Online (Sandbox Code Playgroud)
但是 a{{defaultimg}}正确输出图像 url。
https://toolcart.local/wp-content/themes/toolcart-theme/images/placeimage.png
Run Code Online (Sandbox Code Playgroud)
我不确定接下来要尝试什么?
我正在尝试将这个难题的所有部分拼凑在一起。在过去的三天里,我一直在阅读有关此主题的所有问题和答案。所以我遵循的总体蓝图如下:
woocommerce_variable_add_to_cart();函数来输出正确的 html。这是我每个部分的代码:
global $post;
$product = wc_get_product($post->ID);
$product_type = $product->get_type();
Run Code Online (Sandbox Code Playgroud)
if($product_type == 'variable'):
woocommerce_variable_add_to_cart();
endif;
Run Code Online (Sandbox Code Playgroud)
add_filter('woocommerce_dropdown_variation_attribute_options_html', 'my_theme_variation_radio_buttons', 20, 2);
function my_theme_variation_radio_buttons($html, $args)
{
$args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array(
'options' => false,
'attribute' => false,
'product' => false,
'selected' => false,
'name' => '',
'id' => '', …Run Code Online (Sandbox Code Playgroud) ajax woocommerce woocommerce-theming product-variations variable-product
我是 WordPress 开发新手,目前遇到了死胡同。
我希望在订单状态更改后在 WooCommerce 订单中显示管理员通知。
使用以下代码,不会出现该通知:
<?php
class TestNotice {
public function testTheNotice() {
add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
}
public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
{
add_action('admin_notices', [$this, 'notice']);
}
public function notice()
{
?>
<div class="notice notice-error is-dismissible">
<p>This notice appears on the order page.</p>
</div>
<?php
}
}
$testNotice = new TestNotice();
$testNotice->testTheNotice();
Run Code Online (Sandbox Code Playgroud)
我尝试将“admin_notices”操作的“优先级”参数设置为20,但没有成功(我认为如果嵌套操作与第一次调用的操作相同,这会很有用)。
但是,当我直接在方法中调用“admin_notices”操作testTheNotice()(因此不调用“woocommerce_order_status_changed”操作)时,它可以工作(在每个管理页面上,这不是我想要的)。
我以为这是因为notice()不知何故无法识别,但实际上是:下面的代码显示“此通知出现在订单页面上”。在空白页上(这不是我想要的,仅用于测试目的)。
<?php
class TestNotice {
public function testTheNotice() {
add_action('woocommerce_order_status_changed', [$this, …Run Code Online (Sandbox Code Playgroud) 登录注册表单必须仅像弹出窗口一样显示,因此我进行了重定向,以避免未登录的用户使用默认的 myaccount 页面。
add_action( 'template_redirect', 'wish_custom_redirect' );
function wish_custom_redirect() {
global $wp;
if (!is_user_logged_in() && is_page('my-account') ) {
wp_redirect( '/' );
exit;
}
}
Run Code Online (Sandbox Code Playgroud)
要查看其帐户页面,用户必须登录或以弹出形式注册。但有一个问题 - /my-account/lost-password/、my-account/reset-password/ 是 myaccount 的子端点。他们不必为未登录的用户进行重定向。我试着这样做
add_action( 'template_redirect', 'wish_custom_redirect' );
function wish_custom_redirect() {
global $wp;
if (!is_user_logged_in() && is_page('my-account') && !is_page('my-account/lost-password/') ) {
wp_redirect( '/' );
exit;
}
}
Run Code Online (Sandbox Code Playgroud)
但它仍然重定向。也许这根本就是一个糟糕的解决方案,还有更好的方法吗?或者如何正确地进行此重定向?
add_action('wp_logout','auto_redirect_after_logout');
function auto_redirect_after_logout(){
wp_redirect( home_url() );
exit();
}
Run Code Online (Sandbox Code Playgroud)
仅在注销时重定向有帮助,但并不能避免用户看到默认页面。他们可以注销,然后返回上一页 /myaccount,并查看默认注册表单。
我需要在所有 WordPress 管理页面(后端)上添加 Livechat 小部件。
Livechat JavaScript 代码是这样的:
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
window.__lc = window.__lc || {};
window.__lc.license = 12345678;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
</script>
<noscript>
<a href="https://www.livechatinc.com/chat-with/10437202/" rel="nofollow">Chat with us</a>,
powered by <a href="https://www.livechatinc.com/?welcome" rel="noopener nofollow" target="_blank">LiveChat</a>
</noscript>
<!-- End of LiveChat code -->
Run Code Online (Sandbox Code Playgroud)
Livechat 有一个可以在前端页面上进行聊天的插件。我实际上想将此代码添加到 WordPress 后端的每个页面。 …
javascript wordpress wordpress-theming custom-wordpress-pages wordpress-admin
我想获取我在我的中使用以下代码的购物车总数functions.php:
function display_total(){
global $woocommerce;
$newTotal = $woocommerce->cart->get_total();
echo $newTotal;
};
add_action( 'woocommerce_review_order_before_order_total', 'display_total');
Run Code Online (Sandbox Code Playgroud)
它不是显示一次金额,而是像 那样显示两次$18.00$18.00。
执行 a 操作var_dump也会生成 2 行 HTML:
D:\Wordpress\wp-content\themes\new_theme\functions.php:161:string '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>18.00</bdi></span>' (length=128)
D:\Wordpress\wp-content\themes\new_theme\functions.php:161:string '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>18.00</bdi></span>' (length=128)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
php wordpress woocommerce hook-woocommerce woocommerce-theming
我正在尝试获取与特色图像相关的元数据,但get_post_meta始终返回空。
$image_alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
Run Code Online (Sandbox Code Playgroud)
这可以工作并返回数据,但下面的代码不起作用:
$image_description = get_post_meta($image_id, '_wp_attachment_description', true);
$image_caption = get_post_meta($image_id, '_wp_attachment_caption', true);
Run Code Online (Sandbox Code Playgroud)
这两个返回空。我填写了这些字段,但无法将它们返回到我的模板中!
我正在尝试使用特色图像Alt Text的Title、Caption和Description来改进我的网站 SEO,但我不明白为什么它们显示为空。
你能帮我一下吗?
先感谢您。
我在 WooCommerce 产品上为帖子类型设置了高级自定义字段。因此每个产品都有 1 个独特的自定义字段。
我试图在购物车上的产品名称以及结账页面和订单表信息之后显示自定义字段。
但是,由于我的代码不显示任何输出,因此遇到了问题。
任何有关如何实现这一目标的建议将不胜感激。谢谢
// Display the ACF custom field 'location' after the product title on cart / checkout page.
function cart_item_custom_feild( $cart_item ) {
$address = get_field( 'location', $cart_item['product_id'] );
echo "<div>Address: $address.</div>";
}
add_action( 'woocommerce_after_cart_item_name', 'cart_item_custom_feild', 10, 1 );
Run Code Online (Sandbox Code Playgroud)
我也尝试过the_field而不是get_field
php wordpress woocommerce advanced-custom-fields woocommerce-theming